Commit 2fd7387 1 parent 164bf45 commit 2fd7387 Copy full SHA for 2fd7387
File tree 1 file changed +16
-10
lines changed
1 file changed +16
-10
lines changed Original file line number Diff line number Diff line change 142
142
}
143
143
}
144
144
145
- function getValueFromObject ( json , path ) {
145
+ function getValueFromObject ( object , path ) {
146
146
try {
147
- if ( typeof json == 'undefined' || ! path )
148
- return ;
147
+ if ( ! object || ! path )
148
+ // throw new Error("Invalid input to getValueFromObject");
149
+ return
149
150
150
151
path = path . replace ( / \[ ( \d + ) \] / g, '.$1' ) ;
151
152
152
- let jsonData = json , subpath = path . split ( '.' ) ;
153
+ let data = object , subpath = path . split ( '.' ) ;
153
154
154
155
for ( let i = 0 ; i < subpath . length ; i ++ ) {
155
- jsonData = jsonData [ subpath [ i ] ] ;
156
- if ( ! jsonData )
156
+ // if (!(subpath[i] in data))
157
+ // throw new Error("Key not found in object: " + subpath[i]);
158
+
159
+ data = data [ subpath [ i ] ] ;
160
+ if ( ! data )
157
161
return ;
158
162
}
159
163
160
- return jsonData ;
164
+ return data ;
161
165
} catch ( error ) {
162
- console . log ( "Error in getValueFromObject" , error ) ;
166
+ console . error ( "Error in getValueFromObject:" , error ) ;
167
+ // throw error;
163
168
}
164
169
}
165
170
594
599
595
600
function isMatch ( data , query ) {
596
601
for ( let key of Object . keys ( query ) ) {
602
+ // if (!data.hasOwnProperty(key))
603
+ // return false
604
+
597
605
let dataValue = getValueFromObject ( data , key )
598
- if ( ! dataValue )
599
- return false
600
606
601
607
if ( typeof query [ key ] === 'string' || typeof query [ key ] === 'number' || typeof query [ key ] === 'boolean' ) {
602
608
if ( Array . isArray ( dataValue ) )
You can’t perform that action at this time.
0 commit comments