File tree Expand file tree Collapse file tree 2 files changed +6
-26
lines changed
packages/optimizely-sdk/lib/utils/fns Expand file tree Collapse file tree 2 files changed +6
-26
lines changed Original file line number Diff line number Diff line change @@ -27,25 +27,9 @@ module.exports = {
27
27
return Math . round ( new Date ( ) . getTime ( ) ) ;
28
28
} ,
29
29
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
+ } ,
49
33
isFinite : function ( number ) {
50
34
return _isFinite ( number ) && Math . abs ( number ) <= MAX_NUMBER_LIMIT ;
51
35
} ,
Original file line number Diff line number Diff line change @@ -38,20 +38,16 @@ describe('lib/utils/fns', function() {
38
38
} ) ;
39
39
} ) ;
40
40
describe ( 'isEmpty' , function ( ) {
41
- it ( 'should return true in case of null' , function ( ) {
41
+ it ( 'should return true when object is null' , function ( ) {
42
42
assert . isTrue ( fns . isEmpty ( null ) ) ;
43
43
} ) ;
44
- it ( 'should return True in case of empty {}' , function ( ) {
44
+ it ( 'should return true when object is empty {}' , function ( ) {
45
45
assert . isTrue ( fns . isEmpty ( { } ) ) ;
46
46
} ) ;
47
- it ( 'should return false in case of value object ' , function ( ) {
47
+ it ( 'should return false when object has attributes ' , function ( ) {
48
48
var obj = { "key" : "value" } ;
49
49
assert . isFalse ( fns . isEmpty ( obj ) ) ;
50
50
} ) ;
51
- it ( 'should return true if anything else than an object' , function ( ) {
52
- var obj = { "key" : "value" } ;
53
- assert . isTrue ( fns . isEmpty ( 1 ) ) ;
54
- } ) ;
55
51
} ) ;
56
52
} ) ;
57
53
} ) ;
You can’t perform that action at this time.
0 commit comments