@ribbon-studios/validify
TypeScript icon, indicating that this package has built-in type declarations

1.4.5 • Public • Published

@ribbon-studios/validify

NPM Version NPM Downloads Coveralls

CI Build Maintainability Semantic Release Code Style: Prettier

An incredibly simple object validation library

Usage

import { Validator, isDefined, isAlpha } from '@ribbon-studios/validify';

type MyCustomType = {
  name: string;
  version: string;

  i18n: {
    en: {
      hello: string;
    };
  };

  users: Array<{
    first: string;
    last: string;
  }>;
};

const validator = new Validator<MyCustomType>({
  name: [isDefined, isAlpha],

  i18n: {
    en: {
      hello: [isDefined, isAlphaNumeric],
    },
  },

  users: {
    first: [isDefined, isAlpha],
    last: [isDefined, isAlpha],
  },
});

const myObject = {
  name: 'App',
  version: '1.0.0',

  i18n: {
    en: {
      hello: 'world',
    },
  },

  users: [
    {
      first: 'Cecilia',
      last: 'Sanare',
    },
  ],
};

const errors = validator.check(myObject); // returns a list of all the validator failure reasons
validator.validate(myObject); // throws an error containing all of the validator failure reasons
validator.isValid(myObject); // returns true if the object passes all of the validators
validator.isInvalid(myObject); // returns true if the object fails any of the validators

Readme

Keywords

none

Package Sidebar

Install

npm i @ribbon-studios/validify

Weekly Downloads

1

Version

1.4.5

License

MIT

Unpacked Size

153 kB

Total Files

20

Last publish

Collaborators

  • cozybot
  • cecilia-sanare