12
12
const DOMAIN = 'utils'
13
13
14
14
const INFINITY = 1 / 0
15
- const MAX_INTEGER = 1.7976931348623157e+308
15
+ const MAX_INTEGER = 1.7976931348623157e308
16
16
const BOOL_TAG = '[object Boolean]'
17
17
const DATE_TAG = '[object Date]'
18
18
const FUNC_TAG = '[object Function]'
@@ -24,8 +24,14 @@ const objToString = Object.prototype.toString
24
24
const PATH = / ^ ( .+ ) \. ( .+ ) $ /
25
25
26
26
const ERRORS = {
27
- '400' ( ) { return `expected: ${ arguments [ 0 ] } , found: ${ arguments [ 2 ] ? arguments [ 1 ] : typeof arguments [ 1 ] } ` } ,
28
- '404' ( ) { return `${ arguments [ 0 ] } not found` }
27
+ '400' ( ) {
28
+ return `expected: ${ arguments [ 0 ] } , found: ${
29
+ arguments [ 2 ] ? arguments [ 1 ] : typeof arguments [ 1 ]
30
+ } `
31
+ } ,
32
+ '404' ( ) {
33
+ return `${ arguments [ 0 ] } not found`
34
+ }
29
35
}
30
36
31
37
const toInteger = function ( value ) {
@@ -35,7 +41,7 @@ const toInteger = function (value) {
35
41
// Coerce to number
36
42
value = + value
37
43
if ( value === INFINITY || value === - INFINITY ) {
38
- const sign = ( value < 0 ? - 1 : 1 )
44
+ const sign = value < 0 ? - 1 : 1
39
45
return sign * MAX_INTEGER
40
46
}
41
47
const remainder = value % 1
@@ -47,7 +53,7 @@ const toStr = function (value) {
47
53
}
48
54
49
55
const isPlainObject = function ( value ) {
50
- return ( ! ! value && typeof value === 'object' && value . constructor === Object )
56
+ return ! ! value && typeof value === 'object' && value . constructor === Object
51
57
}
52
58
53
59
const mkdirP = function ( object , path ) {
@@ -96,7 +102,12 @@ const utils = {
96
102
*/
97
103
_ ( dest , src ) {
98
104
utils . forOwn ( src , function ( value , key ) {
99
- if ( key && dest [ key ] === undefined && ! utils . isFunction ( value ) && key . indexOf ( '_' ) !== 0 ) {
105
+ if (
106
+ key &&
107
+ dest [ key ] === undefined &&
108
+ ! utils . isFunction ( value ) &&
109
+ key . indexOf ( '_' ) !== 0
110
+ ) {
100
111
dest [ key ] = value
101
112
}
102
113
} )
@@ -138,7 +149,12 @@ const utils = {
138
149
optsCopy . with = opts . with . slice ( )
139
150
optsCopy . _activeWith = optsCopy . with . splice ( index , 1 ) [ 0 ]
140
151
optsCopy . with . forEach ( function ( relation , i ) {
141
- if ( relation && relation . indexOf ( containedName ) === 0 && relation . length >= containedName . length && relation [ containedName . length ] === '.' ) {
152
+ if (
153
+ relation &&
154
+ relation . indexOf ( containedName ) === 0 &&
155
+ relation . length >= containedName . length &&
156
+ relation [ containedName . length ] === '.'
157
+ ) {
142
158
optsCopy . with [ i ] = relation . substr ( containedName . length + 1 )
143
159
} else {
144
160
optsCopy . with [ i ] = ''
@@ -225,9 +241,10 @@ const utils = {
225
241
areDifferent ( newObject , oldObject , opts ) {
226
242
opts || ( opts = { } )
227
243
const diff = utils . diffObjects ( newObject , oldObject , opts )
228
- const diffCount = Object . keys ( diff . added ) . length +
229
- Object . keys ( diff . removed ) . length +
230
- Object . keys ( diff . changed ) . length
244
+ const diffCount =
245
+ Object . keys ( diff . added ) . length +
246
+ Object . keys ( diff . removed ) . length +
247
+ Object . keys ( diff . changed ) . length
231
248
return diffCount > 0
232
249
} ,
233
250
@@ -293,13 +310,23 @@ const utils = {
293
310
if ( plain ) {
294
311
to = utils . copy ( from , { } , stackFrom , stackTo , blacklist , plain )
295
312
} else {
296
- to = utils . copy ( from , Object . create ( Object . getPrototypeOf ( from ) ) , stackFrom , stackTo , blacklist , plain )
313
+ to = utils . copy (
314
+ from ,
315
+ Object . create ( Object . getPrototypeOf ( from ) ) ,
316
+ stackFrom ,
317
+ stackTo ,
318
+ blacklist ,
319
+ plain
320
+ )
297
321
}
298
322
}
299
323
}
300
324
} else {
301
325
if ( from === to ) {
302
- throw utils . err ( `${ DOMAIN } .copy` ) ( 500 , 'Cannot copy! Source and destination are identical.' )
326
+ throw utils . err ( `${ DOMAIN } .copy` ) (
327
+ 500 ,
328
+ 'Cannot copy! Source and destination are identical.'
329
+ )
303
330
}
304
331
305
332
stackFrom = stackFrom || [ ]
@@ -320,7 +347,14 @@ const utils = {
320
347
let i
321
348
to . length = 0
322
349
for ( i = 0 ; i < from . length ; i ++ ) {
323
- result = utils . copy ( from [ i ] , null , stackFrom , stackTo , blacklist , plain )
350
+ result = utils . copy (
351
+ from [ i ] ,
352
+ null ,
353
+ stackFrom ,
354
+ stackTo ,
355
+ blacklist ,
356
+ plain
357
+ )
324
358
if ( utils . isObject ( from [ i ] ) ) {
325
359
stackFrom . push ( from [ i ] )
326
360
stackTo . push ( result )
@@ -340,7 +374,14 @@ const utils = {
340
374
if ( utils . isBlacklisted ( key , blacklist ) ) {
341
375
continue
342
376
}
343
- result = utils . copy ( from [ key ] , null , stackFrom , stackTo , blacklist , plain )
377
+ result = utils . copy (
378
+ from [ key ] ,
379
+ null ,
380
+ stackFrom ,
381
+ stackTo ,
382
+ blacklist ,
383
+ plain
384
+ )
344
385
if ( utils . isObject ( from [ key ] ) ) {
345
386
stackFrom . push ( from [ key ] )
346
387
stackTo . push ( result )
@@ -523,7 +564,10 @@ http://www.js-data.io/v3.0/docs/errors#400]
523
564
err ( domain , target ) {
524
565
return function ( code ) {
525
566
const prefix = `[${ domain } :${ target } ] `
526
- let message = ERRORS [ code ] . apply ( null , Array . prototype . slice . call ( arguments , 1 ) )
567
+ let message = ERRORS [ code ] . apply (
568
+ null ,
569
+ Array . prototype . slice . call ( arguments , 1 )
570
+ )
527
571
message = `${ prefix } ${ message }
528
572
http://www.js-data.io/v3.0/docs/errors#${ code } `
529
573
return new Error ( message )
@@ -552,8 +596,12 @@ http://www.js-data.io/v3.0/docs/errors#${code}`
552
596
target = target || this
553
597
let _events = { }
554
598
if ( ! getter && ! setter ) {
555
- getter = function ( ) { return _events }
556
- setter = function ( value ) { _events = value }
599
+ getter = function ( ) {
600
+ return _events
601
+ }
602
+ setter = function ( value ) {
603
+ _events = value
604
+ }
557
605
}
558
606
Object . defineProperties ( target , {
559
607
emit : {
@@ -831,16 +879,18 @@ http://www.js-data.io/v3.0/docs/errors#${code}`
831
879
* @see utils.set
832
880
* @since 3.0.0
833
881
*/
834
- ' get' : function ( object , prop ) {
882
+ get : function ( object , prop ) {
835
883
if ( ! prop ) {
836
884
return
837
885
}
838
886
const parts = prop . split ( '.' )
839
887
const last = parts . pop ( )
840
888
841
- while ( prop = parts . shift ( ) ) { // eslint-disable-line
889
+ while ( ( prop = parts . shift ( ) ) ) {
890
+ // eslint-disable-line
842
891
object = object [ prop ]
843
- if ( object == null ) { // eslint-disable-line
892
+ if ( object == null ) {
893
+ // eslint-disable-line
844
894
return
845
895
}
846
896
}
@@ -904,6 +954,8 @@ http://www.js-data.io/v3.0/docs/errors#${code}`
904
954
if ( ! array1 || ! array2 ) {
905
955
return [ ]
906
956
}
957
+ array1 = Array . isArray ( array1 ) ? array1 : [ array1 ]
958
+ array2 = Array . isArray ( array2 ) ? array2 : [ array2 ]
907
959
const result = [ ]
908
960
let item
909
961
let i
@@ -961,7 +1013,10 @@ http://www.js-data.io/v3.0/docs/errors#${code}`
961
1013
}
962
1014
let matches
963
1015
for ( var i = 0 ; i < blacklist . length ; i ++ ) {
964
- if ( ( toStr ( blacklist [ i ] ) === REGEXP_TAG && blacklist [ i ] . test ( prop ) ) || blacklist [ i ] === prop ) {
1016
+ if (
1017
+ ( toStr ( blacklist [ i ] ) === REGEXP_TAG && blacklist [ i ] . test ( prop ) ) ||
1018
+ blacklist [ i ] === prop
1019
+ ) {
965
1020
matches = prop
966
1021
return ! ! matches
967
1022
}
@@ -1004,7 +1059,7 @@ http://www.js-data.io/v3.0/docs/errors#${code}`
1004
1059
* @since 3.0.0
1005
1060
*/
1006
1061
isDate ( value ) {
1007
- return ( value && typeof value === 'object' && toStr ( value ) === DATE_TAG )
1062
+ return value && typeof value === 'object' && toStr ( value ) === DATE_TAG
1008
1063
} ,
1009
1064
1010
1065
/**
@@ -1085,7 +1140,10 @@ http://www.js-data.io/v3.0/docs/errors#${code}`
1085
1140
*/
1086
1141
isNumber ( value ) {
1087
1142
const type = typeof value
1088
- return type === 'number' || ( value && type === 'object' && toStr ( value ) === NUMBER_TAG )
1143
+ return (
1144
+ type === 'number' ||
1145
+ ( value && type === 'object' && toStr ( value ) === NUMBER_TAG )
1146
+ )
1089
1147
} ,
1090
1148
1091
1149
/**
@@ -1164,7 +1222,10 @@ http://www.js-data.io/v3.0/docs/errors#${code}`
1164
1222
* @since 3.0.0
1165
1223
*/
1166
1224
isString ( value ) {
1167
- return typeof value === 'string' || ( value && typeof value === 'object' && toStr ( value ) === STRING_TAG )
1225
+ return (
1226
+ typeof value === 'string' ||
1227
+ ( value && typeof value === 'object' && toStr ( value ) === STRING_TAG )
1228
+ )
1168
1229
} ,
1169
1230
1170
1231
/**
@@ -1223,7 +1284,8 @@ http://www.js-data.io/v3.0/docs/errors#${code}`
1223
1284
if ( level === 'debug' && ! this . debug ) {
1224
1285
return
1225
1286
}
1226
- const prefix = `${ level . toUpperCase ( ) } : (${ this . name || this . constructor . name } )`
1287
+ const prefix = `${ level . toUpperCase ( ) } : (${ this . name ||
1288
+ this . constructor . name } )`
1227
1289
if ( utils . isFunction ( console [ level ] ) ) {
1228
1290
console [ level ] ( prefix , ...args )
1229
1291
} else {
@@ -1575,9 +1637,11 @@ http://www.js-data.io/v3.0/docs/errors#${code}`
1575
1637
const parts = path . split ( '.' )
1576
1638
const last = parts . pop ( )
1577
1639
1578
- while ( path = parts . shift ( ) ) { // eslint-disable-line
1640
+ while ( ( path = parts . shift ( ) ) ) {
1641
+ // eslint-disable-line
1579
1642
object = object [ path ]
1580
- if ( object == null ) { // eslint-disable-line
1643
+ if ( object == null ) {
1644
+ // eslint-disable-line
1581
1645
return
1582
1646
}
1583
1647
}
0 commit comments