propable

0.5.1 • Public • Published

Propable wercker status

A collection of prop types that can be used for checking and parsing values.

API Reference

Installing / Getting Started

Install the package

npm install --save propable

and import/require it

import { propTypes } from 'propable';
// OR (pre ES6)
var propTypes = require('propable').propTypes;

Usage

const v = '2';
typeof v; // 'string'
 
propTypes.number.test(v); // true
propTypes.number.parse(v); // 2
typeof propTypes.number.parse(v); // 'number'
 
propTypes.array.test(v); // false
propTypes.array.parse(v); // undefined

You can also define custom prop types using the PropType class:

import PropType from 'propable/proptype';
 
const boolProp = new PropType(
  'myBOOL', // unique type id
  (v) => !!// parser (returns the parsed value or throws an error)
);
 
boolProp.test(0); // true
boolProp.parse(0); // false

Developing

This is what you do after you have cloned the repository:

npm install
npm run build

(Install dependencies & build the project.)

Linting

Execute ESLint

npm run lint

Try to automatically fix linting errors

npm run lint:fix

Testing

Execute Jest unit tests using

npm test

Tests are defined in the same directory the module lives in. They are specified in '[module].test.js' files.

Building

To build the project, execute

npm run build

This saves the production ready code into 'dist/'.

Package Sidebar

Install

npm i propable

Weekly Downloads

0

Version

0.5.1

License

BSD-3-Clause

Last publish

Collaborators

  • mlpxbrachmann