Skip to content

Commit 2fd7387

Browse files
committed
fix: getValueFromObject conditions and param names
1 parent 164bf45 commit 2fd7387

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

src/index.js

+16-10
Original file line numberDiff line numberDiff line change
@@ -142,24 +142,29 @@
142142
}
143143
}
144144

145-
function getValueFromObject(json, path) {
145+
function getValueFromObject(object, path) {
146146
try {
147-
if (typeof json == 'undefined' || !path)
148-
return;
147+
if (!object || !path)
148+
// throw new Error("Invalid input to getValueFromObject");
149+
return
149150

150151
path = path.replace(/\[(\d+)\]/g, '.$1');
151152

152-
let jsonData = json, subpath = path.split('.');
153+
let data = object, subpath = path.split('.');
153154

154155
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)
157161
return;
158162
}
159163

160-
return jsonData;
164+
return data;
161165
} catch (error) {
162-
console.log("Error in getValueFromObject", error);
166+
console.error("Error in getValueFromObject:", error);
167+
// throw error;
163168
}
164169
}
165170

@@ -594,9 +599,10 @@
594599

595600
function isMatch(data, query) {
596601
for (let key of Object.keys(query)) {
602+
// if (!data.hasOwnProperty(key))
603+
// return false
604+
597605
let dataValue = getValueFromObject(data, key)
598-
if (!dataValue)
599-
return false
600606

601607
if (typeof query[key] === 'string' || typeof query[key] === 'number' || typeof query[key] === 'boolean') {
602608
if (Array.isArray(dataValue))

0 commit comments

Comments
 (0)