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

@mochart/movalid

v1.0.1

Published

Simple yet powerful TypeScript validators

Readme

@mochart/movalid

Simple yet powerful TypeScript validators with chainable extensions and human-readable error messages.

Every validator is a factory: calling validators.number() returns a plain predicate function (value) => boolean that also carries metadata — errorMessage, getErrorMessage(value), allowedValues, rangeValues, nestedValues, and isEnum — so callers can both check values and report readable errors. @mochart/core uses it for config validation.

Usage

import validators from '@mochart/movalid';

const isRenderer = validators.oneOf(['bar', 'line', 'area']).orEqual(undefined);

isRenderer('bar');        // true
isRenderer('pie');        // false
isRenderer.errorMessage;  // 'should be one of [ "bar", "line", "area" ] or be equal to undefined'
isRenderer.getErrorMessage('pie');
// 'should be one of [ "bar", "line", "area" ] or be equal to undefined: "pie"'

Validators

All are called as validators.name(...args):

  • Types — boolean, number, string, array, object, any
  • Custom types — numeric, integer, color (hex/rgb/rgba), dateInstance (a valid Date object), dateISO (iso date string), datePrimitive (iso date string or epoch number), dateAny (any of the three)
  • Instances — instanceOf(Class), typeOf('object'), custom(fn) (give fn a message property)
  • Ranges — numberMin/Max/MinMax, numericMin/Max/MinMax, integerMin/Max/MinMax
  • Strings — regexp(re) (a number is stringified and matched too), stringRegexp(re) (text only), stringWithLength(n), stringWithLengthMin/Max/MinMax
  • Values — equal(v), oneOf([...]), oneIn({...}), notEqual(v), notOneOf([...]), notOneIn({...})
  • Arrays — arrayWithLength(n), arrayWithLengthMin/Max/MinMax, arrayOf(validator, allowEmpty)
  • Objects — objectWith(properties, validator), objectWithSome(properties, validator), objectWithShape({ prop: validator, … }, allowExtraProperties), partialObjectWithShape({ prop: validator, … }, allowExtraProperties) (only the properties actually present have to pass, so it is the one to use for optional config objects)
  • Combinators — or([...validators]), and([...validators]), not(validator)
  • Conditional — validators.conditional(rules, object) picks the first rule whose condition(object) matches and uses its validator. A rule's optional suffix is appended to that validator's message, so it can say when the rule applies (should be a number when type is a). When no rule matches, the result rejects every value and its errorMessage is every rule's message joined with or (no conditional rule matched for an empty rule list)

The bare type predicates are also exported directly for convenience:

import { typeValidators, customTypeValidators } from '@mochart/movalid';
typeValidators.string('hi'); // true

TypeScript types are exported as well: Validator (the predicate-with-metadata shape returned by every factory), Validators, CustomValidator, ConditionalRule, and RangeValues.

Chainable extensions

Every validator can be extended, conditional included. Each extension returns a new validator that can be extended in turn:

  • .orEqual(value) / .orOneOf([...]) / .or(otherValidator) — widen what passes and extend the error message
  • .withMessage(msg) / .appendMessage(msg) / .prependMessage(msg) — override or decorate the error message without changing behavior
  • .withCustomName(name) — set the customName metadata field, leaving both behavior and error message unchanged
const size = validators.numberMin(0).orEqual('auto').withMessage('should be a size');

Development

npm test -w @mochart/movalid

License

MIT

The development export condition

In this repository's manifest, the exports map has a development entry pointing at this package's TypeScript sources; the repo's own dev servers, tests and tsx scripts run the library from source through it. It never reaches npm: publishing goes through pnpm publish, which replaces the map with the dist-only publishConfig.exports, so installed copies of this package always resolve the built dist/.