truthjs

1.1.0 • Public • Published

truthjs

Maintainability Test Coverage

truthjs is a javascript validator library for:

  • Number
  • Array (future support)
  • Boolean (future support)
  • Email (future support)
  • Network (future support)
  • Object (future support)
  • String (future support)

truthjs was implemented by functional approach by creating validator composable.

truthjs uses recent ES features. It is tested on stable Node. If you need to support legacy browsers consider using a transpiler with polyfills.

Installation

truthjs can be installed using npm.

npm install --save truthjs

For the complete code including all tests the repo can be cloned.

git clone https://github.com/hoangtranson/truejs.git
cd truejs
npm run test

Getting Started

The truthjs function composes the validator to a single validator function. The validator are run in order, if one returns false the following functions will not be run.

In this example the age:

  • Must be a number.
  • Must be a integer.
  • Must between 1 and 100.
const truth = require("truthjs");
const { isNumber, isInteger, between } = require("truthjs/number");
const ageValidator = truth(isNumber(), isInteger(), between(1, 100));

ageValidator(5);
ageValidator(-10);
ageValidator(1.0);

/truthjs/

    Package Sidebar

    Install

    npm i truthjs

    Weekly Downloads

    2

    Version

    1.1.0

    License

    MIT

    Unpacked Size

    12.4 kB

    Total Files

    9

    Last publish

    Collaborators

    • hayden.tran.d