7
7
several condition arrays.
8
8
*/
9
9
10
- export const conditionsMapper = ( { conditions} ) => {
11
- if ( ! conditions ) return { } ;
10
+ function isObject ( obj ) {
11
+ return obj !== null && typeof obj === 'object' && ! Array . isArray ( obj ) ;
12
+ }
12
13
13
- function isObject ( obj ) {
14
- return obj !== null && typeof obj === 'object' && ! Array . isArray ( obj ) ;
15
- }
14
+ function isArray ( obj ) {
15
+ return Array . isArray ( obj ) ;
16
+ }
16
17
17
- function isArray ( obj ) {
18
- return Array . isArray ( obj ) ;
19
- }
18
+ export const conditionsMapper = ( { conditions} ) => {
19
+ if ( ! conditions ) return { } ;
20
20
21
21
function traverse ( { obj, fnc, key} ) {
22
22
fnc && fnc ( { obj, key} ) ;
@@ -37,27 +37,23 @@ export const conditionsMapper = ({conditions}) => {
37
37
}
38
38
39
39
function traverseArray ( { obj, fnc, key} ) {
40
- for ( var index = 0 , len = obj . length ; index < len ; index ++ ) {
41
- const item = obj [ index ] ;
40
+ obj . forEach ( ( [ key , item ] ) => {
42
41
traverse ( {
43
42
obj : item ,
44
43
fnc,
45
- key : index ,
44
+ key,
46
45
} ) ;
47
- }
46
+ } ) ;
48
47
}
49
48
50
49
function traverseObject ( { obj, fnc, key} ) {
51
- for ( var index in obj ) {
52
- if ( obj . hasOwnProperty ( index ) ) {
53
- const item = obj [ index ] ;
54
- traverse ( {
55
- obj : item ,
56
- fnc,
57
- key : index ,
58
- } ) ;
59
- }
60
- }
50
+ Object . entries ( obj ) . forEach ( ( [ key , item ] ) => {
51
+ traverse ( {
52
+ obj : item ,
53
+ fnc,
54
+ key,
55
+ } ) ;
56
+ } ) ;
61
57
}
62
58
63
59
const indexedConditions = { } ;
0 commit comments