|
1 | 1 | /**
|
2 |
| - * Copyright 2017, 2019-2020, Optimizely |
| 2 | + * Copyright 2017, 2019-2020 Optimizely |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
|
13 | 13 | * See the License for the specific language governing permissions and
|
14 | 14 | * limitations under the License.
|
15 | 15 | */
|
16 |
| -var uuid = require('uuid'); |
| 16 | +import { keyBy as keyByUtil } from '@optimizely/js-sdk-utils'; |
| 17 | + |
| 18 | +import uid from 'uuid'; |
| 19 | + |
17 | 20 | var MAX_SAFE_INTEGER_LIMIT = Math.pow(2, 53);
|
18 |
| -var keyBy = require('@optimizely/js-sdk-utils').keyBy; |
19 |
| -module.exports = { |
20 |
| - assign: function(target) { |
21 |
| - if (!target) { |
22 |
| - return {}; |
23 |
| - } |
24 |
| - if (typeof Object.assign === 'function') { |
25 |
| - return Object.assign.apply(Object, arguments); |
26 |
| - } else { |
27 |
| - var to = Object(target); |
28 |
| - for (var index = 1; index < arguments.length; index++) { |
29 |
| - var nextSource = arguments[index]; |
30 |
| - if (nextSource !== null && nextSource !== undefined) { |
31 |
| - for (var nextKey in nextSource) { |
32 |
| - // Avoid bugs when hasOwnProperty is shadowed |
33 |
| - if (Object.prototype.hasOwnProperty.call(nextSource, nextKey)) { |
34 |
| - to[nextKey] = nextSource[nextKey]; |
35 |
| - } |
| 21 | + |
| 22 | +export var assign = function(target) { |
| 23 | + if (!target) { |
| 24 | + return {}; |
| 25 | + } |
| 26 | + if (typeof Object.assign === 'function') { |
| 27 | + return Object.assign.apply(Object, arguments); |
| 28 | + } else { |
| 29 | + var to = Object(target); |
| 30 | + for (var index = 1; index < arguments.length; index++) { |
| 31 | + var nextSource = arguments[index]; |
| 32 | + if (nextSource !== null && nextSource !== undefined) { |
| 33 | + for (var nextKey in nextSource) { |
| 34 | + // Avoid bugs when hasOwnProperty is shadowed |
| 35 | + if (Object.prototype.hasOwnProperty.call(nextSource, nextKey)) { |
| 36 | + to[nextKey] = nextSource[nextKey]; |
36 | 37 | }
|
37 | 38 | }
|
38 | 39 | }
|
39 |
| - return to; |
40 | 40 | }
|
41 |
| - }, |
42 |
| - currentTimestamp: function() { |
43 |
| - return Math.round(new Date().getTime()); |
44 |
| - }, |
45 |
| - isSafeInteger: function(number) { |
46 |
| - return typeof number == 'number' && Math.abs(number) <= MAX_SAFE_INTEGER_LIMIT; |
47 |
| - }, |
48 |
| - keyBy: function(arr, key) { |
49 |
| - if (!arr) return {}; |
50 |
| - return keyBy(arr, function(item) { |
51 |
| - return item[key]; |
52 |
| - }); |
53 |
| - }, |
54 |
| - uuid: function() { |
55 |
| - return uuid.v4(); |
56 |
| - }, |
57 |
| - isNumber: function(value) { |
58 |
| - return typeof value === 'number'; |
59 |
| - }, |
60 |
| -}; |
| 41 | + return to; |
| 42 | + } |
| 43 | +} |
| 44 | + |
| 45 | +export var currentTimestamp = function() { |
| 46 | + console.log('Calling Actual Method'); |
| 47 | + return Math.round(new Date().getTime()); |
| 48 | +} |
| 49 | + |
| 50 | +export var isSafeInteger = function(number) { |
| 51 | + return typeof number == 'number' && Math.abs(number) <= MAX_SAFE_INTEGER_LIMIT; |
| 52 | +} |
| 53 | + |
| 54 | +export var keyBy = function(arr, key) { |
| 55 | + if (!arr) return {}; |
| 56 | + return keyByUtil(arr, function(item) { |
| 57 | + return item[key]; |
| 58 | + }); |
| 59 | +} |
| 60 | + |
| 61 | +export var uuid = function() { |
| 62 | + return uid.v4(); |
| 63 | +} |
| 64 | + |
| 65 | +export var isNumber = function(value) { |
| 66 | + return typeof value === 'number'; |
| 67 | +} |
| 68 | + |
| 69 | +export default { |
| 70 | + assign: assign, |
| 71 | + currentTimestamp: currentTimestamp, |
| 72 | + isSafeInteger: isSafeInteger, |
| 73 | + keyBy: keyBy, |
| 74 | + uuid: uuid, |
| 75 | + isNumber: isNumber, |
| 76 | +} |
0 commit comments