0.1.1 • Published 3 years ago

ensure-is v0.1.1

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

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