1.2.1 • Published 7 years ago

strova-validation v1.2.1

Weekly downloads
2
License
MIT
Repository
github
Last release
7 years ago

strova-validation

Validation library for common use cases like notNull, notEmpty, min, max, ... Intention of this library is to support user entry validation and to support strova-assert that supports Defensive programming.

FunctionDescription
isNull(arg)returns true when argument is null or undefined
notNull(arg)negated isNull(arg)
isBlank(arg)for string only: returns true when argument is null, undefined, an empty string or string containing only white spaces.
notBlank(arg)negated isBlank(arg)
isEmpty(arg)returns true when tested argument is null or undefined, empty '' string, zero sized Array or Map, Object without properties
notEmpty(arg)negated isEmpty(arg)
isNumber(arg)true when argument is number
isInteger(arg)true when argument is integer number
max(arg, limit)true when arg is number and is less or equal to limit
min(arg, limit)true when arg is number and is greater or equal to limit

Install

npm i --save strova-validation

Example

import {notNull, isNull, notBlank, min} from 'strova-validation';

const validateUser = (firstName, middleName, lastName, age) => (
  notBlank(firstName)
  && (isNull(middleName) || notBlank(middleName))
  && notBlank(lastName)
  && (notNull(age) && min(age, 1))
);

if (!validateUser('John')) {
  console.error('User is not valid');
}

See example.spec.js for more detailed example using tests.

Build Status

1.2.1

7 years ago

1.2.0

7 years ago

1.1.0

7 years ago

1.0.5

7 years ago

1.0.4

7 years ago

1.0.2

7 years ago

1.0.3

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago