ensure-is

0.1.1 • Public • Published

ensure-is

Easy to read type checking library

Examples

ensure('Fantastic').is.string() // 'Fantastic'
ensure('').is.string() // ''
ensure(4).is.string() // throws TypeError

ensure([1, 'amazing', 'array']).is.array() // [1, 'amazing', 'array']
ensure([]).is.array() // []
ensure('Hello There').is.array() // throws TypeError

Getting started

Installation

npm install ensure-is --save

Usage

const ensure = require('ensure-is')

const probably_pets = ensure(['cat', 'dog', 1, 'unicorn']).is.array();
// probably_pets = ['cat', 'dog', 1, 'unicorn']

const pets = probably_pets.map(pet => {
    return ensure(pet).is.string();
}); // Throws TypeError when pet=1

Readme

Keywords

Package Sidebar

Install

npm i ensure-is

Weekly Downloads

0

Version

0.1.1

License

MIT

Unpacked Size

2.97 kB

Total Files

4

Last publish

Collaborators

  • davlin