@bernierllc/nevar-operator-registry
v0.1.0
Published
Operator registry with 12 built-in operators for the Nevar rules engine
Readme
@bernierllc/nevar-operator-registry
Operator registry with 12 built-in operators for the Nevar rules engine.
Installation
npm install @bernierllc/nevar-operator-registryUsage
import { OperatorRegistry } from '@bernierllc/nevar-operator-registry';
const registry = new OperatorRegistry();
// All 12 built-in operators are pre-registered
registry.evaluate('eq', 'hello', 'hello'); // true
registry.evaluate('gt', 10, 5); // true
registry.evaluate('in', 'a', ['a', 'b']); // true
registry.evaluate('is_true', true, null); // true
// List all operators
const operators = registry.list();
// Filter by category
const comparisons = registry.getByCategory('comparison');
// Register custom operators
registry.register('starts_with', {
label: 'Starts With',
category: 'string',
evaluate: (field, target) => String(field).startsWith(String(target)),
schema: z.string(),
fieldTypes: ['string'],
});Built-in Operators
| Operator | Category | Description | |----------|----------|-------------| | eq | comparison | Equal to | | neq | comparison | Not equal to | | gt | comparison | Greater than | | gte | comparison | Greater than or equal | | lt | comparison | Less than | | lte | comparison | Less than or equal | | in | membership | Value is in array | | not_in | membership | Value is not in array | | contains | membership | Array/string contains value | | not_contains | membership | Array/string does not contain value | | is_true | boolean | Value is truthy | | is_false | boolean | Value is falsy |
API
OperatorRegistry
Registry for managing built-in and custom operators. All 12 built-in operators are pre-registered on construction.
Constructor: new OperatorRegistry()
register(name, definition)- Registers a custom operator. ThrowsNevarValidationErrorif the name is already registeredget(name)- Returns theOperatorDefinitionfor the given name, orundefinedhas(name)- Returnstrueif the operator is registeredlist()- Returns all operators as serializableOperatorInfo[](without evaluate functions)getByCategory(category)- Returns operators filtered by categoryevaluate(name, fieldValue, targetValue)- Evaluates a field value against a target using the named operator. ThrowsNevarEvaluationErrorfor unknown operators
builtInOperators
Exported map of the 12 built-in operator definitions, useful for inspection or testing.
Integration Documentation
Logger Integration
This package does not integrate with @bernierllc/logger. As a core package, logger integration is optional and not included by default. Consumers should handle logging at the service layer.
NeverHub Integration
This package does not integrate with @bernierllc/neverhub-adapter. As a core package, NeverHub integration is not applicable. NeverHub registration should be handled by service-layer packages that compose this package.
License
Copyright (c) 2025 Bernier LLC. All rights reserved.
