Package Exports
- @ncardez/is
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@ncardez/is) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
is
A data type checker and validator for node (typescript compatible).
- Installation
- Test
- API
- is.object
- is.null
- is.undefined
- is.number
- is.array
- is.string
- is.boolean
- is.uuid
- is.integer
- is.float
- is.positive
- is.negative
- is.zero
- is.between
- is.alpha
- is.digit
- is.function
- is.asyncFunction
- is.promise
- is.empty
- is.regexp
- is.ip
- is.port
- is.date
- is.time
- is.dateTime
- is.dateISO
- is.dateInstance
- is.dateValid
- is.type
- is.error
- is.jwt
- is.jsonwebtoken - alias for
is.jwt.
- Contributors
- License
Installation
As a node.js module
$ npm install @ncardez/isAPI
const is = require('@ncardez/is');Test
npm run testobject
is.object(value: object):boolean
// Example:
expect(is.object({})).toBe(true);null
is.null(value: null):boolean
// Example:
expect(is.null(null)).toBe(true);undefined
is.undefined(value: undefined): boolean
// Example:
expect(is.undefined()).toBe(true);
expect(is.undefined(undefined)).toBe(true);number
is.number(value: number|string, parse: boolean): boolean
// Example:
expect(is.number(12)).toBe(true);
expect(is.number(-23)).toBe(true);
expect(is.number('13', true)).toBe(true);array
is.array(value: array): boolean
// Example:
expect(is.array([])).toBe(true);string
is.string(value: string): boolean
// Example:
expect(is.string('')).toBe(true);boolean
is.boolean(value: boolean|string, parse: boolean): boolean
// Example:
expect(is.boolean(true)).toBe(true);
expect(is.boolean(false)).toBe(true);
expect(is.boolean('true', true)).toBe(true);
expect(is.boolean('false', true)).toBe(true);uuid
is.uuid(value: string, version: string): booleanvalue: must be a valid UUID.
version:
'v1'|'v2'|'v3'|'v4'|'v5'
// Example:
expect(is.uuid('1b9d6bcd-bbfd-4b2d-9b5d-ab8dfbbd4bed', 'v4')).toBe(true);integer
is.integer(value: number|string): boolean
// Example:
expect(is.integer(23)).toBe(true);
expect(is.integer('43')).toBe(true);float
is.float(value: number|string): boolean
// Example:
expect(is.float(.23)).toBe(true);
expect(is.float('2.43')).toBe(true);positive
is.positive(value: number|string, parse: boolean): boolean
// Example:
expect(is.positive(23)).toBe(true);
expect(is.positive('2.43')).toBe(true);negative
is.negative(value: number|string, parse: boolean): boolean
// Example:
expect(is.negative(-23)).toBe(true);
expect(is.negative('-2.43')).toBe(true);zero
is.zero(value: number|string, parse: boolean): boolean
// Example:
expect(is.zero(0)).toBe(true);
expect(is.zero('0')).toBe(true);between
is.between(min: number|string|date, max: number|string|date, value: number|string|date, parse: boolean): boolean
// Example:
expect(is.between(0, 10, 5)).toBe(true);
expect(is.between('0', '6', '2')).toBe(true);
expect(is.between('2010-02-01', '2010-02-20', '2010-02-10')).toBe(true);
expect(is.between(new Date('2010-02-01'), new Date('2010-02-20'), new Date('2010-02-10'))).toBe(true);alpha
is.alpha(value: string): boolean
// Example:
expect(is.zero('aknd23')).toBe(true);
expect(is.zero('0ksjdn =13')).toBe(false);digit
is.digit(value: number|string): boolean
// Example
expect(is.zero('2')).toBe(true);
expect(is.zero(3)).toBe(true);function
is.function(value: function): boolean
// Example:
expect(is.function(() => {})).toBe(true);
expect(is.function(function() {})).toBe(true);asyncFunction
is.asyncFunction(value: Async Function): boolean
// Example:
expect(is.asyncFunction(async () => {})).toBe(true);
expect(is.asyncFunction(async function() {})).toBe(true);promise
is.promise(value: Promise): boolean
// Example:
expect(is.promise(Promise.resolve(2))).toBe(true);empty
is.empty(value: string|array|object|function): boolean
// Example:
expect(is.promise('')).toBe(true);
expect(is.promise([])).toBe(true);
expect(is.promise({})).toBe(true);
expect(is.promise(() => {})).toBe(true);
expect(is.promise(function () {})).toBe(true);regexp
is.regexp(value: RegExp): boolean
// Example:
expect(is.regexp(/\d/)).toBe(true);ip
is.ip(value: string): boolean
// Example:
expect(is.ip('192.168.0.1')).toBe(true);port
is.port(value: number): boolean
// Example:
expect(is.port(8080)).toBe(true);date
is.date(value: string): boolean
// Example:
expect(is.date('2010-02-03')).toBe(true);time
is.time(value: string): boolean
// Example:
expect(is.time('03:20:14')).toBe(true);dateTime
is.dateTime(value: string): boolean
// Example:
expect(is.dateTime('2010-02-03 03:20:14')).toBe(true);dateISO
is.dateISO(value: string): boolean
// Example:
expect(is.dateISO('2010-02-03 03:20:14.290z')).toBe(true);
expect(is.dateISO('2010-02-03 03:20:14')).toBe(true);
expect(is.dateISO('2010-02-03T03:20:14')).toBe(true);
expect(is.dateISO('2010-02-03 03:20:14.290Z')).toBe(true);
expect(is.dateISO('2018-02-11T02:10:14.210Z')).toBe(true);dateInstance
is.dateInstance(value: Date): boolean
// Example:
expect(is.dateInstance(new Date())).toBe(true);
expect(is.dateInstance(new Date('2018-02-11T02:10:14.210Z'))).toBe(true);dateValid
is.dateValid(value: Date): boolean
// Example:
expect(is.dateValid('2010-02-03')).toBe(true);
expect(is.dateValid('2010-02-03 11:11:11')).toBe(true);
expect(is.dateValid('2010-02-03 11:11:11.000Z')).toBe(true);
expect(is.dateValid('2010-02-03T11:11:11.000Z')).toBe(true);
expect(is.dateValid(new Date())).toBe(true);
expect(is.dateValid(new Date(2020, 10, 12))).toBe(true);
expect(is.dateValid(new Date('2010-02-03'))).toBe(true);type
is.type(value: function|number|boolean|object|array|null|undefined|regexp|date|string|function, parse: boolean): string
// Example:
expect(is.type).toBeFunction();
expect(is.type(3)).toEqual('number');
expect(is.type(true)).toEqual('boolean');
expect(is.type({})).toEqual('object');
expect(is.type([])).toEqual('array');
expect(is.type(null)).toEqual('null');
expect(is.type()).toEqual('undefined');
expect(is.type(undefined)).toEqual('undefined');
expect(is.type(/\d/)).toEqual('regexp');
expect(is.type(new Date())).toEqual('date');
expect(is.type('djsnfkjsndfkjn')).toEqual('string');
expect(is.type(function(){})).toEqual('function');
expect(is.type(() => {})).toEqual('function');error
is.error(value: Error): boolean
// Example:
expect(is.error(new Error('Ouch!'))).toBe(true);
expect(is.error({ stack: 'aa', message: 'sss' })).toBe(true);jwt
is.jwt(value: string): booleanis.jsonwebtoken(value: string): boolean
// Example:
const token: string = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9' +
'.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ' +
'.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c';
expect(is.jwt(token)).toBe(true);
expect(is.jsonwebtoken(token)).toBe(true);Contributors
- Norman Carcamo normancarcamo@gmail.com
License
© Norman Carcamo, Software Developer
Licensed under the MIT.