2.4.0 • Published 7 years ago

klay v2.4.0

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

klay

NPM Package Build Status Coverage Status

Isomorphic and extensible validation library for JavaScript.

API Documentation

Usage

Install

npm install --save klay

Validate

const klay = require('klay').defaultModelContext

const myModel = klay
  .object()
  .children({
    firstName: klay.string().required(),
    lastName: klay.string().required(),
    email: klay.email().required(),
    age: klay.integer(),
  })
  .strict()

const results = myModel.validate({
  firstName: 'John',
  lastName: 42,
  email: 'invalid.com',
  age: 'eleven',
})

console.log(results.toJSON())
{ value:
   { firstName: 'John',
     lastName: '42',
     email: 'invalid.com',
     age: 'eleven' },
  conforms: false,
  errors:
   [ { message: 'expected value (invalid.com) to be email',
       path: ['email'] },
     { message: 'expected value (eleven) to have typeof number',
       path: ['age'] } ] }

Extend

const {ModelContext} = require('klay')

const klay = ModelContext.create().use({
  types: ['custom-type'],
  defaults: {required: true, strict: true},
})

const myModel = klay.object().children({
  firstName: klay.string(), // required by default
  lastName: klay.string(), // required by default
  email: klay.email(), // required by default
  age: klay.integer().optional(),
  custom: klay.customType(),
})
3.0.0-alpha.5

7 years ago

3.0.0-alpha.4

8 years ago

3.0.0-alpha.3

8 years ago

3.0.0-alpha.2

8 years ago

3.0.0-alpha.1

8 years ago

2.5.1-alpha.0

8 years ago

3.0.0-alpha.0

8 years ago

0.0.2-alpha.0

8 years ago

2.4.0

8 years ago

2.3.1

8 years ago

2.3.0

8 years ago

2.2.1

8 years ago

2.2.0

8 years ago

2.1.0

8 years ago

2.0.1

8 years ago

2.0.0

8 years ago

1.3.0

9 years ago

1.2.4

9 years ago

1.2.3

9 years ago

1.2.2

10 years ago

1.2.1

10 years ago

1.2.0

10 years ago

1.1.0

10 years ago

1.0.3

10 years ago

1.0.2

10 years ago

1.0.1

10 years ago

1.0.0

10 years ago