The Coline App SDK: apps, tools, file types and surfaces that run inside Coline workspaces, and public websites with Coline Sites. TypeScript, with an in-memory test workspace. MIT.
| 3 | if (!where || typeof where !== "object") return true; |
| 4 | return Object.entries(where).every(([key, condition]) => { |
| 5 | const value = data[key]; |
| 6 | if (condition === null || typeof condition !== "object") return value === condition; |
| 7 | return Object.entries(condition).every(([operator, expected]) => { |
| 8 | if (operator === "eq") return value === expected; |
| 9 | if (operator === "contains") |
| 10 | return ( |
| 11 | typeof value === "string" && |
| 12 | typeof expected === "string" && |
| 13 | value.toLowerCase().includes(expected.toLowerCase()) |
| 14 | ); |
| 15 | if ( |
| 16 | typeof value !== typeof expected || |
| 17 | (typeof value !== "string" && typeof value !== "number") |
| 18 | ) |
| 19 | return false; |
| 20 | const comparison = |
| 21 | typeof value === "number" |
| 22 | ? value - Number(expected) |
| 23 | : value.localeCompare(String(expected)); |
| 24 | if (operator === "gt") return comparison > 0; |
| 25 | if (operator === "gte") return comparison >= 0; |
| 26 | if (operator === "lt") return comparison < 0; |
| 27 | if (operator === "lte") return comparison <= 0; |
| 28 | return false; |
| 29 | }); |
| 30 | }); |
| 31 | } |
| 32 |