Install & Compatibility
Where this runs
No compatibility data collected yet for this library.
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
test
✓ import { test } from 'json-criteria'
✗ const test = require('json-criteria').test
ESM import works in Node.js with type:module or bundler; CommonJS require also supported.
filter
✓ import { filter } from 'json-criteria'
Also exported as a named function; can be used with ESM or CJS.
jsonCriteria
✓ import jsonCriteria from 'json-criteria'
✗ import * as jsonCriteria from 'json-criteria'
Default export is not documented; prefer named exports for clarity.
JC
✓ const JC = require('json-criteria')
✗ import JC from 'json-criteria'
CommonJS style returns an object with test and filter methods; ESM default is not the same object.
Shows import, test, filter usage with MongoDB-style operators including $gt, $gte, $in, $and.
import { test, filter } from 'json-criteria';
// Test a single object against a criteria
const obj = { name: 'Alice', age: 30 };
const criteria = { age: { $gt: 25 } };
console.log(test(obj, criteria)); // true
// Filter an array of objects
const items = [
{ name: 'Alice', price: 10 },
{ name: 'Bob', price: 5 },
{ name: 'Charlie', price: 15 }
];
const filtered = filter(items, { price: { $gte: 10 } });
console.log(filtered); // [{ name: 'Alice', price: 10 }, { name: 'Charlie', price: 15 }]
// Complex query with $and
const complexCriteria = {
$and: [
{ age: { $gte: 18 } },
{ status: { $in: ['active', 'pending'] } }
]
};
const user = { age: 25, status: 'active' };
console.log(test(user, complexCriteria)); // true
Errors
Common errors & fixes
TypeError: jsonCriteria.test is not a function
Using default import when the default export is an object, but named imports are different.
fixUse named import: import { test } from 'json-criteria' ReferenceError: require is not defined in ES module scope
Using require() in an ESM context without proper configuration.
fixSwitch to import statements or use createRequire.
Error: $where requires a function
Passing a string to $where instead of a function.
fixUse a function: { $where: function(v) { return v > 0; } } Audit
Dependencies
No dependency data recorded yet.