0.0.12 • Published 7 years ago

typeshape v0.0.12

Weekly downloads
1
License
MIT
Repository
-
Last release
7 years ago

Runtime type checking against composable schemas.

import { Types, OneOf, validate } from 'typeshape';

let CardSchema = {
  suit: OneOf('Spades', 'Diamonds', 'Clubs', 'Hearts'),
  value: Types.number({ '>': 0, '<': 14 })
};

validate(CardSchema, { suit: 'Spaded', value: 10 })

// {
//   valid: false,
//   reason: 'Expected one of "Spades" or "Diamonds" or "Clubs" or "Hearts" but got "Spaded"',
//   at: ['suit']
// }

Check out the demo!

Inspired by Clojure Spec, React PropTypes and JSON Blueprint.

Docs

Rationale

Many applications and tools operate with structured data that the user provides at runtime, such as data sets, configuration files and task descriptions. Normally, these data sources are well beyond the reach of compile-time type checks, so its the programmer's responsibility to build parsing/validation interfaces that receive and handle the data elegantly.

Typeshape exists to help programmers write declarative, composable runtime schemas that can be used to validate against potentially malformed data, giving the programmer the tools they need to let the user know where and why an error occurred.

0.0.12

7 years ago

0.0.11

7 years ago

0.0.10

7 years ago

0.0.9

7 years ago

0.0.8

7 years ago

0.0.7

7 years ago

0.0.6

7 years ago

0.0.5

7 years ago

0.0.4

7 years ago

0.0.3

7 years ago

0.0.1

7 years ago