Check an object against predefined schema.
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
__tests__
src
.editorconfig
.gitignore
README.md
package-lock.json
package.json
tsconfig.json

README.md

Type-validate

Check an object against predefined schema.

Installation

Using npm:

npm i -S type-validate

Using yarn:

yarn add type-validate

Example

Sample typings definition:

const typings = {
  name: 'string',
  age: 'number',
  height: 'number?',
  isDeveloper: 'boolean',
  birthDate: 'date|number',
  address: {
    country: 'string?',
    city: 'string',
  },
  posts: [{
    title: 'string'
  }, true],
}

Supported types

  • primitive types - string, number, boolean, date, and undefined
  • optional types, defined with ?, like string?
  • union types, defined with |, like string|number
  • array types, defined as [arrayItemType, isOptional]