path-to-regexp#Path TypeScript Examples

The following examples show how to use path-to-regexp#Path. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: router.ts    From native with MIT License 6 votes vote down vote up
/** Convert strings into path match functions */
    public parsePath(path: TypeRouteStyle): RegExp | boolean {
        if (typeof path === "string" || path instanceof RegExp || Array.isArray(path)) {
            let _keys = [];
            return pathToRegexp(path as Path, _keys, {
                start: false,
                end: false
            });
        } else if (typeof path === "boolean")
            return path ? /.*/ : path;

        throw "[Router] only regular expressions, strings, booleans and arrays of regular expressions and strings are accepted as paths.";
    }