@@ -16,24 +16,36 @@ function nodeAsRegex(node) {
16
16
return new RegExp ( node . text . replace ( / ( ^ { | } $ ) / g, "" ) ) ;
17
17
}
18
18
19
+ /**
20
+ * Iterates over object or array, passing each key, value and parentObject to the callback
21
+ * @param value - to iterate
22
+ * @param callback - receiving key on given input value
23
+ */
24
+ function forEach ( parent : Record < string , unknown > | unknown [ ] , callback ) {
25
+ if ( Array . isArray ( parent ) ) {
26
+ parent . forEach ( callback ) ;
27
+ } else if ( Object . prototype . toString . call ( parent ) === "[object Object]" ) {
28
+ Object . keys ( parent ) . forEach ( function ( key ) {
29
+ callback ( parent [ key ] , key , parent ) ;
30
+ } ) ;
31
+ }
32
+ }
33
+
19
34
/**
20
35
* Returns all keys of the given input data
21
- *
22
36
* @param value
23
37
* @return {Array } containing keys of given value
24
38
*/
25
- function getKeys ( value : unknown ) {
26
- let keys ;
39
+ function getKeys ( value : unknown ) : string [ ] {
27
40
if ( Array . isArray ( value ) ) {
28
- keys = value . map ( function ( value , index ) {
29
- return index ;
41
+ return value . map ( function ( value , index ) {
42
+ return ` ${ index } ` ;
30
43
} ) ;
31
- } else if ( Object . prototype . toString . call ( value ) === "[object Object]" ) {
44
+ }
45
+ if ( Object . prototype . toString . call ( value ) === "[object Object]" ) {
32
46
return Object . keys ( value ) ;
33
- } else {
34
- keys = [ ] ;
35
47
}
36
- return keys ;
48
+ return [ ] ;
37
49
}
38
50
39
51
const cache = {
@@ -70,7 +82,7 @@ const expand = {
70
82
71
83
all ( node : IToken , entry ) {
72
84
const result = [ entry ] ;
73
- o . forEach ( entry [ VALUE_INDEX ] , ( value , prop ) => {
85
+ forEach ( entry [ VALUE_INDEX ] , ( value , prop ) => {
74
86
const childEntry = cache . get ( entry , prop ) ;
75
87
// const childEntry = [value, prop, entry[VALUE_INDEX], join(entry[POINTER_INDEX], prop)];
76
88
childEntry && result . push ( ...expand . all ( node , childEntry ) ) ;
@@ -154,15 +166,13 @@ function expressionMatches(value, cmp, test) {
154
166
}
155
167
156
168
let valid ;
157
- const valueString = "" + value ;
158
-
169
+ const valueString = `${ value } ` ;
159
170
if ( test . type === "regex" ) {
160
171
const regex = nodeAsRegex ( test ) ;
161
172
valid = regex . test ( valueString ) ;
162
173
} else {
163
174
valid = valueString === test . text ;
164
175
}
165
-
166
176
if ( cmp . type === "isnot" ) {
167
177
valid = valid === false && value !== undefined ;
168
178
}
0 commit comments