@alidatorjs/is-falsy
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

is-falsy

Tiny function, compatible with Alidator.js, to validate if a value is falsy.

Install

You can use npm or yarn to install it.

$ npm install --save @alidatorjs/is-falsy

$ yarn add @alidatorjs/is-falsy

Then with a module bundler like rollup or webpack, use as you would anything else:

// using ES6 modules
import { isFalsy } from '@alidatorjs/is-falsy'

// using CommonJS modules
var { isFalsy } = require('@alidatorjs/is-falsy')

Usage

Is as easy as define an array with the validations.

import { validator } from '@alidatorjs/validator';
import { isFalsy } from '@alidatorjs/is-falsy';

const isValid = validator([
    isFalsy(false),
    isFalsy(null),
    isFalsy(undefined),
    isFalsy(0),
    isFalsy(NaN),
    isFalsy(''),
]).every; // true

const errors = validator([
    [isFalsy(false), () => 'message'],
    [isFalsy(true), () => 'Error 1'],
    [isFalsy('tralala'), () => 'Error 2'],
    [isFalsy(0), () => 'message'],
    [isFalsy(NaN), () => 'message'],
]).errors, // ['Error 1', 'Error 2']

License

MIT License

Package Sidebar

Install

npm i @alidatorjs/is-falsy

Weekly Downloads

1

Version

1.0.0

License

MIT

Unpacked Size

3.76 kB

Total Files

12

Last publish

Collaborators

  • gc-victor