@microsoft/applicationinsights-core-js 2.7.4-nightly.2201-03 → 2.7.4-nightly.2202-05
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/browser/applicationinsights-core-js.integrity.json +9 -9
- package/browser/applicationinsights-core-js.js +160 -122
- package/browser/applicationinsights-core-js.js.map +1 -1
- package/browser/applicationinsights-core-js.min.js +2 -2
- package/browser/applicationinsights-core-js.min.js.map +1 -1
- package/dist/applicationinsights-core-js.api.json +37 -111
- package/dist/applicationinsights-core-js.api.md +3 -3
- package/dist/applicationinsights-core-js.d.ts +4 -4
- package/dist/applicationinsights-core-js.js +160 -122
- package/dist/applicationinsights-core-js.js.map +1 -1
- package/dist/applicationinsights-core-js.min.js +2 -2
- package/dist/applicationinsights-core-js.min.js.map +1 -1
- package/dist/applicationinsights-core-js.rollup.d.ts +4 -4
- package/dist-esm/JavaScriptSDK/AppInsightsCore.js +1 -1
- package/dist-esm/JavaScriptSDK/BaseCore.js +1 -1
- package/dist-esm/JavaScriptSDK/BaseTelemetryPlugin.js +1 -1
- package/dist-esm/JavaScriptSDK/ChannelController.js +1 -1
- package/dist-esm/JavaScriptSDK/Constants.js +1 -1
- package/dist-esm/JavaScriptSDK/CookieMgr.js +1 -1
- package/dist-esm/JavaScriptSDK/CoreUtils.js +1 -1
- package/dist-esm/JavaScriptSDK/DbgExtensionUtils.js +1 -1
- package/dist-esm/JavaScriptSDK/DiagnosticLogger.js +1 -1
- package/dist-esm/JavaScriptSDK/EnvUtils.js +1 -1
- package/dist-esm/JavaScriptSDK/HelperFuncs.js +296 -111
- package/dist-esm/JavaScriptSDK/HelperFuncs.js.map +1 -1
- package/dist-esm/JavaScriptSDK/InstrumentHooks.js +2 -35
- package/dist-esm/JavaScriptSDK/InstrumentHooks.js.map +1 -1
- package/dist-esm/JavaScriptSDK/NotificationManager.js +1 -1
- package/dist-esm/JavaScriptSDK/PerfManager.js +1 -1
- package/dist-esm/JavaScriptSDK/ProcessTelemetryContext.js +1 -1
- package/dist-esm/JavaScriptSDK/RandomHelper.js +1 -1
- package/dist-esm/JavaScriptSDK/TelemetryHelpers.js +1 -1
- package/dist-esm/JavaScriptSDK/TelemetryPluginChain.js +1 -1
- package/dist-esm/JavaScriptSDK.Enums/EventsDiscardedReason.js +1 -1
- package/dist-esm/JavaScriptSDK.Enums/LoggingEnums.js +1 -1
- package/dist-esm/JavaScriptSDK.Enums/SendRequestReason.js +1 -1
- package/dist-esm/JavaScriptSDK.Interfaces/IAppInsightsCore.js +1 -1
- package/dist-esm/JavaScriptSDK.Interfaces/IChannelControls.js +1 -1
- package/dist-esm/JavaScriptSDK.Interfaces/IConfiguration.js +1 -1
- package/dist-esm/JavaScriptSDK.Interfaces/ICookieMgr.js +1 -1
- package/dist-esm/JavaScriptSDK.Interfaces/IDbgExtension.js +1 -1
- package/dist-esm/JavaScriptSDK.Interfaces/IDiagnosticLogger.js +1 -1
- package/dist-esm/JavaScriptSDK.Interfaces/IInstrumentHooks.js +1 -1
- package/dist-esm/JavaScriptSDK.Interfaces/INotificationListener.js +1 -1
- package/dist-esm/JavaScriptSDK.Interfaces/INotificationManager.js +1 -1
- package/dist-esm/JavaScriptSDK.Interfaces/IPerfEvent.js +1 -1
- package/dist-esm/JavaScriptSDK.Interfaces/IPerfManager.js +1 -1
- package/dist-esm/JavaScriptSDK.Interfaces/IProcessTelemetryContext.js +1 -1
- package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryItem.js +1 -1
- package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryPlugin.js +1 -1
- package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryPluginChain.js +1 -1
- package/dist-esm/applicationinsights-core-js.js +1 -1
- package/package.json +1 -1
- package/src/JavaScriptSDK/HelperFuncs.ts +332 -110
- package/src/JavaScriptSDK/InstrumentHooks.ts +1 -41
- package/types/JavaScriptSDK/HelperFuncs.d.ts +42 -3
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// Licensed under the MIT License.
|
|
3
3
|
import {
|
|
4
4
|
strShimUndefined, strShimObject, strShimFunction, throwTypeError,
|
|
5
|
-
ObjClass, ObjProto, ObjAssign, ObjHasOwnProperty, ObjDefineProperty
|
|
5
|
+
ObjClass, ObjProto, ObjAssign, ObjHasOwnProperty, ObjDefineProperty, strShimPrototype
|
|
6
6
|
} from "@microsoft/applicationinsights-shims";
|
|
7
7
|
|
|
8
8
|
// RESTRICT and AVOID circular dependencies you should not import other contained modules or export the contents of this file directly
|
|
@@ -14,13 +14,79 @@ const strAddEventHelper = "addEventListener";
|
|
|
14
14
|
const strDetachEvent = "detachEvent";
|
|
15
15
|
const strRemoveEventListener = "removeEventListener";
|
|
16
16
|
const strToISOString = "toISOString";
|
|
17
|
+
const cStrEndsWith = "endsWith";
|
|
18
|
+
const cStrStartsWith = "startsWith";
|
|
19
|
+
const strIndexOf = "indexOf";
|
|
20
|
+
const strMap = "map";
|
|
21
|
+
const strReduce = "reduce";
|
|
22
|
+
const cStrTrim = "trim";
|
|
23
|
+
const strKeys = "keys";
|
|
24
|
+
const strToString = "toString";
|
|
17
25
|
|
|
26
|
+
/**
|
|
27
|
+
* Constant string defined to support minimization
|
|
28
|
+
* @ignore
|
|
29
|
+
*/
|
|
30
|
+
const str__Proto = "__proto__";
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Constant string defined to support minimization
|
|
34
|
+
* @ignore
|
|
35
|
+
*/
|
|
36
|
+
const strConstructor = "constructor";
|
|
37
|
+
|
|
18
38
|
const _objDefineProperty = ObjDefineProperty;
|
|
19
39
|
const _objFreeze = ObjClass["freeze"];
|
|
20
40
|
const _objSeal = ObjClass["seal"];
|
|
21
41
|
|
|
42
|
+
const StringProto = String[strShimPrototype];
|
|
43
|
+
const _strTrim = StringProto[cStrTrim];
|
|
44
|
+
const _strEndsWith = StringProto[cStrEndsWith];
|
|
45
|
+
const _strStartsWith = StringProto[cStrStartsWith];
|
|
46
|
+
|
|
47
|
+
const DateProto = Date[strShimPrototype];
|
|
48
|
+
const _dataToISOString = DateProto[strToISOString];
|
|
49
|
+
const _isArray = Array.isArray;
|
|
50
|
+
const _objToString = ObjProto[strToString];
|
|
51
|
+
|
|
52
|
+
const _fnToString = ObjHasOwnProperty[strToString];
|
|
53
|
+
// Cache what this browser reports as the object function constructor (as a string)
|
|
54
|
+
const _objFunctionString = _fnToString.call(ObjClass);
|
|
55
|
+
|
|
56
|
+
const rCamelCase = /-([a-z])/g;
|
|
57
|
+
const rNormalizeInvalid = /([^\w\d_$])/g;
|
|
58
|
+
const rLeadingNumeric = /^(\d+[\w\d_$])/;
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Pre-lookup to check if we are running on a modern browser (i.e. not IE8)
|
|
63
|
+
* @ignore
|
|
64
|
+
*/
|
|
65
|
+
let _objGetPrototypeOf = Object["getPrototypeOf"];
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Helper used to get the prototype of the target object as getPrototypeOf is not available in an ES3 environment.
|
|
69
|
+
* @ignore
|
|
70
|
+
*/
|
|
71
|
+
export function _getObjProto(target:any) {
|
|
72
|
+
if (target) {
|
|
73
|
+
// This method doesn't existing in older browsers (e.g. IE8)
|
|
74
|
+
if (_objGetPrototypeOf) {
|
|
75
|
+
return _objGetPrototypeOf(target);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// target[Constructor] May break if the constructor has been changed or removed
|
|
79
|
+
let newProto = target[str__Proto] || target[strShimPrototype] || target[strConstructor];
|
|
80
|
+
if(newProto) {
|
|
81
|
+
return newProto;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
return null;
|
|
86
|
+
}
|
|
87
|
+
|
|
22
88
|
export function objToString(obj: any) {
|
|
23
|
-
return
|
|
89
|
+
return _objToString.call(obj);
|
|
24
90
|
}
|
|
25
91
|
|
|
26
92
|
export function isTypeof(value: any, theType: string): boolean {
|
|
@@ -44,17 +110,17 @@ export function isNotNullOrUndefined(value: any): boolean {
|
|
|
44
110
|
}
|
|
45
111
|
|
|
46
112
|
export function hasOwnProperty(obj: any, prop: string): boolean {
|
|
47
|
-
return obj && ObjHasOwnProperty.call(obj, prop);
|
|
113
|
+
return !!(obj && ObjHasOwnProperty.call(obj, prop));
|
|
48
114
|
}
|
|
49
115
|
|
|
50
116
|
export function isObject(value: any): boolean {
|
|
51
117
|
// Changing to inline for performance
|
|
52
|
-
return typeof value === strShimObject;
|
|
118
|
+
return !!(value && typeof value === strShimObject);
|
|
53
119
|
}
|
|
54
120
|
|
|
55
121
|
export function isFunction(value: any): value is Function {
|
|
56
122
|
// Changing to inline for performance
|
|
57
|
-
return typeof value === strShimFunction;
|
|
123
|
+
return !!(value && typeof value === strShimFunction);
|
|
58
124
|
}
|
|
59
125
|
|
|
60
126
|
/**
|
|
@@ -116,9 +182,17 @@ export function detachEvent(obj: any, eventNameWithoutOn: string, handlerRef: an
|
|
|
116
182
|
*/
|
|
117
183
|
export function normalizeJsName(name: string): string {
|
|
118
184
|
let value = name;
|
|
119
|
-
|
|
120
|
-
if (
|
|
121
|
-
|
|
185
|
+
|
|
186
|
+
if (value && isString(value)) {
|
|
187
|
+
// CamelCase everything after the "-" and remove the dash
|
|
188
|
+
value = value.replace(rCamelCase, function (_all, letter) {
|
|
189
|
+
return letter.toUpperCase();
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
value = value.replace(rNormalizeInvalid, "_");
|
|
193
|
+
value = value.replace(rLeadingNumeric, function(_all, match) {
|
|
194
|
+
return "_" + match;
|
|
195
|
+
});
|
|
122
196
|
}
|
|
123
197
|
|
|
124
198
|
return value;
|
|
@@ -147,25 +221,38 @@ export function objForEachKey(target: any, callbackfn: (name: string, value: any
|
|
|
147
221
|
* @returns true if the given search value is found at the end of the string, otherwise false.
|
|
148
222
|
*/
|
|
149
223
|
export function strEndsWith(value: string, search: string) {
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
} else if (valLen >= searchLen) {
|
|
156
|
-
let pos = valLen - 1;
|
|
157
|
-
for (let lp = searchLen - 1; lp >= 0; lp--) {
|
|
158
|
-
if (value[pos] != search[lp]) {
|
|
159
|
-
return false;
|
|
160
|
-
}
|
|
161
|
-
pos--;
|
|
162
|
-
}
|
|
224
|
+
let result = false;
|
|
225
|
+
if (value && search && !(result = value === search)) {
|
|
226
|
+
// For Performance try and use the native instance, using string lookup of the function to easily pass the ES3 build checks and minification
|
|
227
|
+
result = _strEndsWith ? value[cStrEndsWith](search) : _strEndsWithPoly(value, search);
|
|
228
|
+
}
|
|
163
229
|
|
|
164
|
-
|
|
230
|
+
return result;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
/**
|
|
234
|
+
* The _strEndsWith() method determines whether a string ends with the characters of a specified string, returning true or false as appropriate.
|
|
235
|
+
* @param value - The value to check whether it ends with the search value.
|
|
236
|
+
* @param search - The characters to be searched for at the end of the value.
|
|
237
|
+
* @returns true if the given search value is found at the end of the string, otherwise false.
|
|
238
|
+
*/
|
|
239
|
+
export function _strEndsWithPoly(value: string, search: string) {
|
|
240
|
+
let result = false;
|
|
241
|
+
let searchLen = search ? search.length : 0;
|
|
242
|
+
let valLen = value ? value.length : 0;
|
|
243
|
+
if (searchLen && valLen && valLen >= searchLen && !(result = value === search)) {
|
|
244
|
+
let pos = valLen - 1;
|
|
245
|
+
for (let lp = searchLen - 1; lp >= 0; lp--) {
|
|
246
|
+
if (value[pos] != search[lp]) {
|
|
247
|
+
return false;
|
|
248
|
+
}
|
|
249
|
+
pos--;
|
|
165
250
|
}
|
|
251
|
+
|
|
252
|
+
result = true;
|
|
166
253
|
}
|
|
167
254
|
|
|
168
|
-
return
|
|
255
|
+
return result;
|
|
169
256
|
}
|
|
170
257
|
|
|
171
258
|
/**
|
|
@@ -175,20 +262,33 @@ export function strEndsWith(value: string, search: string) {
|
|
|
175
262
|
* @returns true if the given search value is found at the start of the string, otherwise false.
|
|
176
263
|
*/
|
|
177
264
|
export function strStartsWith(value: string, checkValue: string) {
|
|
265
|
+
let result = false;
|
|
266
|
+
if (value && checkValue && !(result = value === checkValue)) {
|
|
267
|
+
// For Performance try and use the native instance, using string lookup of the function to easily pass the ES3 build checks and minification
|
|
268
|
+
result = _strStartsWith ? value[cStrStartsWith](checkValue) : _strStartsWithPoly(value, checkValue);
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
return result;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
/**
|
|
275
|
+
* The strStartsWith() method determines whether a string starts with the characters of the specified string, returning true or false as appropriate.
|
|
276
|
+
* @param value - The value to check whether it ends with the search value.
|
|
277
|
+
* @param checkValue - The characters to be searched for at the start of the value.
|
|
278
|
+
* @returns true if the given search value is found at the start of the string, otherwise false.
|
|
279
|
+
*/
|
|
280
|
+
export function _strStartsWithPoly(value: string, checkValue: string) {
|
|
178
281
|
// Using helper for performance and because string startsWith() is not available on IE
|
|
179
282
|
let result = false;
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
for (let lp = 0; lp < chkLen; lp++) {
|
|
186
|
-
if (value[lp] !== checkValue[lp]) {
|
|
187
|
-
return false;
|
|
188
|
-
}
|
|
283
|
+
let chkLen = checkValue ? checkValue.length : 0;
|
|
284
|
+
if (value && chkLen && value.length >= chkLen && !(result = value === checkValue)) {
|
|
285
|
+
for (let lp = 0; lp < chkLen; lp++) {
|
|
286
|
+
if (value[lp] !== checkValue[lp]) {
|
|
287
|
+
return false;
|
|
189
288
|
}
|
|
190
|
-
result = true;
|
|
191
289
|
}
|
|
290
|
+
|
|
291
|
+
result = true;
|
|
192
292
|
}
|
|
193
293
|
|
|
194
294
|
return result;
|
|
@@ -211,21 +311,22 @@ export function strContains(value: string, search: string) {
|
|
|
211
311
|
* Check if an object is of type Date
|
|
212
312
|
*/
|
|
213
313
|
export function isDate(obj: any): obj is Date {
|
|
214
|
-
return
|
|
314
|
+
return !!(obj && _objToString.call(obj) === "[object Date]");
|
|
215
315
|
}
|
|
216
316
|
|
|
217
317
|
/**
|
|
218
318
|
* Check if an object is of type Array
|
|
219
319
|
*/
|
|
220
|
-
export
|
|
221
|
-
|
|
320
|
+
export let isArray: <T = any>(obj: any) => obj is Array<T> = _isArray || _isArrayPoly;
|
|
321
|
+
function _isArrayPoly<T = any>(obj: any): obj is Array<T> {
|
|
322
|
+
return !!(obj && _objToString.call(obj) === "[object Array]");
|
|
222
323
|
}
|
|
223
324
|
|
|
224
325
|
/**
|
|
225
326
|
* Check if an object is of type Error
|
|
226
327
|
*/
|
|
227
328
|
export function isError(obj: any): obj is Error {
|
|
228
|
-
return
|
|
329
|
+
return !!(obj && _objToString.call(obj) === "[object Error]");
|
|
229
330
|
}
|
|
230
331
|
|
|
231
332
|
/**
|
|
@@ -268,35 +369,64 @@ export function isSymbol(value: any): boolean {
|
|
|
268
369
|
return typeof value === "symbol";
|
|
269
370
|
}
|
|
270
371
|
|
|
372
|
+
/**
|
|
373
|
+
* Checks if the type of the value is a normal plain object (not a null or data)
|
|
374
|
+
* @param value
|
|
375
|
+
*/
|
|
376
|
+
export function isPlainObject(value: any): boolean {
|
|
377
|
+
let result: boolean = false;
|
|
378
|
+
|
|
379
|
+
if (value && typeof value === "object") {
|
|
380
|
+
// Inlining _objGetPrototypeOf for performance to avoid an additional function call
|
|
381
|
+
let proto = _objGetPrototypeOf ? _objGetPrototypeOf(value) : _getObjProto(value);
|
|
382
|
+
if (!proto) {
|
|
383
|
+
// No prototype found so this is a plain Object eg. 'Object.create(null)'
|
|
384
|
+
result = true;
|
|
385
|
+
} else {
|
|
386
|
+
// Objects that have a prototype are plain only if they were created using the Object global (native) function
|
|
387
|
+
if (proto[strConstructor] && ObjHasOwnProperty.call(proto, strConstructor)) {
|
|
388
|
+
proto = proto[strConstructor];
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
result = typeof proto === strShimFunction && _fnToString.call(proto) === _objFunctionString;
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
return result;
|
|
396
|
+
}
|
|
397
|
+
|
|
271
398
|
/**
|
|
272
399
|
* Convert a date to I.S.O. format in IE8
|
|
273
400
|
*/
|
|
274
401
|
export function toISOString(date: Date) {
|
|
275
402
|
if (date) {
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
if (isDate(date)) {
|
|
282
|
-
const pad = (num: number) => {
|
|
283
|
-
let r = String(num);
|
|
284
|
-
if (r.length === 1) {
|
|
285
|
-
r = "0" + r;
|
|
286
|
-
}
|
|
403
|
+
// For Performance try and use the native instance, using string lookup of the function to easily pass the ES3 build checks and minification
|
|
404
|
+
return _dataToISOString ? date[strToISOString]() : _toISOStringPoly(date);
|
|
405
|
+
}
|
|
406
|
+
}
|
|
287
407
|
|
|
288
|
-
|
|
408
|
+
/**
|
|
409
|
+
* Convert a date to I.S.O. format in IE8
|
|
410
|
+
*/
|
|
411
|
+
export function _toISOStringPoly(date: Date) {
|
|
412
|
+
if (date && date.getUTCFullYear) {
|
|
413
|
+
const pad = (num: number) => {
|
|
414
|
+
let r = String(num);
|
|
415
|
+
if (r.length === 1) {
|
|
416
|
+
r = "0" + r;
|
|
289
417
|
}
|
|
290
418
|
|
|
291
|
-
return
|
|
292
|
-
+ "-" + pad(date.getUTCMonth() + 1)
|
|
293
|
-
+ "-" + pad(date.getUTCDate())
|
|
294
|
-
+ "T" + pad(date.getUTCHours())
|
|
295
|
-
+ ":" + pad(date.getUTCMinutes())
|
|
296
|
-
+ ":" + pad(date.getUTCSeconds())
|
|
297
|
-
+ "." + String((date.getUTCMilliseconds() / 1000).toFixed(3)).slice(2, 5)
|
|
298
|
-
+ "Z";
|
|
419
|
+
return r;
|
|
299
420
|
}
|
|
421
|
+
|
|
422
|
+
return date.getUTCFullYear()
|
|
423
|
+
+ "-" + pad(date.getUTCMonth() + 1)
|
|
424
|
+
+ "-" + pad(date.getUTCDate())
|
|
425
|
+
+ "T" + pad(date.getUTCHours())
|
|
426
|
+
+ ":" + pad(date.getUTCMinutes())
|
|
427
|
+
+ ":" + pad(date.getUTCSeconds())
|
|
428
|
+
+ "." + String((date.getUTCMilliseconds() / 1000).toFixed(3)).slice(2, 5)
|
|
429
|
+
+ "Z";
|
|
300
430
|
}
|
|
301
431
|
}
|
|
302
432
|
|
|
@@ -332,16 +462,23 @@ export function arrForEach<T>(arr: T[], callbackfn: (value: T, index?: number, a
|
|
|
332
462
|
* @param fromIndex The array index at which to begin the search. If fromIndex is omitted, the search starts at index 0.
|
|
333
463
|
*/
|
|
334
464
|
export function arrIndexOf<T>(arr: T[], searchElement: T, fromIndex?: number): number {
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
465
|
+
if (arr) {
|
|
466
|
+
// For Performance try and use the native instance, using string lookup of the function to easily pass the ES3 build checks and minification
|
|
467
|
+
if (arr[strIndexOf]) {
|
|
468
|
+
return arr[strIndexOf](searchElement, fromIndex);
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
let len = arr.length;
|
|
472
|
+
let from = fromIndex || 0;
|
|
473
|
+
try {
|
|
474
|
+
for (let lp = Math.max(from >= 0 ? from : len - Math.abs(from), 0); lp < len; lp++) {
|
|
475
|
+
if (lp in arr && arr[lp] === searchElement) {
|
|
476
|
+
return lp;
|
|
477
|
+
}
|
|
341
478
|
}
|
|
479
|
+
} catch (e) {
|
|
480
|
+
// This can happen with some native browser objects, but should not happen for the type we are checking for
|
|
342
481
|
}
|
|
343
|
-
} catch (e) {
|
|
344
|
-
// This can happen with some native browser objects, but should not happen for the type we are checking for
|
|
345
482
|
}
|
|
346
483
|
|
|
347
484
|
return -1;
|
|
@@ -356,18 +493,28 @@ export function arrIndexOf<T>(arr: T[], searchElement: T, fromIndex?: number): n
|
|
|
356
493
|
* @param thisArg An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value.
|
|
357
494
|
*/
|
|
358
495
|
export function arrMap<T, R>(arr: T[], callbackfn: (value: T, index?: number, array?: T[]) => R, thisArg?: any): R[] {
|
|
359
|
-
let
|
|
360
|
-
let _this = thisArg || arr;
|
|
361
|
-
let results = new Array(len);
|
|
496
|
+
let results: R[];
|
|
362
497
|
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
498
|
+
if (arr) {
|
|
499
|
+
// For Performance try and use the native instance, using string lookup of the function to easily pass the ES3 build checks and minification
|
|
500
|
+
if (arr[strMap]) {
|
|
501
|
+
return arr[strMap](callbackfn, thisArg);
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
let len = arr.length;
|
|
505
|
+
let _this = thisArg || arr;
|
|
506
|
+
results = new Array(len);
|
|
507
|
+
|
|
508
|
+
try {
|
|
509
|
+
for (let lp = 0; lp < len; lp++) {
|
|
510
|
+
if (lp in arr) {
|
|
511
|
+
results[lp] = callbackfn.call(_this, arr[lp], arr);
|
|
512
|
+
}
|
|
367
513
|
}
|
|
514
|
+
} catch (e) {
|
|
515
|
+
// This can happen with some native browser objects, but should not happen for the type we are checking for
|
|
368
516
|
}
|
|
369
|
-
|
|
370
|
-
// This can happen with some native browser objects, but should not happen for the type we are checking for
|
|
517
|
+
|
|
371
518
|
}
|
|
372
519
|
|
|
373
520
|
return results;
|
|
@@ -382,26 +529,34 @@ export function arrMap<T, R>(arr: T[], callbackfn: (value: T, index?: number, ar
|
|
|
382
529
|
* @param initialValue If initialValue is specified, it is used as the initial value to start the accumulation. The first call to the callbackfn function provides this value as an argument instead of an array value.
|
|
383
530
|
*/
|
|
384
531
|
export function arrReduce<T, R>(arr: T[], callbackfn: (previousValue: T | R, currentValue?: T, currentIndex?: number, array?: T[]) => R, initialValue?: R): R {
|
|
385
|
-
let len = arr.length;
|
|
386
|
-
let lp = 0;
|
|
387
532
|
let value;
|
|
388
533
|
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
while (lp < len && !(lp in arr)) {
|
|
394
|
-
lp++;
|
|
534
|
+
if (arr) {
|
|
535
|
+
// For Performance try and use the native instance, using string lookup of the function to easily pass the ES3 build checks and minification
|
|
536
|
+
if (arr[strReduce]) {
|
|
537
|
+
return arr[strReduce]<R>(callbackfn, initialValue);
|
|
395
538
|
}
|
|
396
539
|
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
if (
|
|
402
|
-
value =
|
|
540
|
+
let len = arr.length;
|
|
541
|
+
let lp = 0;
|
|
542
|
+
|
|
543
|
+
// Specifically checking the number of passed arguments as the value could be anything
|
|
544
|
+
if (arguments.length >= 3) {
|
|
545
|
+
value = arguments[2];
|
|
546
|
+
} else {
|
|
547
|
+
while (lp < len && !(lp in arr)) {
|
|
548
|
+
lp++;
|
|
549
|
+
}
|
|
550
|
+
|
|
551
|
+
value = arr[lp++];
|
|
552
|
+
}
|
|
553
|
+
|
|
554
|
+
while (lp < len) {
|
|
555
|
+
if (lp in arr) {
|
|
556
|
+
value = callbackfn(value, arr[lp], lp, arr);
|
|
557
|
+
}
|
|
558
|
+
lp++;
|
|
403
559
|
}
|
|
404
|
-
lp++;
|
|
405
560
|
}
|
|
406
561
|
|
|
407
562
|
return value;
|
|
@@ -411,11 +566,12 @@ export function arrReduce<T, R>(arr: T[], callbackfn: (previousValue: T | R, cur
|
|
|
411
566
|
* helper method to trim strings (IE8 does not implement String.prototype.trim)
|
|
412
567
|
*/
|
|
413
568
|
export function strTrim(str: any): string {
|
|
414
|
-
if (
|
|
415
|
-
|
|
569
|
+
if (str) {
|
|
570
|
+
// For Performance try and use the native instance, using string lookup of the function to easily pass the ES3 build checks and minification
|
|
571
|
+
str = (_strTrim && str[cStrTrim]) ? str[cStrTrim]() : (str.replace ? str.replace(/^\s+|\s+$/g, "") : str);
|
|
416
572
|
}
|
|
417
|
-
|
|
418
|
-
return str
|
|
573
|
+
|
|
574
|
+
return str;
|
|
419
575
|
}
|
|
420
576
|
|
|
421
577
|
let _objKeysHasDontEnumBug = !({ toString: null }).propertyIsEnumerable("toString");
|
|
@@ -442,6 +598,11 @@ export function objKeys(obj: {}): string[] {
|
|
|
442
598
|
throwTypeError("objKeys called on non-object");
|
|
443
599
|
}
|
|
444
600
|
|
|
601
|
+
// For Performance try and use the native instance, using string lookup of the function to easily pass the ES3 build checks and minification
|
|
602
|
+
if (!_objKeysHasDontEnumBug && obj[strKeys]) {
|
|
603
|
+
return obj[strKeys]();
|
|
604
|
+
}
|
|
605
|
+
|
|
445
606
|
let result: string[] = [];
|
|
446
607
|
|
|
447
608
|
for (let prop in obj) {
|
|
@@ -499,21 +660,12 @@ export function objDefineAccessors<T>(target: any, prop: string, getProp?: () =>
|
|
|
499
660
|
return false;
|
|
500
661
|
}
|
|
501
662
|
|
|
502
|
-
|
|
503
|
-
if (_objFreeze) {
|
|
504
|
-
value = _objFreeze(value) as T;
|
|
505
|
-
}
|
|
506
|
-
|
|
663
|
+
function _doNothing<T>(value: T): T {
|
|
507
664
|
return value;
|
|
508
665
|
}
|
|
509
666
|
|
|
510
|
-
export
|
|
511
|
-
|
|
512
|
-
value = _objSeal(value) as T;
|
|
513
|
-
}
|
|
514
|
-
|
|
515
|
-
return value;
|
|
516
|
-
}
|
|
667
|
+
export const objFreeze: <T>(value: T) => T = _objFreeze || _doNothing;
|
|
668
|
+
export const objSeal: <T>(value: T) => T = _objSeal || _doNothing;
|
|
517
669
|
|
|
518
670
|
/**
|
|
519
671
|
* Return the current time via the Date now() function (if available) and falls back to (new Date()).getTime() if now() is unavailable (IE8 or less)
|
|
@@ -521,11 +673,8 @@ export function objSeal<T>(value: T): T {
|
|
|
521
673
|
*/
|
|
522
674
|
export function dateNow() {
|
|
523
675
|
let dt = Date;
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
}
|
|
527
|
-
|
|
528
|
-
return new dt().getTime();
|
|
676
|
+
|
|
677
|
+
return dt.now ? dt.now() : new dt().getTime();
|
|
529
678
|
}
|
|
530
679
|
|
|
531
680
|
/**
|
|
@@ -687,3 +836,76 @@ export function optimizeObject<T>(theObject: T): T {
|
|
|
687
836
|
|
|
688
837
|
return theObject;
|
|
689
838
|
}
|
|
839
|
+
|
|
840
|
+
/**
|
|
841
|
+
* Pass in the objects to merge as arguments, this will only "merge" (extend) properties that are owned by the object.
|
|
842
|
+
* It will NOT merge inherited or non-enumerable properties.
|
|
843
|
+
* @param obj1 - object to merge. Set this argument to 'true' for a deep extend.
|
|
844
|
+
* @param obj2 - object to merge.
|
|
845
|
+
* @param obj3 - object to merge.
|
|
846
|
+
* @param obj4 - object to merge.
|
|
847
|
+
* @param obj5 - object to merge.
|
|
848
|
+
* @returns The extended first object.
|
|
849
|
+
*/
|
|
850
|
+
export function objExtend<T1, T2, T3, T4, T5, T6>(obj?: boolean | T1, obj2?: T2, obj3?: T3, obj4?: T4, obj5?: T5, obj6?: T6): T1 & T2 & T3 & T4 & T5 & T6 {
|
|
851
|
+
// Variables
|
|
852
|
+
let theArgs = arguments as any;
|
|
853
|
+
let extended: T1 & T2 & T3 & T4 & T5 & T6 = theArgs[0] || {};
|
|
854
|
+
let argLen = theArgs.length;
|
|
855
|
+
let deep = false;
|
|
856
|
+
let idx = 1;
|
|
857
|
+
|
|
858
|
+
// Check for "Deep" flag
|
|
859
|
+
if (argLen > 0 && isBoolean(extended)) {
|
|
860
|
+
deep = extended;
|
|
861
|
+
extended = theArgs[idx] || {};
|
|
862
|
+
idx++;
|
|
863
|
+
}
|
|
864
|
+
|
|
865
|
+
// Handle case when target is a string or something (possible in deep copy)
|
|
866
|
+
if (!isObject(extended)) {
|
|
867
|
+
extended = {} as T1 & T2 & T3 & T4 & T5 & T6;
|
|
868
|
+
}
|
|
869
|
+
|
|
870
|
+
// Loop through each remaining object and conduct a merge
|
|
871
|
+
for (; idx < argLen; idx++ ) {
|
|
872
|
+
let arg = theArgs[idx];
|
|
873
|
+
let isArgArray = isArray(arg);
|
|
874
|
+
let isArgObj = isObject(arg);
|
|
875
|
+
for (let prop in arg) {
|
|
876
|
+
let propOk = (isArgArray && (prop in arg)) || (isArgObj && (ObjHasOwnProperty.call(arg, prop)));
|
|
877
|
+
if (!propOk) {
|
|
878
|
+
continue;
|
|
879
|
+
}
|
|
880
|
+
|
|
881
|
+
let newValue = arg[prop];
|
|
882
|
+
let isNewArray: boolean;
|
|
883
|
+
|
|
884
|
+
// If deep merge and property is an object, merge properties
|
|
885
|
+
if (deep && newValue && ((isNewArray = isArray(newValue)) || isPlainObject(newValue))) {
|
|
886
|
+
// Grab the current value of the extended object
|
|
887
|
+
let clone = extended[prop];
|
|
888
|
+
|
|
889
|
+
if (isNewArray) {
|
|
890
|
+
if (!isArray(clone)) {
|
|
891
|
+
// We can't "merge" an array with a non-array so overwrite the original
|
|
892
|
+
clone = [];
|
|
893
|
+
}
|
|
894
|
+
} else if (!isPlainObject(clone)) {
|
|
895
|
+
// We can't "merge" an object with a non-object
|
|
896
|
+
clone = {};
|
|
897
|
+
}
|
|
898
|
+
|
|
899
|
+
// Never move the original objects always clone them
|
|
900
|
+
newValue = objExtend(deep, clone, newValue);
|
|
901
|
+
}
|
|
902
|
+
|
|
903
|
+
// Assign the new (or previous) value (unless undefined)
|
|
904
|
+
if (newValue !== undefined) {
|
|
905
|
+
extended[prop] = newValue;
|
|
906
|
+
}
|
|
907
|
+
}
|
|
908
|
+
}
|
|
909
|
+
|
|
910
|
+
return extended;
|
|
911
|
+
}
|
|
@@ -5,7 +5,7 @@ import {
|
|
|
5
5
|
IInstrumentHooksCallbacks, IInstrumentHooks, IInstrumentHook, IInstrumentCallDetails, InstrumentorHooksCallback
|
|
6
6
|
} from "../JavaScriptSDK.Interfaces/IInstrumentHooks";
|
|
7
7
|
import { strShimFunction, strShimPrototype } from "@microsoft/applicationinsights-shims";
|
|
8
|
-
import { hasOwnProperty } from "./HelperFuncs";
|
|
8
|
+
import { hasOwnProperty, _getObjProto } from "./HelperFuncs";
|
|
9
9
|
|
|
10
10
|
const aiInstrumentHooks = "_aiHooks";
|
|
11
11
|
|
|
@@ -20,19 +20,6 @@ const cbNames = [
|
|
|
20
20
|
"req", "rsp", "hkErr", "fnErr"
|
|
21
21
|
];
|
|
22
22
|
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* Constant string defined to support minimization
|
|
26
|
-
* @ignore
|
|
27
|
-
*/
|
|
28
|
-
const str__Proto = "__proto__";
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Constant string defined to support minimization
|
|
32
|
-
* @ignore
|
|
33
|
-
*/
|
|
34
|
-
const strConstructor = "constructor";
|
|
35
|
-
|
|
36
23
|
/** @ignore */
|
|
37
24
|
function _arrLoop<T>(arr:T[], fn:(value:T, idx:number) => boolean|number|void) {
|
|
38
25
|
if (arr) {
|
|
@@ -139,33 +126,6 @@ function _createFunctionHook(aiHook:IInstrumentHooks) {
|
|
|
139
126
|
}
|
|
140
127
|
|
|
141
128
|
|
|
142
|
-
/**
|
|
143
|
-
* Pre-lookup to check if we are running on a modern browser (i.e. not IE8)
|
|
144
|
-
* @ignore
|
|
145
|
-
*/
|
|
146
|
-
let _objGetPrototypeOf = Object["getPrototypeOf"];
|
|
147
|
-
|
|
148
|
-
/**
|
|
149
|
-
* Helper used to get the prototype of the target object as getPrototypeOf is not available in an ES3 environment.
|
|
150
|
-
* @ignore
|
|
151
|
-
*/
|
|
152
|
-
function _getObjProto(target:any) {
|
|
153
|
-
if (target) {
|
|
154
|
-
// This method doesn't existing in older browsers (e.g. IE8)
|
|
155
|
-
if (_objGetPrototypeOf) {
|
|
156
|
-
return _objGetPrototypeOf(target);
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
// target[Constructor] May break if the constructor has been changed or removed
|
|
160
|
-
let newProto = target[str__Proto] || target[strShimPrototype] || target[strConstructor];
|
|
161
|
-
if(newProto) {
|
|
162
|
-
return newProto;
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
return null;
|
|
167
|
-
}
|
|
168
|
-
|
|
169
129
|
/** @ignore */
|
|
170
130
|
function _getOwner(target:any, name:string, checkPrototype:boolean): any {
|
|
171
131
|
let owner = null;
|