Skip to content

Powerful validation framework with syntax like React PropTypes.

License

Notifications You must be signed in to change notification settings

kasperpihl/valjs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

97 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

Powerful validation framework with syntax like React PropTypes.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published