🚨 Shai-Hulud Strikes Again:834 Packages Compromised.Technical Analysis →
Socket
Book a DemoInstallSign in
Socket

@rain-cafe/validify

Package Overview
Dependencies
Maintainers
2
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@rain-cafe/validify

An incredibly simple object validation library

latest
Source
npmnpm
Version
1.4.4
Version published
Maintainers
2
Created
Source

@rain-cafe/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 '@rain-cafe/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

FAQs

Package last updated on 23 Feb 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts