UNPKG

1.97 kBMarkdownView Raw
1zan
2===
3
4[![NPM version][npm-image]][npm-url]
5[![Build status][travis-image]][travis-url]
6[![Test coverage][coveralls-image]][coveralls-url]
7[![Downloads][downloads-image]][downloads-url]
8
9Drop in replacement for `React.PropTypes`:
10
11```js
12import { types } from 'zan';
13const { string, number } = types;
14React.createClass({
15 propTypes: {
16 name: string,
17 age: number.isOptional
18 },
19 render() {
20 // ...
21 },
22});
23```
24
25The primary differences this has with `React.PropTypes` is that
26
271. `zan` exposes an `exactShape` type.
282. checks by default are `isRequired` already and they each expose an `isOptional` method
293. `zan` exposes a `createCustomChecker` method which can be used as follows:
30
31```js
32const urlString = createCustomChecker(value => /^https?:/.test(value) );
33```
34
35
36This module also exposes an a checker so you can check types manually without React
37
38### Usage
39
40```js
41import { check, types, createCustomChecker } from 'zan';
42
43check(types.bool, true); // null
44check(types.bool, 123); // returns Error object
45
46check(types.shape({name: types.string}), {name: 'Me'}); // null
47check(types.shape({name: types.string}), {}); // returns Error object
48check(types.shape({name: types.string}), {name: 'Me', age: 22}); // null
49check(types.exactShape({name: types.string}), {name: 'Me', age: 22}); // returns Error object
50```
51
52`check` is curry-able so `const numberChecker = check(types.number); numberChecker(22);` works
53
54
55see [test.js](test.js) from more usage
56
57
58[npm-image]: https://img.shields.io/npm/v/zan.svg?style=flat-square
59[npm-url]: https://npmjs.org/package/zan
60[travis-image]: https://img.shields.io/travis/kolodny/zan.svg?style=flat-square
61[travis-url]: https://travis-ci.org/kolodny/zan
62[coveralls-image]: https://img.shields.io/coveralls/kolodny/zan.svg?style=flat-square
63[coveralls-url]: https://coveralls.io/r/kolodny/zan
64[downloads-image]: http://img.shields.io/npm/dm/zan.svg?style=flat-square
65[downloads-url]: https://npmjs.org/package/zan