libs/scully/src/lib/utils/routeSplit.js
/**
 * Returns a route in a more usable form, and a
 * @param route to split
 */
Returns a route in a more usable form, and a
@param route to split
Returns a route in a more usable form and a @param route to split
function routeSplit(route) {
    if (!route) {
        return { parts: [], params: [], createPath: (..._arg) => '' };
    }
    const parts = route
        .split('/')
        .map((part, position) => ({ part, position }));
    const params = parts
        .filter(Boolean)
        .filter(p => p.part.startsWith(':'))
        .map(p => (Object.assign(Object.assign({}, p), { part: p.part.slice(1) })));
    const createPath = (...data) => {
        const injectData = data.reduce((r, val, pos) => {
            r[params[pos].position] = val;
            return r;
        }, []);
        return parts.reduce((url, part, pos) => `${url}${injectData[pos] !== undefined ? injectData[pos] : part.part}${pos !== parts.length - 1 ? '/' : ''}`, '');
    };
    return { parts, params, createPath };
}
function routeSplit ( route ) { if ( ! route ) { return { parts : [ ] , params : [ ] , createPath : ( ... _arg ) => '' } ; } const parts = route . split ( '/' ) . map ( ( part , position ) => ( { part , position } ) ) ; const params = parts . filter ( Boolean ) . filter ( p => p . part . startsWith ( ':' ) ) . map ( p => ( Object . assign ( Object . assign ( { } , p ) , { part : p . part . slice ( 1 ) } ) ) ) ; const createPath = ( ... data ) => { const injectData = data . reduce ( ( r , val , pos ) => { r [ params [ pos ] . position ] = val ; return r ; } , [ ] ) ; return parts . reduce ( ( url , part , pos ) => ` ${ url } ${ injectData [ pos ] !== undefined ? injectData [ pos ] : part . part } ${ pos !== parts . length - 1 ? '/' : '' } ` , '' ) ; } ; return { parts , params , createPath } ; }
Returns a route in a more usable form, and a
 @param route to split
Returns a route in a more usable form and a @param route to split