ists
v0.3.3
Published
Library for check any variable in javascript
Maintainers
Readme
isTs
Is Node.Js library to check any variable. This library include d.ts file for TypeScript.
Installation
Install with npm (for NodeJS):
npm install ists --saveIncompatible for browser
Usage
TypeScript exemple
import is = require('ists')
var checkString = is.string.length.equal(5)
checkString("abcde") // trueJavaScript exemple
var is = require('ists')
var checkString = is.string.length.equal(5)
checkString("abcde") // trueExemples
Test an array
var checkArray = is.array.each(is.number)
checkArray([3, 18, 5]) // true
checkArray(["3", 18, 5]) // falseAnd/Or/Not
var checkString = is.string.in.list("Hello", "Allo", "Ola", "Bonjour").and.not.in.array(["Bonjour", "Allo"])
checkString("Hello") // true
checkString("miaou") // false
checkString("Bonjour") // falseTest an Object
var checkObject = is.object.with.properties({
a: is.string,
b: is.number.inf(100).or(is.undefined) // is optional
})
checkObject({ a: "hello", b: 20 }) // true
checkObject({ a: "I love javascript" }) // true
checkObject({ b: 40 }) // false
checkObject({ a: 32, b: 40 }) // false
checkObject({ a: 32, b: 40 }) // falseTest Array of Object
var checkObject = is.object.with.properties({
a: is.string,
b: is.number.inf(100).or(is.undefined) // is optional
})
var checkArray = is.array.each(checkObject)
checkArray([
{ a: "hello" },
{ a: "toto", b: 78 },
{ a: "youhou", b: 18 }
]) // true