MCPcopy Index your code
hub / github.com/parse-community/parse-server / objectContainsKeyValue

Method objectContainsKeyValue

src/Utils.js:407–433  ·  view source on GitHub ↗

* Deep-scans an object for a matching key/value definition. * @param {Object} obj The object to scan. * @param {String | undefined} key The key to match, or undefined if only the value should be matched. * @param {any | undefined} value The value to match, or undefined if only the key shoul

(obj, key, value)

Source from the content-addressed store, hash-verified

405 * @returns {Boolean} True if a match was found, false otherwise.
406 */
407 static objectContainsKeyValue(obj, key, value) {
408 const isMatch = (a, b) => (typeof a === 'string' && new RegExp(b).test(a)) || a === b;
409 const isKeyMatch = k => isMatch(k, key);
410 const isValueMatch = v => isMatch(v, value);
411 const stack = [obj];
412 const seen = new WeakSet();
413 while (stack.length > 0) {
414 const current = stack.pop();
415 if (seen.has(current)) {
416 continue;
417 }
418 seen.add(current);
419 for (const [k, v] of Object.entries(current)) {
420 if (key !== undefined && value === undefined && isKeyMatch(k)) {
421 return true;
422 } else if (key === undefined && value !== undefined && isValueMatch(v)) {
423 return true;
424 } else if (key !== undefined && value !== undefined && isKeyMatch(k) && isValueMatch(v)) {
425 return true;
426 }
427 if (['[object Object]', '[object Array]'].includes(Object.prototype.toString.call(v))) {
428 stack.push(v);
429 }
430 }
431 }
432 return false;
433 }
434
435 static checkProhibitedKeywords(config, data) {
436 if (config?.requestKeywordDenylist) {

Callers 3

Calls

no outgoing calls

Tested by

no test coverage detected