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

another-typescript-validator

v1.0.12

Published

Another Typescript Validator

Readme

Another Typescript Validator

This package let's you easily create schemas to validate JSON data and automatically convert schemas into types, so that you can avoid repetition and the problems that derive from it, and consequently ship faster.

Installation

Simply install the package by running

npm i another-typescript-validator

Usage and main features

Create complex schemas in minutes

import {object, array, number, string, boolean, toType, validate} from  'another-typescript-validator'

const  ItemSchema  =  object({
    id: string().uuid_v4().toUpperCase(),
    
    name: string().trim().min(3).max(100),
    
    description: string().trim().max(1000),
    
    visible: boolean(),
    
    stock: number().integer().natural().max(10000),
    
    price: number().integer().positive().max(10000)
    
}).required('id', 'price')

Convert schemas to types in one line

type  Item  =  toType<typeof  ItemSchema>

/* This is equivalent to:
 * 
 * type  Item  = {  
 *    id:  string;  
 *    name:  string;  
 *    description:  string;  
 *    visible:  boolean;  
 *    stock:  number;  
 *    price:  number;  
 * }
 */

*note optional types are not yet supported

Validate raw JSON faster than light

const  data  = {
    id: "f18ef195-7956-4f74-b02c-e1c23226d25d",    
    name: "Super awesome 4k TV",
    description: " I could use a trim ",
    visible: true,
    stock: 10,
    price: 1000,
    unwantedProperty: "nobody likes me"
}

const  television  =  validate(data, ItemSchema)

console.log(television)

/* Output:
*  object {
*	  id: 'F18EF195-7956-4F74-B02C-E1C23226D25D',
*	  name: 'Super awesome 4k TV',
*	  description: 'I could use a trim',
*	  visible: true,
*	  stock: 10,
*	  price: 1000
*	}
*/

This module takes an efficiency before complexity approach. Fast but complex algorithms are more welcomed than easy to understand but slower ones. Though still making the outside user experience super simple. In other words, complex on the inside but easy from the outside. This is often considered bad practice, but I don't care and I am cheap. I don't wanna pay any extra pennies for my serverless functions due to laziness.

Nest objects and arrays as much as you want, it just works.

const  CatalogSchema  =  object({
    categories: array(object({
	    name: string().min(3).max(100),
	    items: array(ItemSchema).min(10)
    })).min(1)
})

type  Catalog  =  toType<typeof  CatalogSchema>

/* Equivalent to:
* 
* type  Catalog  = {  
*    categories: {  
* 	    name:  string;  
* 	    items: {  
* 		    id:  string;  
* 		    name:  string;  
* 		    description:  string;  
* 		    visible:  boolean;  
* 		    stock:  number;  
* 		    price:  number;  
* 	    }[];  
*    }[];  
* }
*/
	

Perform complex maps directly from the schema

number().add(10).mod(2).sin().times(100)

string().repeat(3).trim().slice(2, 3).toUpperCase()

The majority of the Math and String class methods are already supported. However, for now it is only possible to map between the same type, i.e. numbers can only be mapped to other numbers, strings can only be mapped to other strings and so on.

Contributing

If you like this package, please consider contributing. This module is still in its early stages.

The top priorities are:

  • Proper documentation for all functions
  • Proper testing
  • Support for optional properties

Addition of new features is also appreciated. For example things I'd like to see implemented are:

  • efficient support for multiple types in arrays, i.e. array(number(), string()) would validate an array of type Array<number | string>
  • Possibility to map between different types e.g. a string to an array of strings.
  • More support for custom filters and mappings, i.e. letting the end user easily specify custom filters and mappings.

When contributing, keep in mind our efficiency before complexity approach.