🚨 Shai-Hulud Strikes Again:834 Packages Compromised.Technical Analysis →
Socket
Book a DemoInstallSign in
Socket

klay-core

Package Overview
Dependencies
Maintainers
1
Versions
30
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

klay-core

Isomorphic and extensible validation library for JavaScript.

latest
Source
npmnpm
Version
2.4.0
Version published
Maintainers
1
Created
Source

klay

NPM Package Build Status Coverage Status Commitizen friendly Dependencies

Isomorphic and extensible validation library for JavaScript.

API Documentation

Usage

Install

npm install --save klay-core

Validate

const klay = require('klay-core').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 klay = require('klay-core').defaultModelContext

klay.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(),
  })

Keywords

validation

FAQs

Package last updated on 15 Mar 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts