UNPKG

4.86 kBJavaScriptView Raw
1"use strict";
2var __assign = (this && this.__assign) || function () {
3 __assign = Object.assign || function(t) {
4 for (var s, i = 1, n = arguments.length; i < n; i++) {
5 s = arguments[i];
6 for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7 t[p] = s[p];
8 }
9 return t;
10 };
11 return __assign.apply(this, arguments);
12};
13Object.defineProperty(exports, "__esModule", { value: true });
14exports.UrlMatcherFactory = exports.ParamFactory = void 0;
15var common_1 = require("../common");
16var urlMatcher_1 = require("./urlMatcher");
17var params_1 = require("../params");
18var ParamFactory = /** @class */ (function () {
19 function ParamFactory(router) {
20 this.router = router;
21 }
22 ParamFactory.prototype.fromConfig = function (id, type, state) {
23 return new params_1.Param(id, type, params_1.DefType.CONFIG, this.router.urlService.config, state);
24 };
25 ParamFactory.prototype.fromPath = function (id, type, state) {
26 return new params_1.Param(id, type, params_1.DefType.PATH, this.router.urlService.config, state);
27 };
28 ParamFactory.prototype.fromSearch = function (id, type, state) {
29 return new params_1.Param(id, type, params_1.DefType.SEARCH, this.router.urlService.config, state);
30 };
31 return ParamFactory;
32}());
33exports.ParamFactory = ParamFactory;
34/**
35 * Factory for [[UrlMatcher]] instances.
36 *
37 * The factory is available to ng1 services as
38 * `$urlMatcherFactory` or ng1 providers as `$urlMatcherFactoryProvider`.
39 */
40var UrlMatcherFactory = /** @class */ (function () {
41 // TODO: move implementations to UrlConfig (urlService.config)
42 function UrlMatcherFactory(/** @internal */ router) {
43 var _this = this;
44 this.router = router;
45 /** Creates a new [[Param]] for a given location (DefType) */
46 this.paramFactory = new ParamFactory(this.router);
47 // TODO: Check if removal of this will break anything, then remove these
48 this.UrlMatcher = urlMatcher_1.UrlMatcher;
49 this.Param = params_1.Param;
50 /** @deprecated use [[UrlConfig.caseInsensitive]] */
51 this.caseInsensitive = function (value) { return _this.router.urlService.config.caseInsensitive(value); };
52 /** @deprecated use [[UrlConfig.defaultSquashPolicy]] */
53 this.defaultSquashPolicy = function (value) { return _this.router.urlService.config.defaultSquashPolicy(value); };
54 /** @deprecated use [[UrlConfig.strictMode]] */
55 this.strictMode = function (value) { return _this.router.urlService.config.strictMode(value); };
56 /** @deprecated use [[UrlConfig.type]] */
57 this.type = function (name, definition, definitionFn) {
58 return _this.router.urlService.config.type(name, definition, definitionFn) || _this;
59 };
60 }
61 /**
62 * Creates a [[UrlMatcher]] for the specified pattern.
63 *
64 * @param pattern The URL pattern.
65 * @param config The config object hash.
66 * @returns The UrlMatcher.
67 */
68 UrlMatcherFactory.prototype.compile = function (pattern, config) {
69 var urlConfig = this.router.urlService.config;
70 // backward-compatible support for config.params -> config.state.params
71 var params = config && !config.state && config.params;
72 config = params ? __assign({ state: { params: params } }, config) : config;
73 var globalConfig = {
74 strict: urlConfig._isStrictMode,
75 caseInsensitive: urlConfig._isCaseInsensitive,
76 decodeParams: urlConfig._decodeParams,
77 };
78 return new urlMatcher_1.UrlMatcher(pattern, urlConfig.paramTypes, this.paramFactory, common_1.extend(globalConfig, config));
79 };
80 /**
81 * Returns true if the specified object is a [[UrlMatcher]], or false otherwise.
82 *
83 * @param object The object to perform the type check against.
84 * @returns `true` if the object matches the `UrlMatcher` interface, by
85 * implementing all the same methods.
86 */
87 UrlMatcherFactory.prototype.isMatcher = function (object) {
88 // TODO: typeof?
89 if (!common_1.isObject(object))
90 return false;
91 var result = true;
92 common_1.forEach(urlMatcher_1.UrlMatcher.prototype, function (val, name) {
93 if (common_1.isFunction(val))
94 result = result && common_1.isDefined(object[name]) && common_1.isFunction(object[name]);
95 });
96 return result;
97 };
98 /** @internal */
99 UrlMatcherFactory.prototype.$get = function () {
100 var urlConfig = this.router.urlService.config;
101 urlConfig.paramTypes.enqueue = false;
102 urlConfig.paramTypes._flushTypeQueue();
103 return this;
104 };
105 return UrlMatcherFactory;
106}());
107exports.UrlMatcherFactory = UrlMatcherFactory;
108//# sourceMappingURL=urlMatcherFactory.js.map
\No newline at end of file