![Oracle Drags Its Feet in the JavaScript Trademark Dispute](https://cdn.sanity.io/images/cgdhsj6q/production/919c3b22c24f93884c548d60cbb338e819ff2435-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
json-rules-engine-schema-operator
Advanced tools
An operator for json-rules-engine to evaluate a value against a JSON schema
It's an operator to evaluate a value against a JSON Schema for the totally awesome json-rules-engine package.
Because a JSON Schema is a predicate. A value either validates against a schema, or it doesn't. Rather than writing (and maintaining) a bunch of custom operators and bloating your codebase with them, you only need one operator - a schema operator.
npm install json-rules-engine-schema-operator
# or
yarn add json-rules-engine-schema-operator
This package is BYOV - bring your own validator (highly recommend AJV!!)
import Ajv from 'ajv';
import { Engine } from 'json-rules-engine';
import createSchemaOperator from 'json-rules-engine-schema-operator';
const ajv = new Ajv();
const validator = (subject,schema) => ajv.validate(schema,subject);
const engine = new Engine();
engine.addOperator(createSchemaOperator(validator));
and now you can do this:
engine.addRule({
conditions: {
any: [
{
fact: 'firstName',
operator: 'schema',
value: {
type: 'string',
pattern: '^J',
},
},
],
},
event: {
type: 'j_firstName',
},
});
By default, the name of the operator added to the engine is schema
. This is configurable by passing in a custom name via the second optional parameter options
:
const name = 'jsonSchemaOperator';
engine.addOperator(validator, { name });
engine.addRule({
conditions: {
any: [
{
fact: 'firstName',
operator: name,
value: {
type: 'string',
pattern: '^J',
},
},
],
},
event: {
type: 'j_firstName',
},
});
I ❤️ JSON schema and json-rules-engine both so much, that I created a package json-schema-rules-engine that works very similarly, but it relies entirely on JSON schemas for predicates (or "operators"), which greatly simplifies the concept of the rules engine.
FAQs
An operator for json-rules-engine to evaluate a value against a JSON schema
The npm package json-rules-engine-schema-operator receives a total of 3 weekly downloads. As such, json-rules-engine-schema-operator popularity was classified as not popular.
We found that json-rules-engine-schema-operator demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.