lib/web.route.handler.js
function convertUrlSegmentToRegex(segment) {

    // if it has this format "{stuff}" - then it's regex-y
    var beginIdx = segment.indexOf('{');
    var endIdx = segment.indexOf('}');

    if (beginIdx < 0) {
        return segment;
    }

    // if capturing regex and trim trailing "}"
    // this could be a named regex {id:[0-9]+} or just name {companySlug}
    var pieces = segment.split(':');
    if (pieces.length === 2) {
        if ( pieces[1] === (urlPathPatternSymbol + '}') ) {
            // special case where we want to capture the whole remaining path, even slashes, like /search/a/b/c/
            return urlPathPattern;
        }
        else {
            return '(' + pieces[1].substring(0, pieces[1].length - 1) + ')';
        }
    }
    else if (pieces.length === 1) {
        return segment.substring(0, beginIdx) + '[^\\/]+' + segment.substring(endIdx + 1);
    }
    else {
        throw new Error('Weird URL segment- don\'t know how to parse! ' + segment);
    }
}
function convertUrlSegmentToRegex(segment) {

    // if it has this format "{stuff}" - then it's regex-y
    var beginIdx = segment.indexOf('{');
    var endIdx = segment.indexOf('}');

    if (beginIdx < 0) {
        return segment;
    }

    // if capturing regex and trim trailing "}"
    // this could be a named regex {id:[0-9]+} or just name {companySlug}
    var pieces = segment.split(':');
    if (pieces.length === 2) {
        if ( pieces[1] === (urlPathPatternSymbol + '}') ) {
            // special case where we want to capture the whole remaining path, even slashes, like /search/a/b/c/
            return urlPathPattern;
        }
        else {
            return '(' + pieces[1].substring(0, pieces[1].length - 1) + ')';
        }
    }
    else if (pieces.length === 1) {
        return segment.substring(0, beginIdx) + '[^\\/]+' + segment.substring(endIdx + 1);
    }
    else {
        throw new Error('Weird URL segment- don\'t know how to parse! ' + segment);
    }
}
function convertUrlSegmentToRegex ( segment ) { // if it has this format "{stuff}" - then it's regex-y var beginIdx = segment . indexOf ( '{' ) ; var endIdx = segment . indexOf ( '}' ) ; if ( beginIdx < 0 ) { return segment ; } // if capturing regex and trim trailing "}" // this could be a named regex {id:[0-9]+} or just name {companySlug} var pieces = segment . split ( ':' ) ; if ( pieces . length === 2 ) { if ( pieces [ 1 ] === ( urlPathPatternSymbol + '}' ) ) { // special case where we want to capture the whole remaining path, even slashes, like /search/a/b/c/ return urlPathPattern ; } else { return '(' + pieces [ 1 ] . substring ( 0 , pieces [ 1 ] . length - 1 ) + ')' ; } } else if ( pieces . length === 1 ) { return segment . substring ( 0 , beginIdx ) + '[^\\/]+' + segment . substring ( endIdx + 1 ) ; } else { throw new Error ( 'Weird URL segment- don\'t know how to parse! ' + segment ) ; } }
Convert a segment of URL to a regex pattern for full URL casting below
@param segment
@returns string A segment as a URL pattern string
Convert a segment of URL to a regex pattern for full URL casting below