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

ur-validator

v0.0.2

Published

JavaScript and TypeScript validation library

Readme

ur-validator

ur-validator is a lightweight and flexible JavaScript/TypeScript library designed for data validation. It draws inspiration from popular JavaScript libraries, incorporating their best practices while adding unique enhancements. The library provides robust functionality to validate, cast, and clean data, ensuring it meets specified criteria.

Key Features

  • Validation: Validate data against predefined schemas to ensure it meets the required format and constraints.
  • Casting: Automatically cast data to the specified type, making it easier to work with different data formats.
  • Cleaning: Remove unnecessary data from objects, keeping only the relevant fields as defined by the schema.
  • Schema-based: Define schemas for various data types including strings, numbers, booleans, arrays, and objects.
  • Customizable: Easily extend and customize validation rules to fit specific use cases.

Сontents

Installation

npm install ur-validator

Connection

import uv from 'ur-validator'; // uv includes object, array, string, number, boolean schemas
// or
import { uv } from 'ur-validator';
// or
import { object, array, string, number, boolean } from 'ur-validator';

Usage examples

First, we need to generate a schema, then we can validate the data.

import { array, boolean, number, object, string } from 'ur-validator';

string().minLength(4).validate('example text'); // { valid: true, value: 'example text', error: ''}
nubmer().min(5).max(100).isValid(22); // true
boolean().cast(1); // true (will cast true and 1 to true and false and 0 to false if strict mode is not enabled)

const objectData = object()
  .required()
  .entries({
    stringData: string().required('custom required message'),
    numberData: number().min(20),
    booleanData: boolean().isTrue(),
    arrayData: array().of(string().minLength(2)),
    objectData: object().required(),
  });

objectData.validate({
  stringData: 'string data',
  numberData: 50,
  booleanData: true,
  arrayData: ['text1', 'text2', 'text3'],
  objectData: { name: 'John', age: 25 },
}); // { valid: true, value: {...}, error: ''}

const arrayData = array().of(number());

arrayData.validate([123, '124', 125]); // { valid: true, value: [123, 124, 125], error: ''}

Schemas

uv

import uv from 'ur-validator';
// or
import { uv } from 'ur-validator';

uv.array();
uv.boolean();
uv.number();
uv.object();
uv.string();

string

validate()

import { string } from 'ur-validator';

string().validate('valid text'); // { valid: true, value: 'valid text', error: '' }
string().validate(''); // { valid: true, value: '', error: '' }
string().validate(12345); // { valid: true, value: '12345', error: '' }
string().validate(true); // { valid: false, value: true, error: 'expected string value' }

isValid()

import { string } from 'ur-validator';

string().isValid('valid text'); // true
string().isValid(12345); // true
string().isValid(true); // false

cast()

import { string } from 'ur-validator';

string().cast('valid text'); // 'valid text'
string().cast(12345); // '12345'
string().cast(true); // TypeError: expected string value

strict()

import { string } from 'ur-validator';

string().strict().validate('valid text'); // { valid: true, value: 'valid text', error: '' }
string().strict().validate(12345); // { valid: false, value: 12345, error: 'expected string value' }

required()

import { string } from 'ur-validator';

string().required().validate('valid text'); // { valid: true, value: 'valid text', error: '' }
string().required().validate(''); // { valid: false, value: '', error: 'required field' }
string().required().required().validate(undefined); // { valid: false, value: undefined, error: 'required field' }
string().required().required().validate(null); // { valid: false, value: null, error: 'required field' }

notRequired()

import { string } from 'ur-validator';

string().notRequired().validate(undefined); // { valid: true, value: undefined, error: '' }
string().required().notRequired().validate(undefined); // { valid: true, value: undefined, error: '' }

length()

import { string } from 'ur-validator';

string().length(4).validate('text'); // { valid: true, value: 'text', error: '' }
string().length(4).validate(''); // { valid: true, value: '', error: '' }
string().length(4).validate('long text'); // { valid: true, value: 'long text', error: 'field length must be 4 characters' }
string().length(40).validate('short text'); // { valid: false, value: 'short text', error: 'field length must be 40 characters' }

Documentation

For detailed documentation and more examples, visit the GitHub repository.

License

This project is licensed under the ISC License. See the LICENSE file for more details.