@showwhat/core
v2.0.0
Published
Core rule engine and schemas for showwhat library
Maintainers
Readme
@showwhat/core
Low-level schemas, parsers, and rule engine for showwhat.
Use @showwhat/core when you want the evaluation primitives without the higher-level convenience API.
Installation
npm install @showwhat/coreQuick start
import { MemoryData, resolve, builtinEvaluators } from "@showwhat/core";
const data = await MemoryData.fromObject({
definitions: {
checkout_v2: {
variations: [{ value: true, conditions: [{ type: "env", value: "prod" }] }, { value: false }],
},
},
});
const def = await data.get("checkout_v2");
const result = await resolve({
definitions: { checkout_v2: def! },
context: { env: "prod" },
options: { evaluators: builtinEvaluators },
});
console.log(result.checkout_v2.value); // trueNote: The resolver is strict — evaluators must be passed explicitly. There is no default evaluator set injected automatically.
Features
- Built-in condition types:
string,number,datetime,bool,env,startAt,endAt - Composite conditions with
and/orlogic - Custom condition types via evaluator composition
- YAML and JSON parsing with schema validation
- Pluggable data sources (
DefinitionReader/DefinitionWriter) - Typed error hierarchy
- Preset condition shortcuts
Documentation
- Quick Start — installation and first definition
- Conditions — built-in condition types and usage
- Context — runtime context object
- Definitions — definition structure and variations
- Core API —
showwhat(),resolve(), parsing, and more - Errors — error types and when they are thrown
- Custom Conditions — writing your own evaluators
- Custom Data Sources — implementing
DefinitionReader - MemoryData — in-memory data source
