8000 converted fns · optimizely/javascript-sdk@85bd3d0 · GitHub
[go: up one dir, main page]

Skip to content

Commit 85bd3d0

Browse files
committed
converted fns
1 parent 32cb7bf commit 85bd3d0

File tree

3 files changed

+61
-46
lines changed

3 files changed

+61
-46
lines changed

packages/optimizely-sdk/lib/optimizely/index.tests.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import enums from '../utils/enums';
2929
import eventBuilder from '../core/event_builder/index.js';
3030
import eventDispatcher from '../plugins/event_dispatcher/index.node';
3131
import errorHandler from '../plugins/error_handler';
32-
import fns from '../utils/fns';
32+
import * as fns from '../utils/fns';
3333
import logger from '../plugins/logger';
3434
import decisionService from '../core/decision_service';
3535
import jsonSchemaValidator from '../utils/json_schema_validator';
Lines changed: 57 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2017, 2019-2020, Optimizely
2+
* Copyright 2017, 2019-2020 Optimizely
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -13,48 +13,64 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
var uuid = require('uuid');
16+
import { keyBy as keyByUtil } from '@optimizely/js-sdk-utils';
17+
18+
import uid from 'uuid';
19+
1720
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];
3637
}
3738
}
3839
}
39-
return to;
4040
}
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+
}

packages/optimizely-sdk/lib/utils/fns/index.tests.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2019, Optimizely
2+
* Copyright 2019-2020 Optimizely
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -13,10 +13,9 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16+
import { assert } from 'chai';
1617

17-
var chai = require('chai');
18-
var assert = chai.assert;
19-
var fns = require('./');
18+
import fns from './';
2019

2120
describe('lib/utils/fns', function() {
2221
describe('APIs', function() {

0 commit comments

Comments
 (0)
0