Checkers allow users to validate data with simple functions
const { checker } = require('@herbsjs/suma')
function sampleFunc () {}
const ret = checker.isFunction(sampleFunc)
console.log(ret)
/* Output: true */
const { checker } = require('@herbsjs/suma')
const samples = [
null,
undefined,
''
]
for (const value of samples) {
const ret = checker.isDefined(value)
console.log(ret)
}
/* Output: false, false, true */
const { checker } = require('@herbsjs/suma')
const value = ['a', 'b', 'c']
const ret = checker.isArray(value)
console.log(ret)
/* Output: true */
const { checker } = require('@herbsjs/suma')
const value = [{ name: 'jhon', age: 35},{ name: 'marie', age: 29}]
const ret = checker.isIterable(value)
console.log(ret)
/* Output: true */
const { checker } = require('@herbsjs/suma')
const value = 'herbs validators'
const ret = checker.isString(value)
console.log(ret)
/* Output: true */
const { checker } = require('@herbsjs/suma')
const value = false
const ret = checker.isBoolean(value)
console.log(ret)
/* Output: true */
const { checker } = require('@herbsjs/suma')
const value = 152
const ret = checker.isNumber(value)
console.log(ret)
/* Output: true */
const { checker } = require('@herbsjs/suma')
const value = new Date(1900, 5, 1)
const ret = checker.isDate(value)
console.log(ret)
/* Output: true */
const { checker } = require('@herbsjs/suma')
const value = /^[0-9]{8}$/
const ret = checker.isRegExp(value)
console.log(ret)
/* Output: true */
const { checker } = require('@herbsjs/suma')
class CustomClass {}
const value = new CustomClass()
const ret = checker.isInstanceOf(value, CustomClass)
console.log(ret)
/* Output: true */
const { checker } = require('@herbsjs/suma')
class SampleClass {}
const samples = [
{},
new Object(),
new SampleClass(),
[],
'herbs',
true
]
for (const value of samples) {
const ret = checker.isObject(value)
console.log(ret)
}
/* Output: true, true, true, true, false, false */
const { checker } = require('@herbsjs/suma')
const samples = [
'',
' ',
[],
{},
'herbs',
22
]
for (const value of samples) {
const ret = checker.isEmpty(value)
console.log(ret)
}
/* Output: true, true, true, true, false, false */
const { checker } = require('@herbsjs/suma')
const value = 45125
const ret = checker.isValidFormat(value, /^[0-9]{8}$/)
console.log(ret)
/* Output: true */
const { checker } = require('@herbsjs/suma')
const value = '[email protected]'
const ret = checker.isValidEmail(value)
console.log(ret)
/* Output: true */
const { checker } = require('@herbsjs/suma')
const value = 'http://herbsjs.org'
const ret = checker.isValidURL(value)
console.log(ret)
/* Output: true */
const { checker } = require('@herbsjs/suma')
const value = 'herbs'
const ret = checker.isValidJavascriptIdentifier(value)
console.log(ret)
/* Output: true */
const { checker } = require('@herbsjs/suma')
const value = 'herbs'
const ret = checker.isTooShort(value, 3)
console.log(ret)
/* Output: true */
const { checker } = require('@herbsjs/suma')
const value = 'herbs'
const ret = checker.isTooLong(value, 10)
console.log(ret)
/* Output: true */
const { checker } = require('@herbsjs/suma')
const value = 'herbs'
const ret = checker.isWrongLength(value, 5)
console.log(ret)
/* Output: true */
const { checker } = require('@herbsjs/suma')
const ret = checker.isEqualTo(1520, 1520)
console.log(ret)
/* Output: true */
const { checker } = require('@herbsjs/suma')
const ret = checker.isGreaterThan(100, 50)
console.log(ret)
/* Output: true */
const { checker } = require('@herbsjs/suma')
const ret = checker.isGreaterThanOrEqualTo(100, 100)
console.log(ret)
/* Output: true */
const { checker } = require('@herbsjs/suma')
const ret = checker.isLessThan(50, 100)
console.log(ret)
/* Output: true */
const { checker } = require('@herbsjs/suma')
const ret = checker.isLessThanOrEqualTo(100, 100)
console.log(ret)
/* Output: true */
const { checker } = require('@herbsjs/suma')
const ret = checker.isInteger(10)
console.log(ret)
/* Output: true */
const { checker } = require('@herbsjs/suma')
const ret = checker.isBeforeThan(new Date(1900, 2, 1), new Date(1991, 2, 1))
console.log(ret)
/* Output: true */
const { checker } = require('@herbsjs/suma')
const ret = checker.isBeforeThan(new Date(1991, 2, 1), new Date(1900, 2, 1))
console.log(ret)
/* Output: true */
const { checker } = require('@herbsjs/suma')
const ret = checker.isAt(new Date(1991, 2, 1), new Date(1991, 2, 1))
console.log(ret)
/* Output: true */
const { checker } = require('@herbsjs/suma')
const values = ['apple', 'orange']
const ret = checker.isAt(values, 'orange')
console.log(ret)
/* Output: true */