|
| 1 | +/** |
| 2 | + * Matches URLs against patterns. |
| 3 | + * |
| 4 | + * Matches URLs against patterns and extracts named parameters from the path or the search |
| 5 | + * part of the URL. |
| 6 | + * |
| 7 | + * A URL pattern consists of a path pattern, optionally followed by '?' and a list of search (query) |
| 8 | + * parameters. Multiple search parameter names are separated by '&'. Search parameters |
| 9 | + * do not influence whether or not a URL is matched, but their values are passed through into |
| 10 | + * the matched parameters returned by [[UrlMatcher.exec]]. |
| 11 | + * |
| 12 | + * - *Path parameters* are defined using curly brace placeholders (`/somepath/{param}`) |
| 13 | + * or colon placeholders (`/somePath/:param`). |
| 14 | + * |
| 15 | + * - *A parameter RegExp* may be defined for a param after a colon |
| 16 | + * (`/somePath/{param:[a-zA-Z0-9]+}`) in a curly brace placeholder. |
| 17 | + * The regexp must match for the url to be matched. |
| 18 | + * Should the regexp itself contain curly braces, they must be in matched pairs or escaped with a backslash. |
| 19 | + * |
| 20 | + * Note: a RegExp parameter will encode its value using either [[ParamTypes.path]] or [[ParamTypes.query]]. |
| 21 | + * |
| 22 | + * - *Custom parameter types* may also be specified after a colon (`/somePath/{param:int}`) in curly brace parameters. |
| 23 | + * See [[UrlMatcherFactory.type]] for more information. |
| 24 | + * |
| 25 | + * - *Catch-all parameters* are defined using an asterisk placeholder (`/somepath/*catchallparam`). |
| 26 | + * A catch-all * parameter value will contain the remainder of the URL. |
| 27 | + * |
| 28 | + * --- |
| 29 | + * |
| 30 | + * Parameter names may contain only word characters (latin letters, digits, and underscore) and |
| 31 | + * must be unique within the pattern (across both path and search parameters). |
| 32 | + * A path parameter matches any number of characters other than '/'. For catch-all |
| 33 | + * placeholders the path parameter matches any number of characters. |
| 34 | + * |
| 35 | + * Examples: |
| 36 | + * |
| 37 | + * * `'/hello/'` - Matches only if the path is exactly '/hello/'. There is no special treatment for |
| 38 | + * trailing slashes, and patterns have to match the entire path, not just a prefix. |
| 39 | + * * `'/user/:id'` - Matches '/user/bob' or '/user/1234!!!' or even '/user/' but not '/user' or |
| 40 | + * '/user/bob/details'. The second path segment will be captured as the parameter 'id'. |
| 41 | + * * `'/user/{id}'` - Same as the previous example, but using curly brace syntax. |
| 42 | + * * `'/user/{id:[^/]*}'` - Same as the previous example. |
| 43 | + * * `'/user/{id:[0-9a-fA-F]{1,8}}'` - Similar to the previous example, but only matches if the id |
| 44 | + * parameter consists of 1 to 8 hex digits. |
| 45 | + * * `'/files/{path:.*}'` - Matches any URL starting with '/files/' and captures the rest of the |
| 46 | + * path into the parameter 'path'. |
| 47 | + * * `'/files/*path'` - ditto. |
| 48 | + * * `'/calendar/{start:date}'` - Matches "/calendar/2014-11-12" (because the pattern defined |
| 49 | + * in the built-in `date` ParamType matches `2014-11-12`) and provides a Date object in $stateParams.start |
| 50 | + * |
| 51 | + */ |
| 52 | +export class UrlMatcher { |
| 53 | + static encodeDashes(str: any): string; |
| 54 | + /** @internal Given a matcher, return an array with the matcher's path segments and path params, in order */ |
| 55 | + static pathSegmentsAndParams(matcher: any): any; |
| 56 | + /** @internal Given a matcher, return an array with the matcher's query params */ |
| 57 | + static queryParams(matcher: any): any; |
| 58 | + /** |
| 59 | + * Compare two UrlMatchers |
| 60 | + * |
| 61 | + * This comparison function converts a UrlMatcher into static and dynamic path segments. |
| 62 | + * Each static path segment is a static string between a path separator (slash character). |
| 63 | + * Each dynamic segment is a path parameter. |
| 64 | + * |
| 65 | + * The comparison function sorts static segments before dynamic ones. |
| 66 | + */ |
| 67 | + static compare(a: any, b: any): number; |
| 68 | + /** |
| 69 | + * @param pattern The pattern to compile into a matcher. |
| 70 | + * @param paramTypes The [[ParamTypes]] registry |
| 71 | + * @param paramFactory A [[ParamFactory]] object |
| 72 | + * @param config A [[UrlMatcherCompileConfig]] configuration object |
| 73 | + */ |
| 74 | + constructor(pattern: any, paramTypes: any, paramFactory: any, config: any); |
| 75 | + _cache: { |
| 76 | + path: this[]; |
| 77 | + }; |
| 78 | + _children: any[]; |
| 79 | + _params: any[]; |
| 80 | + _segments: any[]; |
| 81 | + _compiled: any[]; |
| 82 | + config: any; |
| 83 | + pattern: any; |
| 84 | + /** |
| 85 | + * Creates a new concatenated UrlMatcher |
| 86 | + * |
| 87 | + * Builds a new UrlMatcher by appending another UrlMatcher to this one. |
| 88 | + * |
| 89 | + * @param url A `UrlMatcher` instance to append as a child of the current `UrlMatcher`. |
| 90 | + */ |
| 91 | + append(url: any): any; |
| 92 | + isRoot(): boolean; |
| 93 | + /** Returns the input pattern string */ |
| 94 | + toString(): any; |
| 95 | + _getDecodedParamValue(value: any, param: any): any; |
| 96 | + /** |
| 97 | + * Tests the specified url/path against this matcher. |
| 98 | + * |
| 99 | + * Tests if the given url matches this matcher's pattern, and returns an object containing the captured |
| 100 | + * parameter values. Returns null if the path does not match. |
| 101 | + * |
| 102 | + * The returned object contains the values |
| 103 | + * of any search parameters that are mentioned in the pattern, but their value may be null if |
| 104 | + * they are not present in `search`. This means that search parameters are always treated |
| 105 | + * as optional. |
| 106 | + * |
| 107 | + * #### Example: |
| 108 | + * ```js |
| 109 | + * new UrlMatcher('/user/{id}?q&r').exec('/user/bob', { |
| 110 | + * x: '1', q: 'hello' |
| 111 | + * }); |
| 112 | + * // returns { id: 'bob', q: 'hello', r: null } |
| 113 | + * ``` |
| 114 | + * |
| 115 | + * @param path The URL path to match, e.g. `$location.path()`. |
| 116 | + * @param search URL search parameters, e.g. `$location.search()`. |
| 117 | + * @param hash URL hash e.g. `$location.hash()`. |
| 118 | + * |
| 119 | + * @returns The captured parameter values. |
| 120 | + */ |
| 121 | + exec(path: any, search: {}, hash: any): { |
| 122 | + "#": any; |
| 123 | + }; |
| 124 | + /** |
| 125 | + * @internal |
| 126 | + * Returns all the [[Param]] objects of all path and search parameters of this pattern in order of appearance. |
| 127 | + * |
| 128 | + * @returns {Array.<Param>} An array of [[Param]] objects. Must be treated as read-only. If the |
| 129 | + * pattern has no parameters, an empty array is returned. |
| 130 | + */ |
| 131 | + parameters(opts?: {}): Array<Param>; |
| 132 | + /** |
| 133 | + * @internal |
| 134 | + * Returns a single parameter from this UrlMatcher by id |
| 135 | + * |
| 136 | + * @param id |
| 137 | + * @param opts |
| 138 | + * @returns {Param|any|boolean|UrlMatcher|null} |
| 139 | + */ |
| 140 | + parameter(id: any, opts?: {}): Param | any | boolean | UrlMatcher | null; |
| 141 | + /** |
| 142 | + * Validates the input parameter values against this UrlMatcher |
| 143 | + * |
| 144 | + * Checks an object hash of parameters to validate their correctness according to the parameter |
| 145 | + * types of this `UrlMatcher`. |
| 146 | + * |
| 147 | + * @param params The object hash of parameters to validate. |
| 148 | + * @returns Returns `true` if `params` validates, otherwise `false`. |
| 149 | + */ |
| 150 | + validates(params: any): any; |
| 151 | + /** |
| 152 | + * Given a set of parameter values, creates a URL from this UrlMatcher. |
| 153 | + * |
| 154 | + * Creates a URL that matches this pattern by substituting the specified values |
| 155 | + * for the path and search parameters. |
| 156 | + * |
| 157 | + * #### Example: |
| 158 | + * ```js |
| 159 | + * new UrlMatcher('/user/{id}?q').format({ id:'bob', q:'yes' }); |
| 160 | + * // returns '/user/bob?q=yes' |
| 161 | + * ``` |
| 162 | + * |
| 163 | + * @param values the values to substitute for the parameters in this pattern. |
| 164 | + * @returns the formatted URL (path and optionally search part). |
| 165 | + */ |
| 166 | + format(values?: {}): string; |
| 167 | +} |
| 168 | +export namespace UrlMatcher { |
| 169 | + let nameValidator: RegExp; |
| 170 | +} |
| 171 | +import { Param } from "../params/param"; |
0 commit comments