DEV Community

Sachin Dilshan
Sachin Dilshan

Posted on

Stop the Bloat: Introducing lite-schema-check, the Zero-Dependency Runtime Validator You Didn't Know You Needed

Hello DEV Community!

I've just released a minimal, zero-dependency NPM package called lite-schema-check and I think it directly addresses a common pattern in the JavaScript ecosystem.

We all know the moment: we need to check if a simple object—a configuration file, an options parameter, or a JSON payload—has the right keys and types. The common choices are either writing verbose, custom type checks or pulling in a huge dependency like Zod or Joi.

lite-schema-check is the ultimate minimalist solution, built for Node.js microservices and lightweight libraries where every kilobyte counts.

What is it and Why is it "Lite"?

This utility exports a single, pure function: validate(object, schema).

It performs the minimum viable validation: it only checks for key presence and primitive type matching. It validates for string, number, boolean, array, and object.

The core philosophy is minimalism over complex data modeling. It doesn't do nested validation, unions, or transforms—that's what the bigger libraries are for. It exists to solve the 80% case: ensuring a flat config object or API input meets its basic primitive contract. And crucially, it does this with zero external dependencies.

🎯 Use Case: Fail Fast on External Data
This tool is perfect for asserting data integrity when dealing with inputs that TypeScript can't guarantee at compile time (like API responses or environment variables).

Imagine validating a module's configuration object:

TypeScript

// Define the expected contract
const MODULE_CONFIG_SCHEMA = {
  apiKey: 'string',
  port: 'number',
  useCache: 'boolean',
};

// Check the incoming data
const options = getExternalConfig(); 

const result = validate(options, MODULE_CONFIG_SCHEMA);

if (!result.isValid) {
    // Throw a clear, immediate error on initialization
    throw new Error(`Config validation failed: ${result.errors[0].message}`);
}
// Configuration is now safe and guaranteed to have the right primitives.
Enter fullscreen mode Exit fullscreen mode

If a user passes the wrong type (e.g., port: "8080"), the app fails immediately with a clear error message, saving hours of downstream debugging.

🛠️ Get Involved
This is a true MVP. I'd love your feedback, especially on:

The "Lite" Promise: What is the next most critical, simple feature that could be added without breaking the zero-dependency promise?

Missing Primitives: Should we add types like 'function' or 'symbol'?

Check out the GitHub repo and help us keep the utility ultra-light!

➡️ GitHub Repo: https://github.com/toozuuu/lite-schema-check

javascript #typescript #nodejs #opensource #validation

Top comments (0)