UNPKG

5.6 kBTypeScriptView Raw
1import { ParamTypeDefinition } from './interface';
2/**
3 * A registry for parameter types.
4 *
5 * This registry manages the built-in (and custom) parameter types.
6 *
7 * The built-in parameter types are:
8 *
9 * - [[string]]
10 * - [[path]]
11 * - [[query]]
12 * - [[hash]]
13 * - [[int]]
14 * - [[bool]]
15 * - [[date]]
16 * - [[json]]
17 * - [[any]]
18 *
19 * To register custom parameter types, use [[UrlConfig.type]], i.e.,
20 *
21 * ```js
22 * router.urlService.config.type(customType)
23 * ```
24 */
25export declare class ParamTypes {
26 /**
27 * Built-in parameter type: `string`
28 *
29 * This parameter type coerces values to strings.
30 * It matches anything (`new RegExp(".*")`) in the URL
31 */
32 static string: ParamTypeDefinition;
33 /**
34 * Built-in parameter type: `path`
35 *
36 * This parameter type is the default type for path parameters.
37 * A path parameter is any parameter declared in the path portion of a url
38 *
39 * - `/foo/:param1/:param2`: two path parameters
40 *
41 * This parameter type behaves exactly like the [[string]] type with one exception.
42 * When matching parameter values in the URL, the `path` type does not match forward slashes `/`.
43 *
44 * #### Angular 1 note:
45 * In ng1, this type is overridden with one that pre-encodes slashes as `~2F` instead of `%2F`.
46 * For more details about this angular 1 behavior, see: https://github.com/angular-ui/ui-router/issues/2598
47 */
48 static path: ParamTypeDefinition;
49 /**
50 * Built-in parameter type: `query`
51 *
52 * This parameter type is the default type for query/search parameters.
53 * It behaves the same as the [[string]] parameter type.
54 *
55 * A query parameter is any parameter declared in the query/search portion of a url
56 *
57 * - `/bar?param2`: a query parameter
58 */
59 static query: ParamTypeDefinition;
60 /**
61 * Built-in parameter type: `hash`
62 *
63 * This parameter type is used for the `#` parameter (the hash)
64 * It behaves the same as the [[string]] parameter type.
65 */
66 static hash: ParamTypeDefinition;
67 /**
68 * Built-in parameter type: `int`
69 *
70 * This parameter type serializes javascript integers (`number`s which represent an integer) to the URL.
71 *
72 * #### Example:
73 * ```js
74 * .state({
75 * name: 'user',
76 * url: '/user/{id:int}'
77 * });
78 * ```
79 * ```js
80 * $state.go('user', { id: 1298547 });
81 * ```
82 *
83 * The URL will serialize to: `/user/1298547`.
84 *
85 * When the parameter value is read, it will be the `number` `1298547`, not the string `"1298547"`.
86 */
87 static int: ParamTypeDefinition;
88 /**
89 * Built-in parameter type: `bool`
90 *
91 * This parameter type serializes `true`/`false` as `1`/`0`
92 *
93 * #### Example:
94 * ```js
95 * .state({
96 * name: 'inbox',
97 * url: '/inbox?{unread:bool}'
98 * });
99 * ```
100 * ```js
101 * $state.go('inbox', { unread: true });
102 * ```
103 *
104 * The URL will serialize to: `/inbox?unread=1`.
105 *
106 * Conversely, if the url is `/inbox?unread=0`, the value of the `unread` parameter will be a `false`.
107 */
108 static bool: ParamTypeDefinition;
109 /**
110 * Built-in parameter type: `date`
111 *
112 * This parameter type can be used to serialize Javascript dates as parameter values.
113 *
114 * #### Example:
115 * ```js
116 * .state({
117 * name: 'search',
118 * url: '/search?{start:date}'
119 * });
120 * ```
121 * ```js
122 * $state.go('search', { start: new Date(2000, 0, 1) });
123 * ```
124 *
125 * The URL will serialize to: `/search?start=2000-01-01`.
126 *
127 * Conversely, if the url is `/search?start=2016-12-25`, the value of the `start` parameter will be a `Date` object where:
128 *
129 * - `date.getFullYear() === 2016`
130 * - `date.getMonth() === 11` (month is 0-based)
131 * - `date.getDate() === 25`
132 */
133 static date: ParamTypeDefinition;
134 /**
135 * Built-in parameter type: `json`
136 *
137 * This parameter type can be used to serialize javascript objects into the URL using JSON serialization.
138 *
139 * #### Example:
140 * This example serializes an plain javascript object to the URL
141 * ```js
142 * .state({
143 * name: 'map',
144 * url: '/map/{coords:json}'
145 * });
146 * ```
147 * ```js
148 * $state.go('map', { coords: { x: 10399.2, y: 49071 });
149 * ```
150 *
151 * The URL will serialize to: `/map/%7B%22x%22%3A10399.2%2C%22y%22%3A49071%7D`
152 */
153 static json: ParamTypeDefinition;
154 /**
155 * Built-in parameter type: `any`
156 *
157 * This parameter type is used by default for url-less parameters (parameters that do not appear in the URL).
158 * This type does not encode or decode.
159 * It is compared using a deep `equals` comparison.
160 *
161 * #### Example:
162 * This example defines a non-url parameter on a [[StateDeclaration]].
163 * ```js
164 * .state({
165 * name: 'new',
166 * url: '/new',
167 * params: {
168 * inrepyto: null
169 * }
170 * });
171 * ```
172 * ```js
173 * $state.go('new', { inreplyto: currentMessage });
174 * ```
175 */
176 static any: ParamTypeDefinition;
177 types: any;
178 enqueue: boolean;
179 typeQueue: any[];
180 private defaultTypes;
181 constructor();
182 dispose(): void;
183 /**
184 * Registers a parameter type
185 *
186 * End users should call [[UrlMatcherFactory.type]], which delegates to this method.
187 */
188 type(name: string, definition?: ParamTypeDefinition, definitionFn?: () => ParamTypeDefinition): any;
189 _flushTypeQueue(): void;
190}