mirror of
https://github.com/nvms/prsm.git
synced 2025-12-19 01:10:52 +00:00
28 lines
677 B
TypeScript
28 lines
677 B
TypeScript
import dot from "dot-wild";
|
|
import { ensureArray, isObject, Ok } from "../../utils";
|
|
|
|
export function $fn(source: object, query: object): boolean {
|
|
let match = undefined;
|
|
|
|
if (isObject(query)) {
|
|
Ok(query).forEach((k) => {
|
|
if (isObject(query[k])) {
|
|
const targetValue = dot.get(source, k);
|
|
if (targetValue === undefined) return;
|
|
|
|
Ok(query[k]).forEach((j) => {
|
|
if (j === "$fn") {
|
|
match = true;
|
|
ensureArray(query[k][j]).forEach((fn) => {
|
|
if (!fn(targetValue)) match = false;
|
|
});
|
|
}
|
|
});
|
|
}
|
|
});
|
|
}
|
|
|
|
if (match !== undefined) return match;
|
|
|
|
return false;
|
|
} |