UNPKG

2.5 kBTypeScriptView Raw
1import { ParamTypeDefinition } from './interface';
2/**
3 * An internal class which implements [[ParamTypeDefinition]].
4 *
5 * A [[ParamTypeDefinition]] is a plain javascript object used to register custom parameter types.
6 * When a param type definition is registered, an instance of this class is created internally.
7 *
8 * This class has naive implementations for all the [[ParamTypeDefinition]] methods.
9 *
10 * Used by [[UrlMatcher]] when matching or formatting URLs, or comparing and validating parameter values.
11 *
12 * #### Example:
13 * ```js
14 * var paramTypeDef = {
15 * decode: function(val) { return parseInt(val, 10); },
16 * encode: function(val) { return val && val.toString(); },
17 * equals: function(a, b) { return this.is(a) && a === b; },
18 * is: function(val) { return angular.isNumber(val) && isFinite(val) && val % 1 === 0; },
19 * pattern: /\d+/
20 * }
21 *
22 * var paramType = new ParamType(paramTypeDef);
23 * ```
24 */
25export declare class ParamType implements ParamTypeDefinition {
26 /** @inheritdoc */
27 pattern: RegExp;
28 /** The name/id of the parameter type */
29 name: string;
30 /** @inheritdoc */
31 raw: boolean;
32 /** @inheritdoc */
33 dynamic: boolean;
34 /** @inheritdoc */
35 inherit: boolean;
36 /**
37 * @param def A configuration object which contains the custom type definition. The object's
38 * properties will override the default methods and/or pattern in `ParamType`'s public interface.
39 * @returns a new ParamType object
40 */
41 constructor(def: ParamTypeDefinition);
42 /** @inheritdoc */
43 is(val: any, key?: string): boolean;
44 /** @inheritdoc */
45 encode(val: any, key?: string): string | string[];
46 /** @inheritdoc */
47 decode(val: string, key?: string): any;
48 /** @inheritdoc */
49 equals(a: any, b: any): boolean;
50 $subPattern(): string;
51 toString(): string;
52 /** Given an encoded string, or a decoded object, returns a decoded object */
53 $normalize(val: any): any;
54 /**
55 * Wraps an existing custom ParamType as an array of ParamType, depending on 'mode'.
56 * e.g.:
57 * - urlmatcher pattern "/path?{queryParam[]:int}"
58 * - url: "/path?queryParam=1&queryParam=2
59 * - $stateParams.queryParam will be [1, 2]
60 * if `mode` is "auto", then
61 * - url: "/path?queryParam=1 will create $stateParams.queryParam: 1
62 * - url: "/path?queryParam=1&queryParam=2 will create $stateParams.queryParam: [1, 2]
63 */
64 $asArray(mode: boolean | 'auto', isSearch: boolean): any;
65}