@arianee/required
v0.9.0
Published
A simple node boilerplate for Arianee
Downloads
237
Keywords
Readme
Required
A simple tool to check type of variable in function. Easy to read and easy to use!
0 dependencies!
Getting started
npm i @arianee/required
Example
required
import {
required,
requiredDefined,
requiredNullOrUndefined,
requiredType }
from '@arianee/required';
function MyFunc (num) {
required(num > 0, 'arg must be true');
return arg;
}
MyFunc(1) // does not throw
MyFunc(0) // throw
MyFunc() // throw
requiredDefined
requiredDefined(undefined, 'should be a defined') // throw
requiredDefined(null, 'should be a defined') // throw
requiredDefined('foo', 'should be a defined')
requiredDefined([], 'should be a defined')
requiredType
requiredType('{}', 'string', 'should be a string')
requiredType([], 'array', 'should be an array')
requiredType({}, 'object', 'should be an object')
requiredType([], 'object', 'should be an object')
requiredType(22, 'number', 'should be an object')
requiredNullOrUndefined
requiredNullOrUndefined(undefined, 'should be a undefined')
requiredNullOrUndefined(null, 'should be a undefined')
requiredNullOrUndefined('foo', 'should be a defined') // throw
requiredNullOrUndefined([], 'should be a defined')// throw