0.0.28 • Published 7 years ago

valjs v0.0.28

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

Installation

npm install --save valjs

Simple example

Let's validate if a string is minimum 5 chars.

import { string } from 'valjs';

let error = string.min(5).test('hello')
// passes! (null)

Badass example

Let's validate this

const todo = {
  id: 'todo-1',
  title: 'Ship Login Page',
  updatedAt: '2017-01-21T22:54:45Z',
  state: 'completed',
  assignees: [
    'user-1'
  ],
  subtasks: [
    { title: 'Design' },
    { title: 'Develop' },
    { title: 'QA' }
  ]
}

Like this

import { object, string, array, any } from 'valjs';

const error = object.as({
  id: string.require(),
  title: string.require().min(1).max(255),
  updatedAt: string.format('iso8601'),
  state: any.of('active', 'completed'),
  assignees: array.require().of(string.min(6).startsWith('user-')),
  subtasks: array.of(object.as({
    title: string.require().min(1).max(60)
  }))
}).test(todo);
// passes!

Here are all the supported types

import valjs, {
  string,
  number,
  bool,
  func,
  object,
  array,
  date,
  any
} from 'valjs';

string API

number API

bool API

func API

object API

array API

date API

any API

0.0.28

7 years ago

0.0.27

7 years ago

0.0.26

7 years ago

0.0.25

7 years ago

0.0.24

7 years ago

0.0.23

7 years ago

0.0.22

7 years ago

0.0.21

7 years ago

0.0.20

7 years ago

0.0.18

7 years ago

0.0.17

7 years ago

0.0.16

7 years ago

0.0.15

7 years ago

0.0.14

7 years ago

0.0.13

7 years ago

0.0.12

7 years ago

0.0.11

7 years ago

0.0.10

7 years ago

0.0.9

7 years ago

0.0.8

7 years ago

0.0.7

7 years ago

0.0.6

7 years ago

0.0.5

7 years ago

0.0.4

7 years ago

0.0.3

7 years ago

0.0.2

7 years ago

0.0.1

7 years ago