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