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 🙏

© 2025 – Pkg Stats / Ryan Hefner

sontaran

v2.0.2

Published

Javascript number, string, boolean, object validator

Readme

Sontaran

Build Status Coverage Status

Sontaran is a javascript validator library. It has a lot validation options out of the box and all validators are extendable with custom validation functions.

Some key features

  • Completely written in Typescript
  • CommonJS build for Node JS
  • Tree shakable ES build
  • Fluid, chainable api
  • Support for async validators with the validateAsync method

Installation

Sontaran can be installed using npm.

npm install --save sontaran

For the complete code including all tests the repo can be cloned.

git clone https://github.com/Barry127/sontaran.git
cd sontaran
npm run test

Getting Started

The object().schema() function takes a schema of Sontaran validators as an argument.

In this example:

username

  • Must be a string
  • Cannot be only empty characters (spaces, tabs, return, ...)
  • Must have a length between 3 and 10 characters
  • Must match the given RegExp (only contain alphanumeric characters and dash, underscore)

email

  • Must be a valid email

password

  • Must be a string
  • Must have a length of at least 8 characters
import { object, string, email } from 'sontaran';

const schema = object().schema({
  username: string()
    .notEmpty()
    .between(3, 10)
    .match(/^[a-zA-Z0-9_\-]*$/),
  email: email(),
  password: string().min(8)
});

// Valid schema (return true)
schema.validate({
  username: 'sontaran',
  email: '[email protected]',
  password: 'mySuperSecretPassword'
}); /** => {
  valid: true,
  value: {
    username: 'sontaran',
    email: '[email protected]',
    password: 'mySuperSecretPassword
  }
}*/

// invalid usernames
let a = 123; // => not a string
let b = ' \t\r'; // => Empty characters
let c = 'aa'; // => too short
let d = 'Hello-World'; // => too long
let e = 'B@dInput'; // => invalid character

Sontarans custom can take any ValidatorFunction function as argument to validate and / or transform a value.

import { string, ValidationError } from 'sontaran';

// value cannot be root and is transformed to lowercase
const myCustomValidator = (value) => {
  if (value.toLocaleLowercase() === 'root') {
    throw new ValidationError('root is not allowed');
  }

  return value.toLocaleLowercase();
};

const schema = string().custom(myCustomValidator);

// valid result transformed to lowercase
const result = schema.label('username').validate('Admin');
/* => {
  valid: true,
  value: 'admin'
}*/

// invalid result
const result = schema.label('username').validate('Root');
/* => {
  valid: false,
  value: 'Root',
  errors: [{
    field: 'username',
    message: 'root is not allowed',
    type: 'root is not allowed'
  }]
}
*/