# klay

> Isomorphic and extensible validation library for JavaScript.

Latest version **2.4.0** (published 2018-02-13) · MIT license · 0 weekly downloads

## Install

```sh
npm install klay
pnpm add klay
yarn add klay
bun add klay
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.4.0 |
| Published | 2018-02-13 |
| First published | 2016-08-02 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 1.3 MB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | Patrick Hulce |
| Maintainers | patrickhulce |
| Keywords | validation |

## Links

- npm: https://www.npmjs.com/package/klay
- Repository: https://github.com/patrickhulce/klay
- Homepage: https://github.com/patrickhulce/klay#readme
- Issues: https://github.com/patrickhulce/klay/issues
- npm.io page: https://npm.io/package/klay

## Dependencies (2)

- [lodash](https://npm.io/package/lodash.md) ^4.14.93
- [@types/lodash](https://npm.io/package/@types/lodash.md) ^4.14.93

## Alternatives

- [@sindresorhus/slugify](https://npm.io/package/@sindresorhus/slugify.md) — 3.7M weekly downloads
- [solid-js](https://npm.io/package/solid-js.md) — 2.7M weekly downloads
- [expo-glass-effect](https://npm.io/package/expo-glass-effect.md) — 2.5M weekly downloads
- [nanoassert](https://npm.io/package/nanoassert.md) — 780.8K weekly downloads
- [@ffmpeg/ffmpeg](https://npm.io/package/@ffmpeg/ffmpeg.md) — 529.5K weekly downloads

## Recent versions

- 2.4.0 (latest) — 2018-02-13
- 3.0.0-alpha.5 (next) — 2018-10-18
- 3.0.0-alpha.4 — 2018-07-23
- 3.0.0-alpha.3 — 2018-07-23
- 3.0.0-alpha.2 — 2018-07-23
- 3.0.0-alpha.1 — 2018-07-16
- 2.5.1-alpha.0 — 2018-07-16
- 3.0.0-alpha.0 — 2018-07-15
- 0.0.2-alpha.0 — 2018-07-15
- 2.5.0-alpha.e0b12f0f — 2018-07-08
- 2.5.0-alpha.3633f6c7 — 2018-07-08
- 2.5.0-alpha.b2f33c5b — 2018-07-08
- 2.5.0-alpha.086b6020 — 2018-06-22
- 2.5.0-alpha.0c051183 — 2018-06-15
- 2.5.0-alpha.69977c6c — 2018-06-15
- … 35 more at https://npm.io/package/klay/versions

## README

# klay
[![NPM Package](https://badge.fury.io/js/klay.svg)](https://www.npmjs.com/package/klay)
[![Build Status](https://travis-ci.org/patrickhulce/klay.svg?branch=master)](https://travis-ci.org/patrickhulce/klay)
[![Coverage Status](https://coveralls.io/repos/github/patrickhulce/klay/badge.svg?branch=master)](https://coveralls.io/github/patrickhulce/klay?branch=master)
[![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg)](http://commitizen.github.io/cz-cli/)
[![Dependencies](https://david-dm.org/patrickhulce/klay.svg)](https://david-dm.org/patrickhulce/klay)

Isomorphic and extensible validation library for JavaScript.

## [API Documentation](https://patrickhulce.github.io/klay/)

## Usage

### Install

`npm install --save klay`

### Validate

```js
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())
```

```js
{ 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

```js
const klay = require('klay').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(),
  })
```

---
_Source: https://npm.io/package/klay · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
