@@ -16,24 +16,36 @@ function nodeAsRegex(node) {
1616    return  new  RegExp ( node . text . replace ( / ( ^ { | } $ ) / g,  "" ) ) ; 
1717} 
1818
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+ 
1934/** 
2035 * Returns all keys of the given input data 
21-  * 
2236 * @param   value 
2337 * @return  {Array } containing keys of given value 
2438 */ 
25- function  getKeys ( value : unknown )  { 
26-     let  keys ; 
39+ function  getKeys ( value : unknown ) : string [ ]  { 
2740    if  ( Array . isArray ( value ) )  { 
28-         keys   =  value . map ( function  ( value ,  index )  { 
29-             return  index ; 
41+         return  value . map ( function  ( value ,  index )  { 
42+             return  ` ${ index } ` ; 
3043        } ) ; 
31-     }  else  if  ( Object . prototype . toString . call ( value )  ===  "[object Object]" )  { 
44+     } 
45+     if  ( Object . prototype . toString . call ( value )  ===  "[object Object]" )  { 
3246        return  Object . keys ( value ) ; 
33-     }  else  { 
34-         keys  =  [ ] ; 
3547    } 
36-     return  keys ; 
48+     return  [ ] ; 
3749} 
3850
3951const  cache  =  { 
@@ -70,7 +82,7 @@ const expand = {
7082
7183    all ( node : IToken ,  entry )  { 
7284        const  result  =  [ entry ] ; 
73-         o . forEach ( entry [ VALUE_INDEX ] ,  ( value ,  prop )  =>  { 
85+         forEach ( entry [ VALUE_INDEX ] ,  ( value ,  prop )  =>  { 
7486            const  childEntry  =  cache . get ( entry ,  prop ) ; 
7587            // const childEntry = [value, prop, entry[VALUE_INDEX], join(entry[POINTER_INDEX], prop)]; 
7688            childEntry  &&  result . push ( ...expand . all ( node ,  childEntry ) ) ; 
@@ -154,15 +166,13 @@ function expressionMatches(value, cmp, test) {
154166    } 
155167
156168    let  valid ; 
157-     const  valueString  =  ""  +  value ; 
158- 
169+     const  valueString  =  `${ value }  ; 
159170    if  ( test . type  ===  "regex" )  { 
160171        const  regex  =  nodeAsRegex ( test ) ; 
161172        valid  =  regex . test ( valueString ) ; 
162173    }  else  { 
163174        valid  =  valueString  ===  test . text ; 
164175    } 
165- 
166176    if  ( cmp . type  ===  "isnot" )  { 
167177        valid  =  valid  ===  false  &&  value  !==  undefined ; 
168178    } 
0 commit comments