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

tadashii

v2.3.0

Published

Easy & functional way to validate a model against a schema

Readme

tadashii

import { validated, isValid } from 'tadashii';

Introduction

The API is quite trivial. There are two concepts: schemas and models.

Models

A model is just a plain javascript object with your data to be validated.

const user = {
    first_name: "Kasper",
    last_name: "Janebrink",
};

Schema

A schema quite simply describes the structure of your model and how its validated. Additionally for each validator an error message for when a validation failed should be supplied. We do not provide standard error messages.

const userSchema = {
    first_name: [
        ["isRequired", "Please provide a first name"],
        ["minLength", 1, "Please provide a name longer than one character"],
    ],
    email: [
        ["isEmail", "Please provide a valid email"],
    ],
};

Schema + model

Combining your schema and model we're able to get answers to these questions:

  1. Is your model valid according to the schema?
  2. What are the error messages for each attribute?

Example

import { validate, isValid, firstError, isAttributeValid } from 'tadashi';

const schema = {
    first_name: [
        ["minLength", 2, "First name must be at least two characters long"]
    ],
    email: [
        ["isEmail", "Email is not in a valid format"]
    ],
};

const model = {
    first_name:  "K",
    email: "kasper@woof"
};

isValid(schema, model);  // => false
validate(schema, model); // =>
/*
    {
        first_name: ["First name must be at least two characters long"],
        email: ["Email is not in a valid format"],
    }
 */
firstError(schema, model); // ["first_name", "First name must be at least two characters long"]
firstErrors(schema, model); // {first_name: "first_error", last_name: "last_error"}
isAttributeValid(schema, model, 'first_name'); // => false

Custom validators

To provide maximum flexibility you can pass a function instead of a named validation. The validators signature looks like this:

function validator(value, attribute, model, additionalArgument) {
    return true || false;
}

Any additional arguments in the schema is passed to the validator:

// This function gets two additional arguments
function customValidator(value, attribute, model, additional, argument) {
    console.log(additional + argument);
    return false;
}

const schema = {
    first_name: [
        [customValidator, "first", "second", "Custom validator error message"]
    ]
};

const model = {first_name: "Hopla"};

isValid(schema, model) # => false;
// console output: "first second"

Default error messages

I am reluctant to include any default error messages, as I've never experienced default ones that fits all bills. Rather than including defaults that 1) are not localised and 2) don't fit all UIs, I've chosen to leave them out.