0.0.28 • Published 8 years ago
valjs v0.0.28
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';
0.0.28
8 years ago
0.0.27
8 years ago
0.0.26
8 years ago
0.0.25
8 years ago
0.0.24
8 years ago
0.0.23
8 years ago
0.0.22
8 years ago
0.0.21
8 years ago
0.0.20
8 years ago
0.0.18
8 years ago
0.0.17
8 years ago
0.0.16
8 years ago
0.0.15
8 years ago
0.0.14
8 years ago
0.0.13
8 years ago
0.0.12
8 years ago
0.0.11
8 years ago
0.0.10
8 years ago
0.0.9
8 years ago
0.0.8
8 years ago
0.0.7
8 years ago
0.0.6
8 years ago
0.0.5
8 years ago
0.0.4
8 years ago
0.0.3
8 years ago
0.0.2
8 years ago
0.0.1
8 years ago