8000 simplified the implementation to only support objects · optimizely/javascript-sdk@19e19ef · GitHub
[go: up one dir, main page]

Skip to content

Commit 19e19ef

Browse files
zashraf1985fayyazarshad
authored andcommitted
simplified the implementation to only support objects
1 parent 99da128 commit 19e19ef

File tree

2 files changed

+6
-26
lines changed

2 files changed

+6
-26
lines changed

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

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -27,25 +27,9 @@ module.exports = {
2727
return Math.round(new Date().getTime());
2828
},
2929
isArray: require('lodash/isArray'),
30-
isEmpty: function isEmpty(value) {
31-
if (value == null) {
32-
return true;
33-
}
34-
var length = value.length;
35-
if (typeof length == 'number' && length > -1 && length % 1 === 0 && length <= MAX_SAFE_INTEGER) {
36-
var type = typeof value;
37-
if (type === 'object') {
38-
return !value.length;
39-
}
40-
}
41-
for (var key in value) {
42-
if (hasOwnProperty.call(value, key)) {
43-
return false;
44-
}
45-
}
46-
return true;
47-
}
48-
,
30+
isEmpty: function(obj) {
31+
return !obj || Object.keys(obj).length === 0;
32+
},
4933
isFinite: function(number) {
5034
return _isFinite(number) && Math.abs(number) <= MAX_NUMBER_LIMIT;
5135
},

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

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,20 +38,16 @@ describe('lib/utils/fns', function() {
3838
});
3939
});
4040
describe('isEmpty', function() {
41-
it('should return true in case of null', function() {
41+
it('should return true when object is null', function() {
4242
assert.isTrue(fns.isEmpty(null));
4343
});
44-
it('should return True in case of empty {}', function() {
44+
it('should return true when object is empty {}', function() {
4545
assert.isTrue(fns.isEmpty({}));
4646
});
47-
it('should return false in case of value object', function() {
47+
it('should return false when object has attributes', function() {
4848
var obj = { "key": "value" };
4949
assert.isFalse(fns.isEmpty(obj));
5050
});
51-
it('should return true if anything else than an object', function() {
52-
var obj = { "key": "value" };
53-
assert.isTrue(fns.isEmpty(1));
54-
});
5551
});
5652
});
5753
});

0 commit comments

Comments
 (0)
0