@angular-wave/angular.ts 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintignore +1 -0
- package/.eslintrc.cjs +29 -0
- package/.github/workflows/playwright.yml +27 -0
- package/CHANGELOG.md +17974 -0
- package/CODE_OF_CONDUCT.md +3 -0
- package/CONTRIBUTING.md +246 -0
- package/DEVELOPERS.md +488 -0
- package/LICENSE +22 -0
- package/Makefile +31 -0
- package/README.md +115 -0
- package/RELEASE.md +98 -0
- package/SECURITY.md +16 -0
- package/TRIAGING.md +135 -0
- package/css/angular.css +22 -0
- package/dist/angular-ts.cjs.js +36843 -0
- package/dist/angular-ts.esm.js +36841 -0
- package/dist/angular-ts.umd.js +36848 -0
- package/dist/build/angular-animate.js +4272 -0
- package/dist/build/angular-aria.js +426 -0
- package/dist/build/angular-message-format.js +1072 -0
- package/dist/build/angular-messages.js +829 -0
- package/dist/build/angular-mocks.js +3757 -0
- package/dist/build/angular-parse-ext.js +1275 -0
- package/dist/build/angular-resource.js +911 -0
- package/dist/build/angular-route.js +1266 -0
- package/dist/build/angular-sanitize.js +891 -0
- package/dist/build/angular-touch.js +368 -0
- package/dist/build/angular.js +36600 -0
- package/e2e/unit.spec.ts +15 -0
- package/images/android-chrome-192x192.png +0 -0
- package/images/android-chrome-512x512.png +0 -0
- package/images/apple-touch-icon.png +0 -0
- package/images/favicon-16x16.png +0 -0
- package/images/favicon-32x32.png +0 -0
- package/images/favicon.ico +0 -0
- package/images/site.webmanifest +1 -0
- package/index.html +104 -0
- package/package.json +47 -0
- package/playwright.config.ts +78 -0
- package/public/circle.html +1 -0
- package/public/my_child_directive.html +1 -0
- package/public/my_directive.html +1 -0
- package/public/my_other_directive.html +1 -0
- package/public/test.html +1 -0
- package/rollup.config.js +31 -0
- package/src/animations/animateCache.js +55 -0
- package/src/animations/animateChildrenDirective.js +105 -0
- package/src/animations/animateCss.js +1139 -0
- package/src/animations/animateCssDriver.js +291 -0
- package/src/animations/animateJs.js +367 -0
- package/src/animations/animateJsDriver.js +67 -0
- package/src/animations/animateQueue.js +851 -0
- package/src/animations/animation.js +506 -0
- package/src/animations/module.js +779 -0
- package/src/animations/ngAnimateSwap.js +119 -0
- package/src/animations/rafScheduler.js +50 -0
- package/src/animations/shared.js +378 -0
- package/src/constants.js +20 -0
- package/src/core/animate.js +845 -0
- package/src/core/animateCss.js +73 -0
- package/src/core/animateRunner.js +195 -0
- package/src/core/attributes.js +199 -0
- package/src/core/cache.js +45 -0
- package/src/core/compile.js +4727 -0
- package/src/core/controller.js +225 -0
- package/src/core/exceptionHandler.js +63 -0
- package/src/core/filter.js +146 -0
- package/src/core/interpolate.js +442 -0
- package/src/core/interval.js +188 -0
- package/src/core/intervalFactory.js +57 -0
- package/src/core/location.js +1086 -0
- package/src/core/parser/parse.js +2562 -0
- package/src/core/parser/parse.md +13 -0
- package/src/core/q.js +746 -0
- package/src/core/rootScope.js +1596 -0
- package/src/core/sanitizeUri.js +85 -0
- package/src/core/sce.js +1161 -0
- package/src/core/taskTrackerFactory.js +125 -0
- package/src/core/timeout.js +121 -0
- package/src/core/urlUtils.js +187 -0
- package/src/core/utils.js +1349 -0
- package/src/directive/a.js +37 -0
- package/src/directive/attrs.js +283 -0
- package/src/directive/bind.js +51 -0
- package/src/directive/bind.md +142 -0
- package/src/directive/change.js +12 -0
- package/src/directive/change.md +25 -0
- package/src/directive/cloak.js +12 -0
- package/src/directive/cloak.md +24 -0
- package/src/directive/events.js +75 -0
- package/src/directive/events.md +166 -0
- package/src/directive/form.js +725 -0
- package/src/directive/init.js +15 -0
- package/src/directive/init.md +41 -0
- package/src/directive/input.js +1783 -0
- package/src/directive/list.js +46 -0
- package/src/directive/list.md +22 -0
- package/src/directive/ngClass.js +249 -0
- package/src/directive/ngController.js +64 -0
- package/src/directive/ngCsp.js +82 -0
- package/src/directive/ngIf.js +134 -0
- package/src/directive/ngInclude.js +217 -0
- package/src/directive/ngModel.js +1356 -0
- package/src/directive/ngModelOptions.js +509 -0
- package/src/directive/ngOptions.js +670 -0
- package/src/directive/ngRef.js +90 -0
- package/src/directive/ngRepeat.js +650 -0
- package/src/directive/ngShowHide.js +255 -0
- package/src/directive/ngSwitch.js +178 -0
- package/src/directive/ngTransclude.js +98 -0
- package/src/directive/non-bindable.js +11 -0
- package/src/directive/non-bindable.md +17 -0
- package/src/directive/script.js +30 -0
- package/src/directive/select.js +624 -0
- package/src/directive/style.js +25 -0
- package/src/directive/style.md +23 -0
- package/src/directive/validators.js +329 -0
- package/src/exts/aria.js +544 -0
- package/src/exts/messages.js +852 -0
- package/src/filters/filter.js +207 -0
- package/src/filters/filter.md +69 -0
- package/src/filters/filters.js +239 -0
- package/src/filters/json.md +16 -0
- package/src/filters/limit-to.js +43 -0
- package/src/filters/limit-to.md +19 -0
- package/src/filters/order-by.js +183 -0
- package/src/filters/order-by.md +83 -0
- package/src/index.js +13 -0
- package/src/injector.js +1034 -0
- package/src/jqLite.js +1117 -0
- package/src/loader.js +1320 -0
- package/src/public.js +215 -0
- package/src/routeToRegExp.js +41 -0
- package/src/services/anchorScroll.js +135 -0
- package/src/services/browser.js +321 -0
- package/src/services/cacheFactory.js +398 -0
- package/src/services/cookieReader.js +72 -0
- package/src/services/document.js +64 -0
- package/src/services/http.js +1537 -0
- package/src/services/httpBackend.js +206 -0
- package/src/services/log.js +160 -0
- package/src/services/templateRequest.js +139 -0
- package/test/angular.spec.js +2153 -0
- package/test/aria/aria.spec.js +1245 -0
- package/test/binding.spec.js +504 -0
- package/test/build-test.html +14 -0
- package/test/injector.spec.js +2327 -0
- package/test/jasmine/jasmine-5.1.2/boot0.js +65 -0
- package/test/jasmine/jasmine-5.1.2/boot1.js +133 -0
- package/test/jasmine/jasmine-5.1.2/jasmine-html.js +963 -0
- package/test/jasmine/jasmine-5.1.2/jasmine.css +320 -0
- package/test/jasmine/jasmine-5.1.2/jasmine.js +10824 -0
- package/test/jasmine/jasmine-5.1.2/jasmine_favicon.png +0 -0
- package/test/jasmine/jasmine-browser.json +17 -0
- package/test/jasmine/jasmine.json +9 -0
- package/test/jqlite.spec.js +2133 -0
- package/test/loader.spec.js +219 -0
- package/test/messages/messages.spec.js +1146 -0
- package/test/min-err.spec.js +174 -0
- package/test/mock-test.html +13 -0
- package/test/module-test.html +15 -0
- package/test/ng/anomate.spec.js +606 -0
- package/test/ng/cache-factor.spec.js +334 -0
- package/test/ng/compile.spec.js +17956 -0
- package/test/ng/controller-provider.spec.js +227 -0
- package/test/ng/cookie-reader.spec.js +98 -0
- package/test/ng/directive/a.spec.js +192 -0
- package/test/ng/directive/bind.spec.js +334 -0
- package/test/ng/directive/boolean.spec.js +136 -0
- package/test/ng/directive/change.spec.js +71 -0
- package/test/ng/directive/class.spec.js +858 -0
- package/test/ng/directive/click.spec.js +38 -0
- package/test/ng/directive/cloak.spec.js +44 -0
- package/test/ng/directive/constoller.spec.js +194 -0
- package/test/ng/directive/element-style.spec.js +92 -0
- package/test/ng/directive/event.spec.js +282 -0
- package/test/ng/directive/form.spec.js +1518 -0
- package/test/ng/directive/href.spec.js +143 -0
- package/test/ng/directive/if.spec.js +402 -0
- package/test/ng/directive/include.spec.js +828 -0
- package/test/ng/directive/init.spec.js +68 -0
- package/test/ng/directive/input.spec.js +3810 -0
- package/test/ng/directive/list.spec.js +170 -0
- package/test/ng/directive/model-options.spec.js +1008 -0
- package/test/ng/directive/model.spec.js +1905 -0
- package/test/ng/directive/non-bindable.spec.js +55 -0
- package/test/ng/directive/options.spec.js +3583 -0
- package/test/ng/directive/ref.spec.js +575 -0
- package/test/ng/directive/repeat.spec.js +1675 -0
- package/test/ng/directive/script.spec.js +52 -0
- package/test/ng/directive/scrset.spec.js +67 -0
- package/test/ng/directive/select.spec.js +2541 -0
- package/test/ng/directive/show-hide.spec.js +253 -0
- package/test/ng/directive/src.spec.js +157 -0
- package/test/ng/directive/style.spec.js +178 -0
- package/test/ng/directive/switch.spec.js +647 -0
- package/test/ng/directive/validators.spec.js +717 -0
- package/test/ng/document.spec.js +52 -0
- package/test/ng/filter/filter.spec.js +714 -0
- package/test/ng/filter/filters.spec.js +35 -0
- package/test/ng/filter/limit-to.spec.js +251 -0
- package/test/ng/filter/order-by.spec.js +891 -0
- package/test/ng/filter.spec.js +149 -0
- package/test/ng/http-backend.spec.js +398 -0
- package/test/ng/http.spec.js +4071 -0
- package/test/ng/interpolate.spec.js +642 -0
- package/test/ng/interval.spec.js +343 -0
- package/test/ng/location.spec.js +3488 -0
- package/test/ng/on.spec.js +229 -0
- package/test/ng/parse.spec.js +4655 -0
- package/test/ng/prop.spec.js +805 -0
- package/test/ng/q.spec.js +2904 -0
- package/test/ng/root-element.spec.js +16 -0
- package/test/ng/sanitize-uri.spec.js +249 -0
- package/test/ng/sce.spec.js +660 -0
- package/test/ng/scope.spec.js +3442 -0
- package/test/ng/template-request.spec.js +236 -0
- package/test/ng/timeout.spec.js +351 -0
- package/test/ng/url-utils.spec.js +156 -0
- package/test/ng/utils.spec.js +144 -0
- package/test/original-test.html +21 -0
- package/test/public.spec.js +34 -0
- package/test/sanitize/bing-html.spec.js +36 -0
- package/test/server/express.js +158 -0
- package/test/test-utils.js +11 -0
- package/tsconfig.json +17 -0
- package/types/angular.d.ts +138 -0
- package/types/global.d.ts +9 -0
- package/types/index.d.ts +2357 -0
- package/types/jqlite.d.ts +558 -0
- package/vite.config.js +14 -0
|
@@ -0,0 +1,1349 @@
|
|
|
1
|
+
import { PREFIX_REGEXP, SPECIAL_CHARS_REGEXP } from "../constants";
|
|
2
|
+
|
|
3
|
+
const ngMinErr = minErr("ng");
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @type {number}
|
|
7
|
+
*/
|
|
8
|
+
let uid = 0;
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* A consistent way of creating unique IDs in angular.
|
|
12
|
+
*
|
|
13
|
+
* Using simple numbers allows us to generate 28.6 million unique ids per second for 10 years before
|
|
14
|
+
* we hit number precision issues in JavaScript.
|
|
15
|
+
*
|
|
16
|
+
* Math.pow(2,53) / 60 / 60 / 24 / 365 / 10 = 28.6M
|
|
17
|
+
*
|
|
18
|
+
* @returns {number} an unique alpha-numeric string
|
|
19
|
+
*/
|
|
20
|
+
export function nextUid() {
|
|
21
|
+
uid += 1;
|
|
22
|
+
return uid;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
*
|
|
27
|
+
* @description Converts the specified string to lowercase.
|
|
28
|
+
* @param {string} string String to be converted to lowercase.
|
|
29
|
+
* @returns {string} Lowercased string.
|
|
30
|
+
*/
|
|
31
|
+
export function lowercase(string) {
|
|
32
|
+
return isString(string) ? string.toLowerCase() : string;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
*
|
|
37
|
+
* @description Converts the specified string to uppercase.
|
|
38
|
+
* @param {string} string String to be converted to uppercase.
|
|
39
|
+
* @returns {string} Uppercased string.
|
|
40
|
+
*/
|
|
41
|
+
export function uppercase(string) {
|
|
42
|
+
return isString(string) ? string.toUpperCase() : string;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* @param {*} obj
|
|
47
|
+
* @return {boolean} Returns true if `obj` is an array or array-like object (NodeList, Arguments,
|
|
48
|
+
* String ...)
|
|
49
|
+
*/
|
|
50
|
+
export function isArrayLike(obj) {
|
|
51
|
+
// `null`, `undefined` and `window` are not array-like
|
|
52
|
+
if (obj == null || isWindow(obj)) return false;
|
|
53
|
+
|
|
54
|
+
// arrays, strings and jQuery/jqLite objects are array like
|
|
55
|
+
// * we have to check the existence of jqLite first as this method is called
|
|
56
|
+
// via the forEach method when constructing the jqLite object in the first place
|
|
57
|
+
if (isArray(obj) || isString(obj)) return true;
|
|
58
|
+
|
|
59
|
+
// Support: iOS 8.2 (not reproducible in simulator)
|
|
60
|
+
// "length" in obj used to prevent JIT error (gh-11508)
|
|
61
|
+
const length = "length" in Object(obj) && obj.length;
|
|
62
|
+
|
|
63
|
+
// NodeList objects (with `item` method) and
|
|
64
|
+
// other objects with suitable length characteristics are array-like
|
|
65
|
+
return (
|
|
66
|
+
isNumber(length) &&
|
|
67
|
+
((length >= 0 && length - 1 in obj) || typeof obj.item === "function")
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* @module angular
|
|
73
|
+
* @function isUndefined
|
|
74
|
+
*
|
|
75
|
+
* @description
|
|
76
|
+
* Determines if a reference is undefined.
|
|
77
|
+
*
|
|
78
|
+
* @param {*} value Reference to check.
|
|
79
|
+
* @returns {boolean} True if `value` is undefined.
|
|
80
|
+
*/
|
|
81
|
+
export function isUndefined(value) {
|
|
82
|
+
return typeof value === "undefined";
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* @module angular
|
|
87
|
+
* @function isDefined
|
|
88
|
+
*
|
|
89
|
+
* @description
|
|
90
|
+
* Determines if a reference is defined.
|
|
91
|
+
*
|
|
92
|
+
* @param {*} value Reference to check.
|
|
93
|
+
* @returns {boolean} True if `value` is defined.
|
|
94
|
+
*/
|
|
95
|
+
export function isDefined(value) {
|
|
96
|
+
return typeof value !== "undefined";
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* @module angular
|
|
101
|
+
* @function isObject
|
|
102
|
+
*
|
|
103
|
+
* @description
|
|
104
|
+
* Determines if a reference is an `Object`. Unlike `typeof` in JavaScript, `null`s are not
|
|
105
|
+
* considered to be objects. Note that JavaScript arrays are objects.
|
|
106
|
+
*
|
|
107
|
+
* @param {*} value Reference to check.
|
|
108
|
+
* @returns {boolean} True if `value` is an `Object` but not `null`.
|
|
109
|
+
*/
|
|
110
|
+
export function isObject(value) {
|
|
111
|
+
// http://jsperf.com/isobject4
|
|
112
|
+
return value !== null && typeof value === "object";
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Determine if a value is an object with a null prototype
|
|
117
|
+
*
|
|
118
|
+
* @returns {boolean} True if `value` is an `Object` with a null prototype
|
|
119
|
+
*/
|
|
120
|
+
export function isBlankObject(value) {
|
|
121
|
+
return (
|
|
122
|
+
value !== null && typeof value === "object" && !Object.getPrototypeOf(value)
|
|
123
|
+
);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* @module angular
|
|
128
|
+
* @function isString
|
|
129
|
+
*
|
|
130
|
+
* @description
|
|
131
|
+
* Determines if a reference is a `String`.
|
|
132
|
+
*
|
|
133
|
+
* @param {*} value Reference to check.
|
|
134
|
+
* @returns {boolean} True if `value` is a `String`.
|
|
135
|
+
*/
|
|
136
|
+
export function isString(value) {
|
|
137
|
+
return typeof value === "string";
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* @module angular
|
|
142
|
+
* @function isNumber
|
|
143
|
+
*
|
|
144
|
+
* @description
|
|
145
|
+
* Determines if a reference is a `Number`.
|
|
146
|
+
*
|
|
147
|
+
* This includes the "special" numbers `NaN`, `+Infinity` and `-Infinity`.
|
|
148
|
+
*
|
|
149
|
+
* If you wish to exclude these then you can use the native
|
|
150
|
+
* [`isFinite'](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/isFinite)
|
|
151
|
+
* method.
|
|
152
|
+
*
|
|
153
|
+
* @param {*} value Reference to check.
|
|
154
|
+
* @returns {boolean} True if `value` is a `Number`.
|
|
155
|
+
*/
|
|
156
|
+
export function isNumber(value) {
|
|
157
|
+
return typeof value === "number";
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* @module angular
|
|
162
|
+
* @function isDate
|
|
163
|
+
*
|
|
164
|
+
* @description
|
|
165
|
+
* Determines if a value is a date.
|
|
166
|
+
*
|
|
167
|
+
* @param {*} value Reference to check.
|
|
168
|
+
* @returns {boolean} True if `value` is a `Date`.
|
|
169
|
+
*/
|
|
170
|
+
export function isDate(value) {
|
|
171
|
+
return toString.call(value) === "[object Date]";
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* @module angular
|
|
176
|
+
* @function isArray
|
|
177
|
+
* @function
|
|
178
|
+
*
|
|
179
|
+
* @description
|
|
180
|
+
* Determines if a reference is an `Array`.
|
|
181
|
+
*
|
|
182
|
+
* @param {*} arr Reference to check.
|
|
183
|
+
* @returns {boolean} True if `value` is an `Array`.
|
|
184
|
+
*/
|
|
185
|
+
export function isArray(arr) {
|
|
186
|
+
return Array.isArray(arr) || arr instanceof Array;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* @description
|
|
191
|
+
* Determines if a reference is an `Error`.
|
|
192
|
+
* Loosely based on https://www.npmjs.com/package/iserror
|
|
193
|
+
*
|
|
194
|
+
* @param {*} value Reference to check.
|
|
195
|
+
* @returns {boolean} True if `value` is an `Error`.
|
|
196
|
+
*/
|
|
197
|
+
export function isError(value) {
|
|
198
|
+
const tag = toString.call(value);
|
|
199
|
+
switch (tag) {
|
|
200
|
+
case "[object Error]":
|
|
201
|
+
return true;
|
|
202
|
+
case "[object Exception]":
|
|
203
|
+
return true;
|
|
204
|
+
case "[object DOMException]":
|
|
205
|
+
return true;
|
|
206
|
+
default:
|
|
207
|
+
return value instanceof Error;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* @module angular
|
|
213
|
+
* @function isFunction
|
|
214
|
+
|
|
215
|
+
* @function
|
|
216
|
+
*
|
|
217
|
+
* @description
|
|
218
|
+
* Determines if a reference is a `Function`.
|
|
219
|
+
*
|
|
220
|
+
* @param {*} value Reference to check.
|
|
221
|
+
* @returns {boolean} True if `value` is a `Function`.
|
|
222
|
+
*/
|
|
223
|
+
export function isFunction(value) {
|
|
224
|
+
return typeof value === "function";
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
/**
|
|
228
|
+
* Determines if a value is a regular expression object.
|
|
229
|
+
*
|
|
230
|
+
* @private
|
|
231
|
+
* @param {*} value Reference to check.
|
|
232
|
+
* @returns {boolean} True if `value` is a `RegExp`.
|
|
233
|
+
*/
|
|
234
|
+
export function isRegExp(value) {
|
|
235
|
+
return toString.call(value) === "[object RegExp]";
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
/**
|
|
239
|
+
* Checks if `obj` is a window object.
|
|
240
|
+
*
|
|
241
|
+
* @private
|
|
242
|
+
* @param {*} obj Object to check
|
|
243
|
+
* @returns {boolean} True if `obj` is a window obj.
|
|
244
|
+
*/
|
|
245
|
+
export function isWindow(obj) {
|
|
246
|
+
return obj && obj.window === obj;
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
/**
|
|
250
|
+
* @param {*} obj
|
|
251
|
+
* @returns {boolean}
|
|
252
|
+
*/
|
|
253
|
+
export function isScope(obj) {
|
|
254
|
+
return obj && obj.$evalAsync && obj.$watch;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
/**
|
|
258
|
+
* @param {*} obj
|
|
259
|
+
* @returns {boolean}
|
|
260
|
+
*/
|
|
261
|
+
export function isFile(obj) {
|
|
262
|
+
return toString.call(obj) === "[object File]";
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
/**
|
|
266
|
+
* @param {*} obj
|
|
267
|
+
* @returns {boolean}
|
|
268
|
+
*/
|
|
269
|
+
export function isFormData(obj) {
|
|
270
|
+
return toString.call(obj) === "[object FormData]";
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
/**
|
|
274
|
+
* @param {*} obj
|
|
275
|
+
* @returns {boolean}
|
|
276
|
+
*/
|
|
277
|
+
export function isBlob(obj) {
|
|
278
|
+
return toString.call(obj) === "[object Blob]";
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
/**
|
|
282
|
+
* @param {*} value
|
|
283
|
+
* @returns {boolean}
|
|
284
|
+
*/
|
|
285
|
+
export function isBoolean(value) {
|
|
286
|
+
return typeof value === "boolean";
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
/**
|
|
290
|
+
* @param {*} obj
|
|
291
|
+
* @returns {boolean}
|
|
292
|
+
*/
|
|
293
|
+
export function isPromiseLike(obj) {
|
|
294
|
+
return obj && isFunction(obj.then);
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
/**
|
|
298
|
+
* @param {*} value
|
|
299
|
+
* @returns {boolean}
|
|
300
|
+
*/
|
|
301
|
+
export function isTypedArray(value) {
|
|
302
|
+
return (
|
|
303
|
+
value &&
|
|
304
|
+
isNumber(value.length) &&
|
|
305
|
+
/^\[object (?:Uint8|Uint8Clamped|Uint16|Uint32|Int8|Int16|Int32|Float32|Float64)Array]$/.test(
|
|
306
|
+
toString.call(value),
|
|
307
|
+
)
|
|
308
|
+
);
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
/**
|
|
312
|
+
* @param {*} obj
|
|
313
|
+
* @returns {boolean}
|
|
314
|
+
*/
|
|
315
|
+
export function isArrayBuffer(obj) {
|
|
316
|
+
return toString.call(obj) === "[object ArrayBuffer]";
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
/**
|
|
320
|
+
* @param {*} value
|
|
321
|
+
* @returns {string | *}
|
|
322
|
+
*/
|
|
323
|
+
export function trim(value) {
|
|
324
|
+
return isString(value) ? value.trim() : value;
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
// eslint-disable-next-line camelcase
|
|
328
|
+
export function snakeCase(name, separator) {
|
|
329
|
+
const modseparator = separator || "_";
|
|
330
|
+
return name.replace(
|
|
331
|
+
/[A-Z]/g,
|
|
332
|
+
(letter, pos) => (pos ? modseparator : "") + letter.toLowerCase(),
|
|
333
|
+
);
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
/**
|
|
337
|
+
* @module angular
|
|
338
|
+
* @function forEach
|
|
339
|
+
*
|
|
340
|
+
* @description
|
|
341
|
+
* Invokes the `iterator` function once for each item in `obj` collection, which can be either an
|
|
342
|
+
* object or an array. The `iterator` function is invoked with `iterator(value, key, obj)`, where `value`
|
|
343
|
+
* is the value of an object property or an array element, `key` is the object property key or
|
|
344
|
+
* array element index and obj is the `obj` itself. Specifying a `context` for the function is optional.
|
|
345
|
+
*
|
|
346
|
+
* It is worth noting that `.forEach` does not iterate over inherited properties because it filters
|
|
347
|
+
* using the `hasOwnProperty` method.
|
|
348
|
+
*
|
|
349
|
+
* Unlike ES262's
|
|
350
|
+
* [Array.prototype.forEach](http://www.ecma-international.org/ecma-262/5.1/#sec-15.4.4.18),
|
|
351
|
+
* providing 'undefined' or 'null' values for `obj` will not throw a TypeError, but rather just
|
|
352
|
+
* return the value provided.
|
|
353
|
+
*
|
|
354
|
+
```js
|
|
355
|
+
let values = {name: 'misko', gender: 'male'};
|
|
356
|
+
let log = [];
|
|
357
|
+
angular.forEach(values, function(value, key) {
|
|
358
|
+
this.push(key + ': ' + value);
|
|
359
|
+
}, log);
|
|
360
|
+
expect(log).toEqual(['name: misko', 'gender: male']);
|
|
361
|
+
```
|
|
362
|
+
*
|
|
363
|
+
* @param {Object|Array} obj Object to iterate over.
|
|
364
|
+
* @param {Function} iterator Iterator function.
|
|
365
|
+
* @param {Object=} context Object to become context (`this`) for the iterator function.
|
|
366
|
+
* @returns {Object|Array} Reference to `obj`.
|
|
367
|
+
*/
|
|
368
|
+
export function forEach(obj, iterator, context) {
|
|
369
|
+
let key;
|
|
370
|
+
let length;
|
|
371
|
+
if (obj) {
|
|
372
|
+
if (isFunction(obj)) {
|
|
373
|
+
for (key in obj) {
|
|
374
|
+
if (
|
|
375
|
+
key !== "prototype" &&
|
|
376
|
+
key !== "length" &&
|
|
377
|
+
key !== "name" &&
|
|
378
|
+
Object.prototype.hasOwnProperty.call(obj, key)
|
|
379
|
+
) {
|
|
380
|
+
iterator.call(context, obj[key], key, obj);
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
} else if (isArray(obj) || isArrayLike(obj)) {
|
|
384
|
+
const isPrimitive = typeof obj !== "object";
|
|
385
|
+
for (key = 0, length = obj.length; key < length; key++) {
|
|
386
|
+
if (isPrimitive || key in obj) {
|
|
387
|
+
iterator.call(context, obj[key], key, obj);
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
} else if (obj.forEach && obj.forEach !== forEach) {
|
|
391
|
+
obj.forEach(iterator, context, obj);
|
|
392
|
+
} else if (isBlankObject(obj)) {
|
|
393
|
+
// createMap() fast path --- Safe to avoid hasOwnProperty check because prototype chain is empty
|
|
394
|
+
for (key in obj) {
|
|
395
|
+
iterator.call(context, obj[key], key, obj);
|
|
396
|
+
}
|
|
397
|
+
} else {
|
|
398
|
+
// Slow path for objects which do not have a method `hasOwnProperty`
|
|
399
|
+
for (key in obj) {
|
|
400
|
+
if (Object.hasOwnProperty.call(obj, key)) {
|
|
401
|
+
iterator.call(context, obj[key], key, obj);
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
return obj;
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
export function forEachSorted(obj, iterator, context) {
|
|
410
|
+
const keys = Object.keys(obj).sort();
|
|
411
|
+
keys.forEach((el) => iterator.call(context, obj[el], el));
|
|
412
|
+
return keys;
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
/**
|
|
416
|
+
* when using forEach the params are value, key, but it is often useful to have key, value.
|
|
417
|
+
* @param {function(string, *)} iteratorFn
|
|
418
|
+
* @returns {function(*, string)}
|
|
419
|
+
*/
|
|
420
|
+
export function reverseParams(iteratorFn) {
|
|
421
|
+
return function (value, key) {
|
|
422
|
+
iteratorFn(key, value);
|
|
423
|
+
};
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
/**
|
|
427
|
+
* Set or clear the hashkey for an object.
|
|
428
|
+
* @param obj object
|
|
429
|
+
* @param h the hashkey (!truthy to delete the hashkey)
|
|
430
|
+
*/
|
|
431
|
+
export function setHashKey(obj, h) {
|
|
432
|
+
if (h) {
|
|
433
|
+
obj.$$hashKey = h;
|
|
434
|
+
} else {
|
|
435
|
+
delete obj.$$hashKey;
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
export function baseExtend(dst, objs, deep) {
|
|
440
|
+
const h = dst.$$hashKey;
|
|
441
|
+
|
|
442
|
+
for (let i = 0, ii = objs.length; i < ii; ++i) {
|
|
443
|
+
const obj = objs[i];
|
|
444
|
+
if (!isObject(obj) && !isFunction(obj)) continue;
|
|
445
|
+
const keys = Object.keys(obj);
|
|
446
|
+
for (let j = 0, jj = keys.length; j < jj; j++) {
|
|
447
|
+
const key = keys[j];
|
|
448
|
+
const src = obj[key];
|
|
449
|
+
|
|
450
|
+
if (deep && isObject(src)) {
|
|
451
|
+
if (isDate(src)) {
|
|
452
|
+
dst[key] = new Date(src.valueOf());
|
|
453
|
+
} else if (isRegExp(src)) {
|
|
454
|
+
dst[key] = new RegExp(src);
|
|
455
|
+
} else if (src.nodeName) {
|
|
456
|
+
dst[key] = src.cloneNode(true);
|
|
457
|
+
} else if (isElement(src)) {
|
|
458
|
+
dst[key] = src[0].cloneNode(true);
|
|
459
|
+
} else if (key !== "__proto__") {
|
|
460
|
+
if (!isObject(dst[key])) dst[key] = isArray(src) ? [] : {};
|
|
461
|
+
baseExtend(dst[key], [src], true);
|
|
462
|
+
}
|
|
463
|
+
} else {
|
|
464
|
+
dst[key] = src;
|
|
465
|
+
}
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
setHashKey(dst, h);
|
|
470
|
+
return dst;
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
/**
|
|
474
|
+
* @module angular
|
|
475
|
+
* @function extend
|
|
476
|
+
|
|
477
|
+
* @function
|
|
478
|
+
*
|
|
479
|
+
* @description
|
|
480
|
+
* Extends the destination object `dst` by copying own enumerable properties from the `src` object(s)
|
|
481
|
+
* to `dst`. You can specify multiple `src` objects. If you want to preserve original objects, you can do so
|
|
482
|
+
* by passing an empty object as the target: `let object = angular.extend({}, object1, object2)`.
|
|
483
|
+
*
|
|
484
|
+
* **Note:** Keep in mind that `angular.extend` does not support recursive merge (deep copy). Use
|
|
485
|
+
* {@link angular.merge} for this.
|
|
486
|
+
*
|
|
487
|
+
* @param {Object} dst Destination object.
|
|
488
|
+
* @param {...Object} src Source object(s).
|
|
489
|
+
* @returns {Object} Reference to `dst`.
|
|
490
|
+
*/
|
|
491
|
+
export function extend(dst) {
|
|
492
|
+
return baseExtend(dst, [].slice.call(arguments, 1), false);
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
/**
|
|
496
|
+
* @module angular
|
|
497
|
+
* @function merge
|
|
498
|
+
|
|
499
|
+
* @function
|
|
500
|
+
*
|
|
501
|
+
* @description
|
|
502
|
+
* Deeply extends the destination object `dst` by copying own enumerable properties from the `src` object(s)
|
|
503
|
+
* to `dst`. You can specify multiple `src` objects. If you want to preserve original objects, you can do so
|
|
504
|
+
* by passing an empty object as the target: `let object = angular.merge({}, object1, object2)`.
|
|
505
|
+
*
|
|
506
|
+
* Unlike {@link angular.extend extend()}, `merge()` recursively descends into object properties of source
|
|
507
|
+
* objects, performing a deep copy.
|
|
508
|
+
*
|
|
509
|
+
* @deprecated
|
|
510
|
+
* sinceVersion="1.6.5"
|
|
511
|
+
* This function is deprecated, but will not be removed in the 1.x lifecycle.
|
|
512
|
+
* There are edge cases (see {@link angular.merge#known-issues known issues}) that are not
|
|
513
|
+
* supported by this function. We suggest using another, similar library for all-purpose merging,
|
|
514
|
+
* such as [lodash's merge()](https://lodash.com/docs/4.17.4#merge).
|
|
515
|
+
*
|
|
516
|
+
* @knownIssue
|
|
517
|
+
* This is a list of (known) object types that are not handled correctly by this function:
|
|
518
|
+
* - [`Blob`](https://developer.mozilla.org/docs/Web/API/Blob)
|
|
519
|
+
* - [`MediaStream`](https://developer.mozilla.org/docs/Web/API/MediaStream)
|
|
520
|
+
* - [`CanvasGradient`](https://developer.mozilla.org/docs/Web/API/CanvasGradient)
|
|
521
|
+
* - AngularJS {@link $rootScope.Scope scopes};
|
|
522
|
+
*
|
|
523
|
+
* `angular.merge` also does not support merging objects with circular references.
|
|
524
|
+
*
|
|
525
|
+
* @param {Object} dst Destination object.
|
|
526
|
+
* @param {...Object} src Source object(s).
|
|
527
|
+
* @returns {Object} Reference to `dst`.
|
|
528
|
+
*/
|
|
529
|
+
export function merge(dst) {
|
|
530
|
+
return baseExtend(dst, Array.prototype.slice.call(arguments, 1), true);
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
export function toInt(str) {
|
|
534
|
+
return parseInt(str, 10);
|
|
535
|
+
}
|
|
536
|
+
|
|
537
|
+
export function isNumberNaN(num) {
|
|
538
|
+
// eslint-disable-next-line no-self-compare
|
|
539
|
+
return Number.isNaN(num);
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
export function inherit(parent, extra) {
|
|
543
|
+
return extend(Object.create(parent), extra);
|
|
544
|
+
}
|
|
545
|
+
|
|
546
|
+
/**
|
|
547
|
+
* @module angular
|
|
548
|
+
* @function identity
|
|
549
|
+
|
|
550
|
+
* @function
|
|
551
|
+
*
|
|
552
|
+
* @description
|
|
553
|
+
* A function that returns its first argument. This function is useful when writing code in the
|
|
554
|
+
* functional style.
|
|
555
|
+
*
|
|
556
|
+
```js
|
|
557
|
+
function transformer(transformationFn, value) {
|
|
558
|
+
return (transformationFn || angular.identity)(value);
|
|
559
|
+
};
|
|
560
|
+
|
|
561
|
+
// E.g.
|
|
562
|
+
function getResult(fn, input) {
|
|
563
|
+
return (fn || angular.identity)(input);
|
|
564
|
+
};
|
|
565
|
+
|
|
566
|
+
getResult(function(n) { return n * 2; }, 21); // returns 42
|
|
567
|
+
getResult(null, 21); // returns 21
|
|
568
|
+
getResult(undefined, 21); // returns 21
|
|
569
|
+
```
|
|
570
|
+
*
|
|
571
|
+
* @param {*} value to be returned.
|
|
572
|
+
* @returns {*} the value passed in.
|
|
573
|
+
*/
|
|
574
|
+
export function identity(value) {
|
|
575
|
+
return value;
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
/**
|
|
579
|
+
* @param {*} value
|
|
580
|
+
* @returns {() => *}
|
|
581
|
+
*/
|
|
582
|
+
export function valueFn(value) {
|
|
583
|
+
return function valueRef() {
|
|
584
|
+
return value;
|
|
585
|
+
};
|
|
586
|
+
}
|
|
587
|
+
|
|
588
|
+
export function hasCustomToString(obj) {
|
|
589
|
+
return isFunction(obj.toString) && obj.toString !== toString;
|
|
590
|
+
}
|
|
591
|
+
|
|
592
|
+
/**
|
|
593
|
+
* @module angular
|
|
594
|
+
* @function isElement
|
|
595
|
+
|
|
596
|
+
* @function
|
|
597
|
+
*
|
|
598
|
+
* @description
|
|
599
|
+
* Determines if a reference is a DOM element (or wrapped jQuery element).
|
|
600
|
+
*
|
|
601
|
+
* @param {*} node Reference to check.
|
|
602
|
+
* @returns {boolean} True if `value` is a DOM element (or wrapped jQuery element).
|
|
603
|
+
*/
|
|
604
|
+
export function isElement(node) {
|
|
605
|
+
return !!(
|
|
606
|
+
node &&
|
|
607
|
+
(node.nodeName || // We are a direct element.
|
|
608
|
+
(node.prop && node.attr && node.find))
|
|
609
|
+
); // We have an on and find method part of jQuery API.
|
|
610
|
+
}
|
|
611
|
+
|
|
612
|
+
export function nodeName_(element) {
|
|
613
|
+
return lowercase(element.nodeName || (element[0] && element[0].nodeName));
|
|
614
|
+
}
|
|
615
|
+
|
|
616
|
+
export function includes(array, obj) {
|
|
617
|
+
return Array.prototype.indexOf.call(array, obj) !== -1;
|
|
618
|
+
}
|
|
619
|
+
|
|
620
|
+
export function arrayRemove(array, value) {
|
|
621
|
+
const index = array.indexOf(value);
|
|
622
|
+
if (index >= 0) {
|
|
623
|
+
array.splice(index, 1);
|
|
624
|
+
}
|
|
625
|
+
return index;
|
|
626
|
+
}
|
|
627
|
+
|
|
628
|
+
export function simpleCompare(a, b) {
|
|
629
|
+
return a === b || (a !== a && b !== b);
|
|
630
|
+
}
|
|
631
|
+
|
|
632
|
+
/**
|
|
633
|
+
* @module angular
|
|
634
|
+
* @function equals
|
|
635
|
+
|
|
636
|
+
* @function
|
|
637
|
+
*
|
|
638
|
+
* @description
|
|
639
|
+
* Determines if two objects or two values are equivalent. Supports value types, regular
|
|
640
|
+
* expressions, arrays and objects.
|
|
641
|
+
*
|
|
642
|
+
* Two objects or values are considered equivalent if at least one of the following is true:
|
|
643
|
+
*
|
|
644
|
+
* * Both objects or values pass `===` comparison.
|
|
645
|
+
* * Both objects or values are of the same type and all of their properties are equal by
|
|
646
|
+
* comparing them with `angular.equals`.
|
|
647
|
+
* * Both values are NaN. (In JavaScript, NaN == NaN => false. But we consider two NaN as equal)
|
|
648
|
+
* * Both values represent the same regular expression (In JavaScript,
|
|
649
|
+
* /abc/ == /abc/ => false. But we consider two regular expressions as equal when their textual
|
|
650
|
+
* representation matches).
|
|
651
|
+
*
|
|
652
|
+
* During a property comparison, properties of `function` type and properties with names
|
|
653
|
+
* that begin with `$` are ignored.
|
|
654
|
+
*
|
|
655
|
+
* Scope and DOMWindow objects are being compared only by identify (`===`).
|
|
656
|
+
*
|
|
657
|
+
* @param {*} o1 Object or value to compare.
|
|
658
|
+
* @param {*} o2 Object or value to compare.
|
|
659
|
+
* @returns {boolean} True if arguments are equal.
|
|
660
|
+
*
|
|
661
|
+
* @example
|
|
662
|
+
<example module="equalsExample" name="equalsExample">
|
|
663
|
+
<file name="index.html">
|
|
664
|
+
<div ng-controller="ExampleController">
|
|
665
|
+
<form novalidate>
|
|
666
|
+
<h3>User 1</h3>
|
|
667
|
+
Name: <input type="text" ng-model="user1.name">
|
|
668
|
+
Age: <input type="number" ng-model="user1.age">
|
|
669
|
+
|
|
670
|
+
<h3>User 2</h3>
|
|
671
|
+
Name: <input type="text" ng-model="user2.name">
|
|
672
|
+
Age: <input type="number" ng-model="user2.age">
|
|
673
|
+
|
|
674
|
+
<div>
|
|
675
|
+
<br/>
|
|
676
|
+
<input type="button" value="Compare" ng-click="compare()">
|
|
677
|
+
</div>
|
|
678
|
+
User 1: <pre>{{user1 | json}}</pre>
|
|
679
|
+
User 2: <pre>{{user2 | json}}</pre>
|
|
680
|
+
Equal: <pre>{{result}}</pre>
|
|
681
|
+
</form>
|
|
682
|
+
</div>
|
|
683
|
+
</file>
|
|
684
|
+
<file name="script.js">
|
|
685
|
+
angular.module('equalsExample', []).controller('ExampleController', ['$scope', function($scope) {
|
|
686
|
+
$scope.user1 = {};
|
|
687
|
+
$scope.user2 = {};
|
|
688
|
+
$scope.compare = function() {
|
|
689
|
+
$scope.result = angular.equals($scope.user1, $scope.user2);
|
|
690
|
+
};
|
|
691
|
+
}]);
|
|
692
|
+
</file>
|
|
693
|
+
</example>
|
|
694
|
+
*/
|
|
695
|
+
export function equals(o1, o2) {
|
|
696
|
+
if (o1 === o2) return true;
|
|
697
|
+
if (o1 === null || o2 === null) return false;
|
|
698
|
+
// eslint-disable-next-line no-self-compare
|
|
699
|
+
if (o1 !== o1 && o2 !== o2) return true; // NaN === NaN
|
|
700
|
+
const t1 = typeof o1;
|
|
701
|
+
const t2 = typeof o2;
|
|
702
|
+
let length;
|
|
703
|
+
let key;
|
|
704
|
+
let keySet;
|
|
705
|
+
if (t1 === t2 && t1 === "object") {
|
|
706
|
+
if (isArray(o1)) {
|
|
707
|
+
if (!isArray(o2)) return false;
|
|
708
|
+
if ((length = o1.length) === o2.length) {
|
|
709
|
+
for (key = 0; key < length; key++) {
|
|
710
|
+
if (!equals(o1[key], o2[key])) return false;
|
|
711
|
+
}
|
|
712
|
+
return true;
|
|
713
|
+
}
|
|
714
|
+
} else if (isDate(o1)) {
|
|
715
|
+
if (!isDate(o2)) return false;
|
|
716
|
+
return simpleCompare(o1.getTime(), o2.getTime());
|
|
717
|
+
} else if (isRegExp(o1)) {
|
|
718
|
+
if (!isRegExp(o2)) return false;
|
|
719
|
+
return o1.toString() === o2.toString();
|
|
720
|
+
} else {
|
|
721
|
+
if (
|
|
722
|
+
isScope(o1) ||
|
|
723
|
+
isScope(o2) ||
|
|
724
|
+
isWindow(o1) ||
|
|
725
|
+
isWindow(o2) ||
|
|
726
|
+
isArray(o2) ||
|
|
727
|
+
isDate(o2) ||
|
|
728
|
+
isRegExp(o2)
|
|
729
|
+
)
|
|
730
|
+
return false;
|
|
731
|
+
keySet = createMap();
|
|
732
|
+
for (key in o1) {
|
|
733
|
+
if (key.charAt(0) === "$" || isFunction(o1[key])) continue;
|
|
734
|
+
if (!equals(o1[key], o2[key])) return false;
|
|
735
|
+
keySet[key] = true;
|
|
736
|
+
}
|
|
737
|
+
for (key in o2) {
|
|
738
|
+
if (
|
|
739
|
+
!(key in keySet) &&
|
|
740
|
+
key.charAt(0) !== "$" &&
|
|
741
|
+
isDefined(o2[key]) &&
|
|
742
|
+
!isFunction(o2[key])
|
|
743
|
+
)
|
|
744
|
+
return false;
|
|
745
|
+
}
|
|
746
|
+
return true;
|
|
747
|
+
}
|
|
748
|
+
}
|
|
749
|
+
return false;
|
|
750
|
+
}
|
|
751
|
+
|
|
752
|
+
const cspCache = {};
|
|
753
|
+
|
|
754
|
+
export function csp() {
|
|
755
|
+
if (!isDefined(cspCache.rules)) {
|
|
756
|
+
const ngCspElement =
|
|
757
|
+
window.document.querySelector("[ng-csp]") ||
|
|
758
|
+
window.document.querySelector("[data-ng-csp]");
|
|
759
|
+
|
|
760
|
+
if (ngCspElement) {
|
|
761
|
+
const ngCspAttribute =
|
|
762
|
+
ngCspElement.getAttribute("ng-csp") ||
|
|
763
|
+
ngCspElement.getAttribute("data-ng-csp");
|
|
764
|
+
cspCache.rules = {
|
|
765
|
+
noUnsafeEval:
|
|
766
|
+
!ngCspAttribute || ngCspAttribute.indexOf("no-unsafe-eval") !== -1,
|
|
767
|
+
noInlineStyle:
|
|
768
|
+
!ngCspAttribute || ngCspAttribute.indexOf("no-inline-style") !== -1,
|
|
769
|
+
};
|
|
770
|
+
} else {
|
|
771
|
+
cspCache.rules = {
|
|
772
|
+
noUnsafeEval: noUnsafeEval(),
|
|
773
|
+
noInlineStyle: false,
|
|
774
|
+
};
|
|
775
|
+
}
|
|
776
|
+
}
|
|
777
|
+
|
|
778
|
+
return cspCache.rules;
|
|
779
|
+
|
|
780
|
+
function noUnsafeEval() {
|
|
781
|
+
try {
|
|
782
|
+
new Function("");
|
|
783
|
+
return false;
|
|
784
|
+
} catch (e) {
|
|
785
|
+
return true;
|
|
786
|
+
}
|
|
787
|
+
}
|
|
788
|
+
}
|
|
789
|
+
|
|
790
|
+
/**
|
|
791
|
+
* throw error if the name given is hasOwnProperty
|
|
792
|
+
* @param {String} name the name to test
|
|
793
|
+
* @param {String} context the context in which the name is used, such as module or directive
|
|
794
|
+
*/
|
|
795
|
+
export function assertNotHasOwnProperty(name, context) {
|
|
796
|
+
if (name === "hasOwnProperty") {
|
|
797
|
+
throw ngMinErr(
|
|
798
|
+
"badname",
|
|
799
|
+
"hasOwnProperty is not a valid {0} name",
|
|
800
|
+
context,
|
|
801
|
+
);
|
|
802
|
+
}
|
|
803
|
+
}
|
|
804
|
+
|
|
805
|
+
/**
|
|
806
|
+
* Return the value accessible from the object by path. Any undefined traversals are ignored
|
|
807
|
+
* @param {Object} obj starting object
|
|
808
|
+
* @param {String} path path to traverse
|
|
809
|
+
* @param {boolean} [bindFnToScope=true]
|
|
810
|
+
* @returns {Object} value as accessible by path
|
|
811
|
+
*/
|
|
812
|
+
// TODO(misko): this function needs to be removed
|
|
813
|
+
export function getter(obj, path, bindFnToScope) {
|
|
814
|
+
if (!path) return obj;
|
|
815
|
+
const keys = path.split(".");
|
|
816
|
+
let key;
|
|
817
|
+
let lastInstance = obj;
|
|
818
|
+
const len = keys.length;
|
|
819
|
+
|
|
820
|
+
for (let i = 0; i < len; i++) {
|
|
821
|
+
key = keys[i];
|
|
822
|
+
if (obj) {
|
|
823
|
+
obj = (lastInstance = obj)[key];
|
|
824
|
+
}
|
|
825
|
+
}
|
|
826
|
+
if (!bindFnToScope && isFunction(obj)) {
|
|
827
|
+
return bind(lastInstance, obj);
|
|
828
|
+
}
|
|
829
|
+
return obj;
|
|
830
|
+
}
|
|
831
|
+
|
|
832
|
+
/**
|
|
833
|
+
* Creates a new object without a prototype. This object is useful for lookup without having to
|
|
834
|
+
* guard against prototypically inherited properties via hasOwnProperty.
|
|
835
|
+
*
|
|
836
|
+
* Related micro-benchmarks:
|
|
837
|
+
* - http://jsperf.com/object-create2
|
|
838
|
+
* - http://jsperf.com/proto-map-lookup/2
|
|
839
|
+
* - http://jsperf.com/for-in-vs-object-keys2
|
|
840
|
+
*
|
|
841
|
+
* @returns {Object}
|
|
842
|
+
*/
|
|
843
|
+
export function createMap() {
|
|
844
|
+
return Object.create(null);
|
|
845
|
+
}
|
|
846
|
+
|
|
847
|
+
export function stringify(value) {
|
|
848
|
+
if (value == null) {
|
|
849
|
+
// null || undefined
|
|
850
|
+
return "";
|
|
851
|
+
}
|
|
852
|
+
switch (typeof value) {
|
|
853
|
+
case "string":
|
|
854
|
+
break;
|
|
855
|
+
case "number":
|
|
856
|
+
value = `${value}`;
|
|
857
|
+
break;
|
|
858
|
+
default:
|
|
859
|
+
if (hasCustomToString(value) && !isArray(value) && !isDate(value)) {
|
|
860
|
+
value = value.toString();
|
|
861
|
+
} else {
|
|
862
|
+
value = toJson(value);
|
|
863
|
+
}
|
|
864
|
+
}
|
|
865
|
+
|
|
866
|
+
return value;
|
|
867
|
+
}
|
|
868
|
+
|
|
869
|
+
/**
|
|
870
|
+
* @param {Number} maxDepth
|
|
871
|
+
* @return {boolean}
|
|
872
|
+
*/
|
|
873
|
+
export function isValidObjectMaxDepth(maxDepth) {
|
|
874
|
+
return isNumber(maxDepth) && maxDepth > 0;
|
|
875
|
+
}
|
|
876
|
+
|
|
877
|
+
export function concat(array1, array2, index) {
|
|
878
|
+
return array1.concat(Array.prototype.slice.call(array2, index));
|
|
879
|
+
}
|
|
880
|
+
|
|
881
|
+
export function sliceArgs(args, startIndex) {
|
|
882
|
+
return Array.prototype.slice.call(args, startIndex || 0);
|
|
883
|
+
}
|
|
884
|
+
|
|
885
|
+
/**
|
|
886
|
+
* @module angular
|
|
887
|
+
* @function bind
|
|
888
|
+
|
|
889
|
+
* @function
|
|
890
|
+
*
|
|
891
|
+
* @description
|
|
892
|
+
* Returns a function which calls function `fn` bound to `self` (`self` becomes the `this` for
|
|
893
|
+
* `fn`). You can supply optional `args` that are prebound to the function. This feature is also
|
|
894
|
+
* known as [partial application](http://en.wikipedia.org/wiki/Partial_application), as
|
|
895
|
+
* distinguished from [function currying](http://en.wikipedia.org/wiki/Currying#Contrast_with_partial_function_application).
|
|
896
|
+
*
|
|
897
|
+
* @param {Object} context Context which `fn` should be evaluated in.
|
|
898
|
+
* @param {*} fn Function to be bound.
|
|
899
|
+
* @returns {Function} Function that wraps the `fn` with all the specified bindings.
|
|
900
|
+
*/
|
|
901
|
+
export function bind(context, fn) {
|
|
902
|
+
const curryArgs = arguments.length > 2 ? sliceArgs(arguments, 2) : [];
|
|
903
|
+
if (isFunction(fn) && !(fn instanceof RegExp)) {
|
|
904
|
+
return curryArgs.length
|
|
905
|
+
? function () {
|
|
906
|
+
return arguments.length
|
|
907
|
+
? fn.apply(context, concat(curryArgs, arguments, 0))
|
|
908
|
+
: fn.apply(context, curryArgs);
|
|
909
|
+
}
|
|
910
|
+
: function () {
|
|
911
|
+
return arguments.length
|
|
912
|
+
? fn.apply(context, arguments)
|
|
913
|
+
: fn.call(context);
|
|
914
|
+
};
|
|
915
|
+
}
|
|
916
|
+
// In IE, native methods are not functions so they cannot be bound (note: they don't need to be).
|
|
917
|
+
return fn;
|
|
918
|
+
}
|
|
919
|
+
|
|
920
|
+
function toJsonReplacer(key, value) {
|
|
921
|
+
let val = value;
|
|
922
|
+
|
|
923
|
+
if (
|
|
924
|
+
typeof key === "string" &&
|
|
925
|
+
key.charAt(0) === "$" &&
|
|
926
|
+
key.charAt(1) === "$"
|
|
927
|
+
) {
|
|
928
|
+
val = undefined;
|
|
929
|
+
} else if (isWindow(value)) {
|
|
930
|
+
val = "$WINDOW";
|
|
931
|
+
} else if (value && window.document === value) {
|
|
932
|
+
val = "$DOCUMENT";
|
|
933
|
+
} else if (isScope(value)) {
|
|
934
|
+
val = "$SCOPE";
|
|
935
|
+
}
|
|
936
|
+
|
|
937
|
+
return val;
|
|
938
|
+
}
|
|
939
|
+
|
|
940
|
+
/**
|
|
941
|
+
* @module angular
|
|
942
|
+
* @function toJson
|
|
943
|
+
*
|
|
944
|
+
* @description
|
|
945
|
+
* Serializes input into a JSON-formatted string. Properties with leading $$ characters will be
|
|
946
|
+
* stripped since AngularJS uses this notation internally.
|
|
947
|
+
*
|
|
948
|
+
* @param {Object|Array|Date|string|number|boolean} obj Input to be serialized into JSON.
|
|
949
|
+
* @param {boolean|number} [pretty=2] If set to true, the JSON output will contain newlines and whitespace.
|
|
950
|
+
* If set to an integer, the JSON output will contain that many spaces per indentation.
|
|
951
|
+
* @returns {string|undefined} JSON-ified string representing `obj`.
|
|
952
|
+
* @knownIssue
|
|
953
|
+
*
|
|
954
|
+
* The Safari browser throws a `RangeError` instead of returning `null` when it tries to stringify a `Date`
|
|
955
|
+
* object with an invalid date value. The only reliable way to prevent this is to monkeypatch the
|
|
956
|
+
* `Date.prototype.toJSON` method as follows:
|
|
957
|
+
*
|
|
958
|
+
* ```
|
|
959
|
+
* let _DatetoJSON = Date.prototype.toJSON;
|
|
960
|
+
* Date.prototype.toJSON = function() {
|
|
961
|
+
* try {
|
|
962
|
+
* return _DatetoJSON.call(this);
|
|
963
|
+
* } catch(e) {
|
|
964
|
+
* if (e instanceof RangeError) {
|
|
965
|
+
* return null;
|
|
966
|
+
* }
|
|
967
|
+
* throw e;
|
|
968
|
+
* }
|
|
969
|
+
* };
|
|
970
|
+
* ```
|
|
971
|
+
*
|
|
972
|
+
* See https://github.com/angular/angular.js/pull/14221 for more information.
|
|
973
|
+
*/
|
|
974
|
+
export function toJson(obj, pretty) {
|
|
975
|
+
if (isUndefined(obj)) return undefined;
|
|
976
|
+
if (!isNumber(pretty)) {
|
|
977
|
+
pretty = pretty ? 2 : null;
|
|
978
|
+
}
|
|
979
|
+
return JSON.stringify(obj, toJsonReplacer, pretty);
|
|
980
|
+
}
|
|
981
|
+
|
|
982
|
+
/**
|
|
983
|
+
* @module angular
|
|
984
|
+
* @function fromJson
|
|
985
|
+
*
|
|
986
|
+
* @description
|
|
987
|
+
* Deserializes a JSON string.
|
|
988
|
+
*
|
|
989
|
+
* @param {string} json JSON string to deserialize.
|
|
990
|
+
* @returns {Object|Array|string|number} Deserialized JSON string.
|
|
991
|
+
*/
|
|
992
|
+
export function fromJson(json) {
|
|
993
|
+
return isString(json) ? JSON.parse(json) : json;
|
|
994
|
+
}
|
|
995
|
+
|
|
996
|
+
export function timezoneToOffset(timezone, fallback) {
|
|
997
|
+
const requestedTimezoneOffset =
|
|
998
|
+
Date.parse(`Jan 01, 1970 00:00:00 ${timezone}`) / 60000;
|
|
999
|
+
return isNumberNaN(requestedTimezoneOffset)
|
|
1000
|
+
? fallback
|
|
1001
|
+
: requestedTimezoneOffset;
|
|
1002
|
+
}
|
|
1003
|
+
|
|
1004
|
+
export function addDateMinutes(date, minutes) {
|
|
1005
|
+
const newDate = new Date(date.getTime());
|
|
1006
|
+
newDate.setMinutes(newDate.getMinutes() + minutes);
|
|
1007
|
+
return newDate;
|
|
1008
|
+
}
|
|
1009
|
+
|
|
1010
|
+
export function convertTimezoneToLocal(date, timezone, reverse) {
|
|
1011
|
+
const doReverse = reverse ? -1 : 1;
|
|
1012
|
+
const dateTimezoneOffset = date.getTimezoneOffset();
|
|
1013
|
+
const timezoneOffset = timezoneToOffset(timezone, dateTimezoneOffset);
|
|
1014
|
+
return addDateMinutes(
|
|
1015
|
+
date,
|
|
1016
|
+
doReverse * (timezoneOffset - dateTimezoneOffset),
|
|
1017
|
+
);
|
|
1018
|
+
}
|
|
1019
|
+
|
|
1020
|
+
/**
|
|
1021
|
+
* Parses an escaped url query string into key-value pairs.
|
|
1022
|
+
* @param {string} keyValue
|
|
1023
|
+
* @returns {Object.<string,boolean|Array>}
|
|
1024
|
+
*/
|
|
1025
|
+
export function parseKeyValue(keyValue) {
|
|
1026
|
+
const obj = {};
|
|
1027
|
+
(keyValue || "").split("&").forEach((keyValue) => {
|
|
1028
|
+
let splitPoint;
|
|
1029
|
+
let key;
|
|
1030
|
+
let val;
|
|
1031
|
+
if (keyValue) {
|
|
1032
|
+
key = keyValue = keyValue.replace(/\+/g, "%20");
|
|
1033
|
+
splitPoint = keyValue.indexOf("=");
|
|
1034
|
+
if (splitPoint !== -1) {
|
|
1035
|
+
key = keyValue.substring(0, splitPoint);
|
|
1036
|
+
val = keyValue.substring(splitPoint + 1);
|
|
1037
|
+
}
|
|
1038
|
+
key = tryDecodeURIComponent(key);
|
|
1039
|
+
if (isDefined(key)) {
|
|
1040
|
+
val = isDefined(val) ? tryDecodeURIComponent(val) : true;
|
|
1041
|
+
if (!Object.hasOwnProperty.call(obj, key)) {
|
|
1042
|
+
obj[key] = val;
|
|
1043
|
+
} else if (isArray(obj[key])) {
|
|
1044
|
+
obj[key].push(val);
|
|
1045
|
+
} else {
|
|
1046
|
+
obj[key] = [obj[key], val];
|
|
1047
|
+
}
|
|
1048
|
+
}
|
|
1049
|
+
}
|
|
1050
|
+
});
|
|
1051
|
+
return obj;
|
|
1052
|
+
}
|
|
1053
|
+
|
|
1054
|
+
export function toKeyValue(obj) {
|
|
1055
|
+
const parts = [];
|
|
1056
|
+
forEach(obj, (value, key) => {
|
|
1057
|
+
if (isArray(value)) {
|
|
1058
|
+
forEach(value, (arrayValue) => {
|
|
1059
|
+
parts.push(
|
|
1060
|
+
encodeUriQuery(key, true) +
|
|
1061
|
+
(arrayValue === true ? "" : `=${encodeUriQuery(arrayValue, true)}`),
|
|
1062
|
+
);
|
|
1063
|
+
});
|
|
1064
|
+
} else {
|
|
1065
|
+
parts.push(
|
|
1066
|
+
encodeUriQuery(key, true) +
|
|
1067
|
+
(value === true ? "" : `=${encodeUriQuery(value, true)}`),
|
|
1068
|
+
);
|
|
1069
|
+
}
|
|
1070
|
+
});
|
|
1071
|
+
return parts.length ? parts.join("&") : "";
|
|
1072
|
+
}
|
|
1073
|
+
|
|
1074
|
+
/**
|
|
1075
|
+
* Tries to decode the URI component without throwing an exception.
|
|
1076
|
+
*
|
|
1077
|
+
* @param {string} value potential URI component to check.
|
|
1078
|
+
* @returns {string}
|
|
1079
|
+
*/
|
|
1080
|
+
export function tryDecodeURIComponent(value) {
|
|
1081
|
+
try {
|
|
1082
|
+
return decodeURIComponent(value);
|
|
1083
|
+
} catch (e) {
|
|
1084
|
+
value;
|
|
1085
|
+
}
|
|
1086
|
+
}
|
|
1087
|
+
|
|
1088
|
+
/**
|
|
1089
|
+
* We need our custom method because encodeURIComponent is too aggressive and doesn't follow
|
|
1090
|
+
* http://www.ietf.org/rfc/rfc3986.txt with regards to the character set (pchar) allowed in path
|
|
1091
|
+
* segments:
|
|
1092
|
+
* segment = *pchar
|
|
1093
|
+
* pchar = unreserved / pct-encoded / sub-delims / ":" / "@"
|
|
1094
|
+
* pct-encoded = "%" HEXDIG HEXDIG
|
|
1095
|
+
* unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~"
|
|
1096
|
+
* sub-delims = "!" / "$" / "&" / "'" / "(" / ")"
|
|
1097
|
+
* / "*" / "+" / "," / ";" / "="
|
|
1098
|
+
*/
|
|
1099
|
+
export function encodeUriSegment(val) {
|
|
1100
|
+
return encodeUriQuery(val, true)
|
|
1101
|
+
.replace(/%26/gi, "&")
|
|
1102
|
+
.replace(/%3D/gi, "=")
|
|
1103
|
+
.replace(/%2B/gi, "+");
|
|
1104
|
+
}
|
|
1105
|
+
|
|
1106
|
+
/**
|
|
1107
|
+
* This method is intended for encoding *key* or *value* parts of query component. We need a custom
|
|
1108
|
+
* method because encodeURIComponent is too aggressive and encodes stuff that doesn't have to be
|
|
1109
|
+
* encoded per http://tools.ietf.org/html/rfc3986:
|
|
1110
|
+
* query = *( pchar / "/" / "?" )
|
|
1111
|
+
* pchar = unreserved / pct-encoded / sub-delims / ":" / "@"
|
|
1112
|
+
* unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~"
|
|
1113
|
+
* pct-encoded = "%" HEXDIG HEXDIG
|
|
1114
|
+
* sub-delims = "!" / "$" / "&" / "'" / "(" / ")"
|
|
1115
|
+
* / "*" / "+" / "," / ";" / "="
|
|
1116
|
+
*/
|
|
1117
|
+
export function encodeUriQuery(val, pctEncodeSpaces) {
|
|
1118
|
+
return encodeURIComponent(val)
|
|
1119
|
+
.replace(/%40/gi, "@")
|
|
1120
|
+
.replace(/%3A/gi, ":")
|
|
1121
|
+
.replace(/%24/g, "$")
|
|
1122
|
+
.replace(/%2C/gi, ",")
|
|
1123
|
+
.replace(/%3B/gi, ";")
|
|
1124
|
+
.replace(/%20/g, pctEncodeSpaces ? "%20" : "+");
|
|
1125
|
+
}
|
|
1126
|
+
|
|
1127
|
+
export const ngAttrPrefixes = ["ng-", "data-ng-", "ng:", "x-ng-"];
|
|
1128
|
+
|
|
1129
|
+
export function getNgAttribute(element, ngAttr) {
|
|
1130
|
+
let attr;
|
|
1131
|
+
let i;
|
|
1132
|
+
const ii = ngAttrPrefixes.length;
|
|
1133
|
+
for (i = 0; i < ii; ++i) {
|
|
1134
|
+
attr = ngAttrPrefixes[i] + ngAttr;
|
|
1135
|
+
if (isString((attr = element.getAttribute(attr)))) {
|
|
1136
|
+
return attr;
|
|
1137
|
+
}
|
|
1138
|
+
}
|
|
1139
|
+
return null;
|
|
1140
|
+
}
|
|
1141
|
+
|
|
1142
|
+
/**
|
|
1143
|
+
* Creates a shallow copy of an object, an array or a primitive.
|
|
1144
|
+
*
|
|
1145
|
+
* Assumes that there are no proto properties for objects.
|
|
1146
|
+
*/
|
|
1147
|
+
export function shallowCopy(src, dst) {
|
|
1148
|
+
if (isArray(src)) {
|
|
1149
|
+
dst = dst || [];
|
|
1150
|
+
|
|
1151
|
+
for (let i = 0, ii = src.length; i < ii; i++) {
|
|
1152
|
+
dst[i] = src[i];
|
|
1153
|
+
}
|
|
1154
|
+
} else if (isObject(src)) {
|
|
1155
|
+
dst = dst || {};
|
|
1156
|
+
|
|
1157
|
+
for (const key in src) {
|
|
1158
|
+
if (!(key.startsWith("$") && key.charAt(1) === "$")) {
|
|
1159
|
+
dst[key] = src[key];
|
|
1160
|
+
}
|
|
1161
|
+
}
|
|
1162
|
+
}
|
|
1163
|
+
|
|
1164
|
+
return dst || src;
|
|
1165
|
+
}
|
|
1166
|
+
|
|
1167
|
+
/**
|
|
1168
|
+
* throw error if the argument is falsy.
|
|
1169
|
+
*/
|
|
1170
|
+
export function assertArg(arg, name, reason) {
|
|
1171
|
+
if (!arg) {
|
|
1172
|
+
throw ngMinErr(
|
|
1173
|
+
"areq",
|
|
1174
|
+
"Argument '{0}' is {1}",
|
|
1175
|
+
name || "?",
|
|
1176
|
+
reason || "required",
|
|
1177
|
+
);
|
|
1178
|
+
}
|
|
1179
|
+
return arg;
|
|
1180
|
+
}
|
|
1181
|
+
|
|
1182
|
+
export function assertArgFn(arg, name, acceptArrayAnnotation) {
|
|
1183
|
+
if (acceptArrayAnnotation && isArray(arg)) {
|
|
1184
|
+
arg = arg[arg.length - 1];
|
|
1185
|
+
}
|
|
1186
|
+
|
|
1187
|
+
assertArg(
|
|
1188
|
+
isFunction(arg),
|
|
1189
|
+
name,
|
|
1190
|
+
`not a function, got ${
|
|
1191
|
+
arg && typeof arg === "object"
|
|
1192
|
+
? arg.constructor.name || "Object"
|
|
1193
|
+
: typeof arg
|
|
1194
|
+
}`,
|
|
1195
|
+
);
|
|
1196
|
+
return arg;
|
|
1197
|
+
}
|
|
1198
|
+
|
|
1199
|
+
/**
|
|
1200
|
+
* @description
|
|
1201
|
+
*
|
|
1202
|
+
* This object provides a utility for producing rich Error messages within
|
|
1203
|
+
* AngularJS. It can be called as follows:
|
|
1204
|
+
*
|
|
1205
|
+
* let exampleMinErr = minErr('example');
|
|
1206
|
+
* throw exampleMinErr('one', 'This {0} is {1}', foo, bar);
|
|
1207
|
+
*
|
|
1208
|
+
* The above creates an instance of minErr in the example namespace. The
|
|
1209
|
+
* resulting error will have a namespaced error code of example.one. The
|
|
1210
|
+
* resulting error will replace {0} with the value of foo, and {1} with the
|
|
1211
|
+
* value of bar. The object is not restricted in the number of arguments it can
|
|
1212
|
+
* take.
|
|
1213
|
+
*
|
|
1214
|
+
* If fewer arguments are specified than necessary for interpolation, the extra
|
|
1215
|
+
* interpolation markers will be preserved in the final string.
|
|
1216
|
+
*
|
|
1217
|
+
* Since data will be parsed statically during a build step, some restrictions
|
|
1218
|
+
* are applied with respect to how minErr instances are created and called.
|
|
1219
|
+
* Instances should have names of the form namespaceMinErr for a minErr created
|
|
1220
|
+
* using minErr('namespace'). Error codes, namespaces and template strings
|
|
1221
|
+
* should all be static strings, not variables or general expressions.
|
|
1222
|
+
*
|
|
1223
|
+
* @param {string} module The namespace to use for the new minErr instance.
|
|
1224
|
+
* @returns {function(string, string, ...*): Error} minErr instance
|
|
1225
|
+
*/
|
|
1226
|
+
|
|
1227
|
+
export const minErrConfig = {};
|
|
1228
|
+
|
|
1229
|
+
export function minErr(module) {
|
|
1230
|
+
const url = 'https://errors.angularjs.org/"NG_VERSION_FULL"/';
|
|
1231
|
+
const regex = `${url.replace(".", "\\.")}[\\s\\S]*`;
|
|
1232
|
+
const errRegExp = new RegExp(regex, "g");
|
|
1233
|
+
|
|
1234
|
+
return function () {
|
|
1235
|
+
const code = arguments[0];
|
|
1236
|
+
const template = arguments[1];
|
|
1237
|
+
let message = `[${module ? `${module}:` : ""}${code}] `;
|
|
1238
|
+
const templateArgs = sliceArgs(arguments, 2).map((arg) =>
|
|
1239
|
+
toDebugString(arg),
|
|
1240
|
+
);
|
|
1241
|
+
let paramPrefix;
|
|
1242
|
+
let i;
|
|
1243
|
+
|
|
1244
|
+
// A minErr message has two parts: the message itself and the url that contains the
|
|
1245
|
+
// encoded message.
|
|
1246
|
+
// The message's parameters can contain other error messages which also include error urls.
|
|
1247
|
+
// To prevent the messages from getting too long, we strip the error urls from the parameters.
|
|
1248
|
+
|
|
1249
|
+
message += template.replace(/\{\d+\}/g, (match) => {
|
|
1250
|
+
const index = +match.slice(1, -1);
|
|
1251
|
+
|
|
1252
|
+
if (index < templateArgs.length) {
|
|
1253
|
+
return templateArgs[index].replace(errRegExp, "");
|
|
1254
|
+
}
|
|
1255
|
+
|
|
1256
|
+
return match;
|
|
1257
|
+
});
|
|
1258
|
+
|
|
1259
|
+
message += `\n${url}${module ? `${module}/` : ""}${code}`;
|
|
1260
|
+
|
|
1261
|
+
if (minErrConfig.urlErrorParamsEnabled) {
|
|
1262
|
+
for (
|
|
1263
|
+
i = 0, paramPrefix = "?";
|
|
1264
|
+
i < templateArgs.length;
|
|
1265
|
+
i++, paramPrefix = "&"
|
|
1266
|
+
) {
|
|
1267
|
+
message += `${paramPrefix}p${i}=${encodeURIComponent(templateArgs[i])}`;
|
|
1268
|
+
}
|
|
1269
|
+
}
|
|
1270
|
+
|
|
1271
|
+
return new Error(message);
|
|
1272
|
+
};
|
|
1273
|
+
}
|
|
1274
|
+
|
|
1275
|
+
export function toDebugString(obj) {
|
|
1276
|
+
if (typeof obj === "function") {
|
|
1277
|
+
return obj.toString().replace(/ \{[\s\S]*$/, "");
|
|
1278
|
+
}
|
|
1279
|
+
if (isUndefined(obj)) {
|
|
1280
|
+
return "undefined";
|
|
1281
|
+
}
|
|
1282
|
+
if (typeof obj !== "string") {
|
|
1283
|
+
const seen = [];
|
|
1284
|
+
let copyObj = structuredClone(obj);
|
|
1285
|
+
return JSON.stringify(copyObj, (key, val) => {
|
|
1286
|
+
const replace = toJsonReplacer(key, val);
|
|
1287
|
+
if (isObject(replace)) {
|
|
1288
|
+
if (seen.indexOf(replace) >= 0) return "...";
|
|
1289
|
+
|
|
1290
|
+
seen.push(replace);
|
|
1291
|
+
}
|
|
1292
|
+
return replace;
|
|
1293
|
+
});
|
|
1294
|
+
}
|
|
1295
|
+
return obj;
|
|
1296
|
+
}
|
|
1297
|
+
|
|
1298
|
+
/**
|
|
1299
|
+
* Computes a hash of an 'obj'.
|
|
1300
|
+
* Hash of a:
|
|
1301
|
+
* string is string
|
|
1302
|
+
* number is number as string
|
|
1303
|
+
* object is either result of calling $$hashKey function on the object or uniquely generated id,
|
|
1304
|
+
* that is also assigned to the $$hashKey property of the object.
|
|
1305
|
+
*
|
|
1306
|
+
* @param {*} obj
|
|
1307
|
+
* @returns {string} hash string such that the same input will have the same hash string.
|
|
1308
|
+
* The resulting string key is in 'type:hashKey' format.
|
|
1309
|
+
*/
|
|
1310
|
+
export function hashKey(obj) {
|
|
1311
|
+
const key = obj && obj.$$hashKey;
|
|
1312
|
+
|
|
1313
|
+
if (key) {
|
|
1314
|
+
if (typeof key === "function") {
|
|
1315
|
+
return obj.$$hashKey();
|
|
1316
|
+
}
|
|
1317
|
+
return key;
|
|
1318
|
+
}
|
|
1319
|
+
|
|
1320
|
+
const objType = typeof obj;
|
|
1321
|
+
if (objType === "function" || (objType === "object" && obj !== null)) {
|
|
1322
|
+
obj.$$hashKey = `${objType}:${nextUid()}`;
|
|
1323
|
+
return obj.$$hashKey;
|
|
1324
|
+
}
|
|
1325
|
+
|
|
1326
|
+
return `${objType}:${obj}`;
|
|
1327
|
+
}
|
|
1328
|
+
|
|
1329
|
+
export function mergeClasses(a, b) {
|
|
1330
|
+
if (!a && !b) return "";
|
|
1331
|
+
if (!a) return b;
|
|
1332
|
+
if (!b) return a;
|
|
1333
|
+
if (isArray(a)) a = a.join(" ");
|
|
1334
|
+
if (isArray(b)) b = b.join(" ");
|
|
1335
|
+
return a + " " + b;
|
|
1336
|
+
}
|
|
1337
|
+
|
|
1338
|
+
/**
|
|
1339
|
+
* Converts all accepted directives format into proper directive name.
|
|
1340
|
+
* @param name Name to normalize
|
|
1341
|
+
*/
|
|
1342
|
+
|
|
1343
|
+
export function directiveNormalize(name) {
|
|
1344
|
+
return name
|
|
1345
|
+
.replace(PREFIX_REGEXP, "")
|
|
1346
|
+
.replace(SPECIAL_CHARS_REGEXP, (_, letter, offset) =>
|
|
1347
|
+
offset ? letter.toUpperCase() : letter,
|
|
1348
|
+
);
|
|
1349
|
+
}
|