Registry / testing / check-compiler

check-compiler

JSON →
library1.4.0jsnpmunverified

A TypeScript-first schema rule compiler and validation library that compiles declarative rule objects into efficient validation functions. Current stable version is 1.4.0 (released 2023). It has zero dependencies, supports both Node.js (>=16) and browsers, and is very small (minified+gzipped). Unlike runtime validation libraries like zod or yup, check-compiler provides a compiled check function for each schema, making repeated validation fast. It uses a type-driven rule definition with custom messages and supports nested objects, nullable values, and pattern validation. Ships TypeScript types.

npm install check-compiler
INSTALL
IMPORT
SIG · CHECK-COMPILER
C
check-compiler
testingjavascriptv1.4.0
harness data pending
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.

compile
import { compile } from 'check-compiler'
Main function to compile a rule object into a check function. ESM only; CommonJS not supported.
Rule
import { Rule } from 'check-compiler'
Type for defining a validation rule. Must be used with generic parameter, e.g., Rule<string>.
Check
import { Check } from 'check-compiler'
Type for the compiled check function signature: (input: T, violations: Violation[]) => void.
Violation
import { Violation } from 'check-compiler'
Interface describing a validation violation: location, message, reason, args.

Creates a string rule with min, max, and pattern, compiles it, and validates two inputs, showing violation details.

import { compile, Rule, Violation } from 'check-compiler'; const nameRule: Rule<string> = { type: 'string', min: 2, max: 50, pattern: /^[a-zA-Z ]+$/, messages: { 'string pattern': 'Only letters and spaces allowed.', }, }; const checkName = compile(nameRule); const violations: Violation[] = []; checkName('John Doe', violations); console.log(violations); // [] checkName('J', violations); // violates min console.log(violations[0].message); // The value must be at least 2 characters.
Debug
Known issues
gotchaNullable fields require explicit nullable: true in the rule; otherwise null values cause violations.
fix
Set nullable: true on the rule object when null is allowed.
affects: >=1.0.0
gotchaCustom messages must use the same key as the built-in reason (e.g., 'string pattern', 'number range'). Incorrect keys are ignored.
fix
Use the exact reason string as the key in the messages object (e.g., 'string pattern' for pattern violations).
affects: >=1.0.0
deprecatedCalling compile() multiple times for the same rule is discouraged; compile once and reuse the check function.
fix
Store compiled check functions and reuse them.
affects: >=1.0.0
gotchaUnknown rule types (e.g., 'boolean', 'date') are not supported and will cause compilation errors.
fix
Use only supported types: 'string', 'number', 'object'. For others, consider custom validation.
affects: >=1.0.0
Errors
Common errors & fixes
Type 'number' has no properties in common with type 'Rule<unknown>'.
Using a plain number/string where a Rule object is expected.
fix
Define a rule object: e.g., { type: 'number', min: 0 } instead of just 0.
Cannot use namespace 'Check' as a type.
Importing Check incorrectly (e.g., `import { Check as CheckType }` instead of `import { Check }`).
fix
Use `import { Check } from 'check-compiler'` directly.
TS2345: Argument of type 'string' is not assignable to parameter of type 'never'.
Passing a value of mismatched type to a compiled check function.
fix
Ensure the input argument matches the generic type used in compile<T>().
Error: Unknown rule type: 'boolean'.
Attempting to use an unsupported rule type like 'boolean' or 'date'.
fix
Switch to a supported type ('string', 'number', 'object') or implement custom validation.
Upgrade
Version history
1.4.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
15 hits · last 30 days
node
12
Bingbot
1
OpenAI (training)
1
Resources
check-compiler — npm install check-compiler · libregistry