lib/escort.js
function (routes) {
        if (!Array.isArray(routes)) {
            routes = [routes];
        }

        var result = [];

        routes.forEach(function (route) {
            if (route.indexOf('[') === -1) {
                result.push(route);
                return;
            }

            var immediateResult = [''];

            var depth = 0;
            var inLiteral = 0;

            for (var i = 0, len = route.length; i < len; i += 1) {
                var c = route[i];
                if (!inLiteral) {
                    if (c === '[') {
                        depth += 1;
                        for (var j = 0, lenJ = immediateResult.length; j < lenJ; j += 1) {
                            immediateResult.push(immediateResult[j]);
                        }
                    } else if (c === ']') {
                        depth -= 1;
                    } else {
                        if (c === '{') {
                            inLiteral += 1;
                        } else if (c === '}') {    
                            throw new Error("Found unexpected } in route: " + route);
                        }
                        addCharToArray(immediateResult, c, depth);
                    }
                } else {
                    if (c === '{') {
                        inLiteral += 1;
                    } else if (c === '}') {
                        inLiteral -= 1;
                    }
                    addCharToArray(immediateResult, c, depth);
                }
            }

            for (i = 0, len = immediateResult.length; i < len; i += 1) {
                result.push(immediateResult[i]);
            }
        });

        return distinct(result);
    }
function (routes) {
        if (!Array.isArray(routes)) {
            routes = [routes];
        }

        var result = [];

        routes.forEach(function (route) {
            if (route.indexOf('[') === -1) {
                result.push(route);
                return;
            }

            var immediateResult = [''];

            var depth = 0;
            var inLiteral = 0;

            for (var i = 0, len = route.length; i < len; i += 1) {
                var c = route[i];
                if (!inLiteral) {
                    if (c === '[') {
                        depth += 1;
                        for (var j = 0, lenJ = immediateResult.length; j < lenJ; j += 1) {
                            immediateResult.push(immediateResult[j]);
                        }
                    } else if (c === ']') {
                        depth -= 1;
                    } else {
                        if (c === '{') {
                            inLiteral += 1;
                        } else if (c === '}') {    
                            throw new Error("Found unexpected } in route: " + route);
                        }
                        addCharToArray(immediateResult, c, depth);
                    }
                } else {
                    if (c === '{') {
                        inLiteral += 1;
                    } else if (c === '}') {
                        inLiteral -= 1;
                    }
                    addCharToArray(immediateResult, c, depth);
                }
            }

            for (i = 0, len = immediateResult.length; i < len; i += 1) {
                result.push(immediateResult[i]);
            }
        });

        return distinct(result);
    }
function ( routes ) { if ( ! Array . isArray ( routes ) ) { routes = [ routes ] ; } var result = [ ] ; routes . forEach ( function ( route ) { if ( route . indexOf ( '[' ) === - 1 ) { result . push ( route ) ; return ; } var immediateResult = [ '' ] ; var depth = 0 ; var inLiteral = 0 ; for ( var i = 0 , len = route . length ; i < len ; i += 1 ) { var c = route [ i ] ; if ( ! inLiteral ) { if ( c === '[' ) { depth += 1 ; for ( var j = 0 , lenJ = immediateResult . length ; j < lenJ ; j += 1 ) { immediateResult . push ( immediateResult [ j ] ) ; } } else if ( c === ']' ) { depth -= 1 ; } else { if ( c === '{' ) { inLiteral += 1 ; } else if ( c === '}' ) { throw new Error ( "Found unexpected } in route: " + route ) ; } addCharToArray ( immediateResult , c , depth ) ; } } else { if ( c === '{' ) { inLiteral += 1 ; } else if ( c === '}' ) { inLiteral -= 1 ; } addCharToArray ( immediateResult , c , depth ) ; } } for ( i = 0 , len = immediateResult . length ; i < len ; i += 1 ) { result . push ( immediateResult [ i ] ) ; } } ) ; return distinct ( result ) ; }
Parse all potential optional routes out of the provided String or Array.

@param {Array} routes an array of routes, or a String which is a single route.
@return {Array} the parsed-out array of optional routes.
@api private

@example parseOptionalRoutes("/same") => ["/same"]
@example parseOptionalRoutes("/[optional]") => ["/", "/optional"]
@example parseOptionalRoutes("/data[.{format}]") => ["/data", "/data.{format}"]
@example parseOptionalRoutes("/multiple[/optional][/parameters]") => ["/multiple", "/multiple/optional", "/multiple/parameters", "/multiple/optional/parameters"]
@example parseOptionalRoutes("/deep[/optional[/parameters]]") => ["/deep", "/deep/optional", "/deep/optional/parameters"]
@example parseOptionalRoutes(["/data[.{format}]", "/data/page/{num:int}[.{format}]"]) => ["/data", "/data.{format}", "/data/page/{num:int}", "/data/page/{num:int}.{format}"]
@example parseOptionalRoutes("/{name:custom(['a', 'b', 'c'])}") => ["/{name:custom(['a', 'b', 'c'])}"]
Parse all potential optional routes out of the provided String or Array .