npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

json-rule-engine-csv

v1.0.0

Published

Compile CSV-managed business rules into a fast JSON validation and repair engine

Readme

json-rule-engine-csv

Compile business-managed CSV rules once, then reuse an immutable schema for fast JSON validation, repair, skeleton generation, and missing-field detection.

Install

npm install json-rule-engine-csv

Node.js 18.18 or newer is required.

Quick start

import { createEngine } from "json-rule-engine-csv";

const csvContent = `Key,Type,Required,Regex,ConditionExpression,AllowedValues,DefaultValue,MinItems
userId,number,true
email,email,true,,!userId
status,string,true,,,"ACTIVE,INACTIVE",ACTIVE
addresses[],array,true,,,,,1
addresses[].city,string,true`;

const engine = createEngine({ csvContent });
const result = engine.isValid({
  userId: 42,
  status: "ACTIVE",
  addresses: [{ city: "Pune" }],
});

For files:

import { createEngineFromFile } from "json-rule-engine-csv";

const engine = await createEngineFromFile({ csvFile: "./schema.csv" });

Compiler-first design

SchemaCompiler validates every schema concern at startup and emits frozen, execution-ready rules. Invalid paths, defaults, regexes, references, cycles, and array hierarchies fail before requests are accepted.

import { SchemaCompiler, Engine } from "json-rule-engine-csv";

const schema = new SchemaCompiler().compileCsv(csvContent);
const engine = new Engine(schema);

Repair

const { nextValidJson, logs } = engine.nextValidJson(input);

Repair deep-clones input, applies defaults, creates missing parents, and uses null for required values without defaults. It never deletes fields or overwrites existing non-null values. Arrays receive generated items only when MinItems explicitly requires them.

Conditions

Supported operators are !, ==, !=, >, <, >=, <=, &&, ||, and IN. Expressions are tokenized and parsed into an AST; JavaScript evaluation functions are never used.

contact.email,email,true,,!userId
state,string,true,,"country == ""IN"""
status,string,true,,"status IN [""ACTIVE"",""PENDING""]"

Custom validators and types

const engine = createEngine({
  csvContent,
  customTypeValidators: {
    money: (value) => Number.isFinite(value) && value >= 0,
  },
});

engine.registerValidator("panValidator", (value, context) => {
  return /^[A-Z]{5}[0-9]{4}[A-Z]$/.test(value) || "Invalid PAN";
});

Custom validator names are declared in the CSV Validator column.

Configuration

createEngine({
  csvContent,
  allowUnknownFields: true,
  warnUnknownFields: true,
  treatEmptyStringAsMissing: true,
  nullMode: "strict", // strict | allow | default
  coercion: "strict", // strict | permissive
});

See API.md and ARCHITECTURE.md.