@microsoft/applicationinsights-core-js 2.7.3 → 2.7.4-nightly.2202-03

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