website/node_modules/is2/README.md

is2

is2 is a type-checking module for node.js to test values. Is does not throw exceptions and every function only returns true or false. Use is2 to validate types in your node.js code. Every function in is2 returns either true of false.

After finding Enrico Marino's module is, the concise syntax amazed, but there were syntax issues that made using is difficult. This fork of is fixes those issues, but the module is no longer cross-platform. Also, added tests via mocha which can be run using 'npm test'.

Installation

To install is2, type:

$ npm install is2

Usage

var is = require('is2');

console.log('true is equal to 1===1: '+(is.equal(true, 1===1));
console.log('10 is a positive number: '+(is.positiveNumber(10));
console.log('11 is an odd number: '+(is.oddNumber(11));

API

type(value, type)

Test if 'value' is a type of 'type'. Alias: a

Params:
Returns:

defined(value)

Test if 'value' is defined. Alias: def

Params:
Returns:

nullOrUndef(value)

Test is 'value' is either null or undefined. Alias: nullOrUndef

Params:
Returns:

empty(value)

Test if 'value' is empty. To be empty means to be an array, object or string with nothing contained.

Params:
Returns:

objEquals(value, other)

Do a deep comparision of two objects for equality. Will recurse without any limits. Meant to be called by equal only.

Params:
Returns:

equal(value, other)

Test if 'value' is equal to 'other'. Works for objects and arrays and will do deep comparisions, using recursion. Alias: eq

Params:
Returns:

NON_HOST_TYPES

JS Type definitions which cannot host values.

hosted(value, host)

Test if 'key' in host is an object. To be hosted means host[value] is an object.

Params:
Returns:

instanceOf(value)

Test if 'value' is an instance of 'constructor'. Aliases: instOf, instanceof

Params:
Returns:

buffer(value)

Test if 'value' is an instance of Buffer. Aliases: instOf, instanceof

Params:
Returns:

null(value)

Test if 'value' is null.

Params:
Returns:

undefined(value)

Test if 'value' is undefined. Aliases: undef, udef

Params:
Returns:

arguments(value)

Test if 'value' is an arguments object. Alias: args

Params:
Returns:

emptyArguments(value)

Test if 'value' is an arguments object that is empty. Alias: args

Params:
Returns:

array(value)

Test if 'value' is an array. Alias: ary, arry

Params:
Returns:

nonEmptyArray(value)

Test if 'value' is an array containing at least 1 entry. Aliases: nonEmptyArry, nonEmptyAry

Params:
Returns:

nonEmptyArray(value)

Test if 'value' is an array containing no entries. Aliases: emptyArry, emptyAry

Params:
Returns:

empty(value)

Test if 'value' is an empty array(like) object. Aliases: arguents.empty, args.empty, ary.empty, arry.empty

Params:
Returns:

arrayLike(value)

Test if 'value' is an arraylike object (i.e. it has a length property with a valid value) Aliases: arraylike, arryLike, aryLike

Params:
Returns:

boolean(value)

Test if 'value' is a boolean. Alias: bool

Params:
Returns:

false(value)

Test if 'value' is false.

Params:
Returns:

true(value)

Test if 'value' is true.

Params:
Returns:

date(value)

Test if 'value' is a date.

Params:
Returns:

error(value)

Test if 'value' is an error object. Alias: err

Params:
Returns:

function(value)

Test if 'value' is a function. Alias: func

Params:
Returns:

number(value)

Test if 'value' is a number. Alias: num

Params:
Returns:

positiveNumber(value)

Test if 'value' is a positive number. Alias: positiveNum, posNum

Params:
Returns:

negativeNumber(value)

Test if 'value' is a negative number. Aliases: negNum, negativeNum

Params:
Returns:

decimal(value)

Test if 'value' is a decimal number. Aliases: decimalNumber, decNum

Params:
Returns:

divisibleBy(value, n)

Test if 'value' is divisible by 'n'. Alias: divisBy

Params:
Returns:

int(value)

Test if 'value' is an integer. Alias: integer

Params:
Returns:

positiveInt(value)

Test if 'value' is a positive integer. Alias: posInt

Params:
Returns:

negativeInt(value)

Test if 'value' is a negative integer. Aliases: negInt, negativeInteger

Params:
Returns:

maximum(value, others)

Test if 'value' is greater than 'others' values. Alias: max

Params:
Returns:

minimum(value, others)

Test if 'value' is less than 'others' values. Alias: min

Params:
Returns:

nan(value)

is.nan Test if value is not a number.

Params:
Returns:

even(value)

Test if 'value' is an even number.

Params:
Returns:

odd(value)

Test if 'value' is an odd number.

Params:
Returns:

ge(value, other)

Test if 'value' is greater than or equal to 'other'. Aliases: greaterOrEq, greaterOrEqual

Params:
Returns:

gt(value, other)

Test if 'value' is greater than 'other'. Aliases: greaterThan

Params:
Returns:

le(value, other)

Test if 'value' is less than or equal to 'other'. Alias: lessThanOrEq, lessThanOrEqual

Params:
Returns:

lt(value, other)

Test if 'value' is less than 'other'. Alias: lessThan

Params:
Returns:

within(value, start, finish)

Test if 'value' is within 'start' and 'finish'. Alias: withIn

Params:
Returns:

object(value)

Test if 'value' is an object. Note: Arrays, RegExps, Date, Error, etc all return false. Alias: obj

Params:
Returns:

nonEmptyObject(value)

Test if 'value' is an object with properties. Note: Arrays are objects. Alias: nonEmptyObj

Params:
Returns:

objectInstanceof(objInst, objType)

Test if 'value' is an instance type objType. Aliases: objInstOf, objectinstanceof, instOf, instanceOf

Params:
Returns:

regexp(value)

Test if 'value' is a regular expression. Alias: regexp

Params:
Returns:

string(value)

Test if 'value' is a string. Alias: str

Params:
Returns:

emptyString(value)

Test if 'value' is an empty string. Alias: emptyStr

Params:
Returns:

nonEmptyString(value)

Test if 'value' is a non-empty string. Alias: nonEmptyStr

Params:
Returns:

emailAddress(value)

Test if value is a valid email address. We're testing only the email address not the user name with an email address, edmond@stdarg.com and not "Edmond Meinfelder" edmond@stdarg.com. The email address does not need a fully qualified host, but does expect an '@host', so 'edmond' is false but 'edmond@stdarg' is true. Aliases: email, emailAddr

Params:
Returns:

ipv4Address(value)

Test if a value is a valid IPv4 numeric address. Non-routable IPv4 address are still valid addresses. This function expects 4 octets separated by '.' with valid values of 0-255 inclusive. Aliases: ipv4, ipv4Addr

Params:
Returns:

ipv6Address(value)

Test if a value is a valid IPv6 numeric address. Aliases: ipv6, ipv6Addr

Params:
Returns:

ipAddress(value)

Test if a value is a valid IPv6 or IPv4 numeric address. Aliases: ip, ipAddr

Params:
Returns:

dnsAddress(value)

Test if a value is a valid DNS address. Aliases: dns, dnsAddr

Params:
Returns:

hostAddress(value)

Test if a value is a valid IPv4, ipv6 or DNS address. Aliases: hostIp, hostAddr

Params:
Returns:

port(value)

Test if a value is a valid TCP/IP port number.

Params:
Returns:

License

The MIT License (MIT)

Copyright (c) 2013 Edmond Meinfelder

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.



JohnCoene/chirp documentation built on May 25, 2021, 6:33 p.m.