GitXplorerGitXplorer
l

easy-vac

public
3 stars
0 forks
2 issues

Commits

List of commits on branch master.
Verified
f8c527f13c7337e12795476bdd24baed5a36eee6

Merge pull request #1 from lyonbot/dependabot/npm_and_yarn/acorn-6.4.1

llyonbot committed 5 years ago
Verified
ecb22fa9682dedd7459be6d4e28c2e1d928f82b6

Bump acorn from 6.1.1 to 6.4.1

ddependabot[bot] committed 5 years ago
Unverified
0a61e97f56ef7ffa6048f324757890fe1a2ca929

VTuple: support optional items; add tests.

llyonbot committed 6 years ago
Unverified
ebdb64a0aed8ebd0602e666d32b6839768e7ed86

fix: terser ruins __esModule

llyonbot committed 6 years ago
Unverified
d66f1876114aaf6a49f3e02baba7147de9b52763

add "any" type

llyonbot committed 6 years ago
Unverified
c117e1045947ba4017be7ac6fb190fafcdaa7218

VEnum: ignoreCase & trim options ...

llyonbot committed 6 years ago

README

The README file for this repository.

easy-vac

Build Status npm npm bundle size npm type definitions NPM License

[ GitHub | Home | Playground | Documentation | Examples ]

easy-vac is a JavaScript library which helps you validate and clean data.

  • Better than JSON Schema: get rid of JSON limits, define schemas in JavaScript style
  • Auto Type Inferrence: works perfectly with TypeScript
  • Type Tolerance: may convert values to correct type
  • Highly Extensible: define your own types and reuse them everywhere

Install

easy-vac can be installed via:

Example (more...)

import { VObject, VArray, VEnum, VTuple, VACError } from "easy-vac"

const OrderItem = VObject({
  product: { type: "string", required: true },
  count:   { type: "int",    default: 1, minimum: 1 },
})

const Order = VObject.required({
  guest:  { type: String },           // <- type can also be "string"
  items:  { type: VArray({ items: { type: OrderItem },
                           minItems: 1,
                           maxItems: 3 })
          }
})

var incoming = {
  _id: "xxxxx",
  guest: 12345,
  items: [
    { product: "Ice Cream" },
    { product: "Toast", count: 3 },
  ]
}

var order = Order.vac(incoming) // <-- throws VACError if failed
console.log(order)

Output:

{
  "guest": "12345",
  "items": [
    { "product": "Ice Cream", "count": 1 },
    { "product": "Toast", "count": 3 }
  ]
}