Standard library assertion utilities.
var assert = require( '@stdlib/assert' );Standard library assertion utilities. The namespace contains a comprehensive suite of assertion functions, ranging from packages to test for various data types to utilities testing for system support of certain JavaScript features.
var o = assert;
// returns {...}To validate the native JavaScript data types, the following functions can be used:
isArray( value ): test if a value is an array.isBoolean( value ): test if a value is a boolean.isDateObject( value ): test if a value is a Date object.isFunction( value ): test if a value is a function.isnan( value ): test if a value is NaN.isNull( value ): test if a value is null.isNumber( value ): test if a value is a number.isObject( value ): test if a value is an object.isRegExp( value ): test if a value is a regular expression.isString( value ): test if a value is a string.isSymbol( value ): test if a value is a symbol.isUndefined( value ): test if a value is undefined.
For types that exist both as an object type and a primitive, the respective function exposes isObject and isPrimitive methods to test for the either of them.
var isBoolean = require( '@stdlib/assert/is-boolean' );
var bool = isBoolean.isObject( new Boolean( false ) );
// returns true
bool = isBoolean.isObject( false );
// returns false
bool = isBoolean.isPrimitive( false );
// returns trueMost of the assertion utilities have corresponding packages that test whether all elements of an array are of the given data type:
isArrayArray( value ): test if a value is an array of arrays.isBooleanArray( value ): test if a value is an array-like object of booleans.isFunctionArray( value ): test if a value is an array-like object containing only functions.isNaNArray( value ): test if a value is an array-like object containing only NaN values.isNullArray( value ): test if a value is an array-like object containing only null values.isNumberArray( value ): test if a value is an array-like object of numbers.isObjectArray( value ): test if a value is an array-like object containing only objects.isStringArray( value ): test if a value is an array of strings.isSymbolArray( value ): test if a value is an array-like object containing only symbols.
Similar to the functions testing for an individual element, whenever applicable above functions have methods for validating an array of primitives or objects.
var isStringArray = require( '@stdlib/assert/is-string-array' );
var bool = isStringArray( [ 'hello', 'world' ] );
// returns true
bool = isStringArray.primitives( [ 'hello', 'world' ] );
// returns true
bool = isStringArray.objects( [ 'hello', 'world' ] );
// returns false
bool = isStringArray.objects( [ new String( 'hello' ), new String( 'world' ) ] );
// returns trueThe namespace also contains functions to test for numbers in a certain range or arrays of such numbers:
isIntegerArray( value ): test if a value is an array-like object containing only integers.isInteger( value ): test if a value is a number having an integer value.isNegativeIntegerArray( value ): test if a value is an array-like object containing only negative integers.isNegativeInteger( value ): test if a value is a number having a negative integer value.isNegativeNumberArray( value ): test if a value is an array-like object containing only negative numbers.isNegativeNumber( value ): test if a value is a number having a negative value.isNonNegativeIntegerArray( value ): test if a value is an array-like object containing only nonnegative integers.isNonNegativeInteger( value ): test if a value is a number having a nonnegative integer value.isNonNegativeNumberArray( value ): test if a value is an array-like object containing only nonnegative numbers.isNonNegativeNumber( value ): test if a value is a number having a nonnegative value.isNonPositiveIntegerArray( value ): test if a value is an array-like object containing only nonpositive integers.isNonPositiveInteger( value ): test if a value is a number having a nonpositive integer value.isNonPositiveNumberArray( value ): test if a value is an array-like object containing only nonpositive numbers.isNonPositiveNumber( value ): test if a value is a number having a nonpositive value.isPositiveIntegerArray( value ): test if a value is an array-like object containing only positive integers.isPositiveInteger( value ): test if a value is a number having a positive integer value.isPositiveNumberArray( value ): test if a value is an array-like object containing only positive numbers.isPositiveNumber( value ): test if a value is a number having a positive value.isSafeIntegerArray( value ): test if a value is an array-like object containing only safe integers.isSafeInteger( value ): test if a value is a number having a safe integer value.
The namespace exposes various methods for validating typed arrays:
isFloat32Array( value ): test if a value is a Float32Array.isFloat64Array( value ): test if a value is a Float64Array.isInt16Array( value ): test if a value is an Int16Array.isInt32Array( value ): test if a value is an Int32Array.isInt8Array( value ): test if a value is an Int8Array.isUint16Array( value ): test if a value is a Uint16Array.isUint32Array( value ): test if a value is a Uint32Array.isUint8Array( value ): test if a value is a Uint8Array.isUint8ClampedArray( value ): test if a value is a Uint8ClampedArray.
It also contains functions for validating ndarrays of varying dimensions.
isCentrosymmetricMatrix( value ): test if a value is a centrosymmetric matrix.isMatrixLike( value ): test if a value is 2-dimensional ndarray-like object.isndarrayLike( value ): test if a value is ndarray-like.isNonSymmetricMatrix( value ): test if a value is a non-symmetric matrix.isPersymmetricMatrix( value ): test if a value is a persymmetric matrix.isSkewCentrosymmetricMatrix( value ): test if a value is a skew-centrosymmetric matrix.isSkewPersymmetricMatrix( value ): test if a value is a skew-persymmetric matrix.isSkewSymmetricMatrix( value ): test if a value is a skew-symmetric matrix.isSquareMatrix( value ): test if a value is a 2-dimensional ndarray-like object having equal dimensions.isSymmetricMatrix( value ): test if a value is a symmetric matrix.isVectorLike( value ): test if a value is a 1-dimensional ndarray-like object.
The namespace contains functions validating complex numbers and arrays of complex numbers:
isComplexLike( value ): test if a value is a complex number-like object.isComplexTypedArray( value ): test if a value is a complex typed array.isComplex( value ): test if a value is a 64-bit or 128-bit complex number.isComplex128( value ): test if a value is a 128-bit complex number.isComplex128Array( value ): test if a value is a Complex128Array.isComplex64( value ): test if a value is a 64-bit complex number.isComplex64Array( value ): test if a value is a Complex64Array.
In addition, the namespace contains functions validating other special arrays or buffers:
isArrayLength( value ): test if a value is a valid array length.isArrayLikeObject( value ): test if a value is an array-like object.isArrayLike( value ): test if a value is array-like.isArrayBuffer( value ): test if a value is an ArrayBuffer.isBetweenArray( value, a, b[, left, right] ): test if a value is an array-like object where every element is between two values.isCircularArray( value ): test if a value is an array containing a circular reference.isEmptyArray( value ): test if a value is an empty array.isFalsyArray( value ): test if a value is an array-like object containing only falsy values.isFiniteArray( value ): test if a value is an array-like object containing only finite numbers.isNumericArray( value ): test if a value is a numeric array.isPlainObjectArray( value ): test if a value is an array-like object containing only plain objects.isPrimitive( value ): test if a value is an array-like object containing only JavaScript primitives.isProbabilityArray( value ): test if a value is an array-like object containing only probabilities.isSharedArrayBuffer( value ): test if a value is a SharedArrayBuffer.isTruthyArray( value ): test if a value is an array-like object containing only truthy values.isTypedArrayLength( value ): test if a value is a valid typed array length.isTypedArrayLike( value ): test if a value is typed-array-like.isTypedArray( value ): test if a value is a typed array.isUnityProbabilityArray( value ): test if a value is an array of probabilities that sum to one.
To test for error objects, use any of the following functions:
isError( value ): test if a value is an Error object.isEvalError( value ): test if a value is an EvalError object.isRangeError( value ): test if a value is a RangeError object.isReferenceError( value ): test if a value is a ReferenceError object.isSyntaxError( value ): test if a value is a SyntaxError object.isTypeError( value ): test if a value is a TypeError object.isURIError( value ): test if a value is a URIError object.
The following constants are exposed to indicate the environment the current process is running on:
IS_BROWSER: check if the runtime is a web browser.IS_DARWIN: boolean indicating if the current process is running on Darwin.IS_ELECTRON_MAIN: check if the runtime is the main Electron process.IS_ELECTRON_RENDERER: check if the runtime is the Electron renderer process.IS_ELECTRON: check if the runtime is Electron.IS_LITTLE_ENDIAN: check if an environment is little endian.IS_NODE: check if the runtime is Node.js.IS_WEB_WORKER: check if the runtime is a web worker.IS_WINDOWS: boolean indicating if the current process is running on Windows.
Use the following functions to check whether a runtime environment supports a certain feature:
hasArrayBufferSupport(): detect nativeArrayBuffersupport.hasAsyncAwaitSupport(): detect nativeasync/awaitsupport.hasClassSupport(): detect nativeclasssupport.hasFloat32ArraySupport(): detect nativeFloat32Arraysupport.hasFloat64ArraySupport(): detect nativeFloat64Arraysupport.hasFunctionNameSupport(): detect native functionnamesupport.hasGeneratorSupport(): detect nativegenerator functionsupport.hasInt16ArraySupport(): detect nativeInt16Arraysupport.hasInt32ArraySupport(): detect nativeInt32Arraysupport.hasInt8ArraySupport(): detect nativeInt8Arraysupport.hasIteratorSymbolSupport(): detect nativeSymbol.iteratorsupport.hasMapSupport(): detect nativeMapsupport.hasNodeBufferSupport(): detect nativeBuffersupport.hasProxySupport(): detect nativeProxysupport.hasSetSupport(): detect nativeSetsupport.hasSharedArrayBufferSupport(): detect nativeSharedArrayBuffersupport.hasSymbolSupport(): detect nativeSymbolsupport.hasSymbolSupport(): detect nativeSymbol.toStringTagsupport.hasUint16ArraySupport(): detect nativeUint16Arraysupport.hasUint32ArraySupport(): detect nativeUint32Arraysupport.hasUint8ArraySupport(): detect nativeUint8Arraysupport.hasUint8ClampedArraySupport(): detect nativeUint8ClampedArraysupport.hasWebAssemblySupport(): detect native WebAssembly support.hasWeakMapSupport(): detect nativeWeakMapsupport.hasWeakSetSupport(): detect nativeWeakSetsupport.
The remaining functions of the assert namespace are:
contains( val, searchValue[, position] ): test if an array-like value contains a search value.deepHasOwnProp( value, path[, options] ): test whether an object contains a nested key path.deepHasProp( value, path[, options] ): test whether an object contains a nested key path, either own or inherited.hasOwnProp( value, property ): test if an object has a specified property.hasProp( value, property ): test if an object has a specified property, either own or inherited.hasPrototype( obj, prototype ): test if an object's prototype chain contains a provided prototype.instanceOf( value, constructor ): test whether a value has in its prototype chain a specified constructor as a prototype property.isAbsolutePath( value ): test if a value is an absolute path.isAlphagram( value ): test if a value is an alphagram.isAlphaNumeric( value ): test whether a string contains only alphanumeric characters.isAnagram( str, value ): test if a value is an anagram.isArguments( value ): test if a value is an arguments object.isASCII( value ): test whether a character belongs to the ASCII character set and whether this is true for all characters in a provided string.isBetween( value, a, b[, left, right] ): test if a value is between two values.isBinaryString( value ): test if a value is a binary string.isBuffer( value ): test if a value is a Buffer object.isCapitalized( value ): test if a value is a string having an uppercase first character.isCircular( value ): test if a value is a plain object containing a circular reference.isCircular( value ): test if an object-like value contains a circular reference.isCollection( value ): test if a value is a collection.isDigitString( value ): test whether a string contains only numeric digits.isEmailAddress( value ): test if a value is an email address.isEmptyObject( value ): test if a value is an empty object.isEmptyString( value ): test if a value is an empty string.isEnumerableProperty( value, property ): test if an object property is enumerable.isEven( value ): test if a value is an even number.isFalsy( value ): test if a value is falsy.isFinite( value ): test if a value is a finite number.isGeneratorObjectLike( value ): test if a value isgeneratorobject-like.isGeneratorObject( value ): test if a value is ageneratorobject.isHexString( value ): test whether a string contains only hexadecimal digits.isInfinite( value ): test if a value is an infinite number.isJSON( value ): test if a value is a parseable JSON string.isLeapYear( [value] ): test if a value corresponds to a leap year in the Gregorian calendar.isLowercase( value ): test if a value is a lowercase string.isNativeFunction( value ): test if a value is a native function.isNegativeZero( value ): test if a value is a number equal to negative zero.isNodeBuiltin( value ): test whether a string matches a Node.js built-in module name.isNodeDuplexStreamLike( value ): test if a value is Node duplex stream-like.isNodeReadableStreamLike( value ): test if a value is Node readable stream-like.isNodeREPL(): check if running in a Node.js REPL environment.isNodeStreamLike( value ): test if a value is Node stream-like.isNodeTransformStreamLike( value ): test if a value is Node transform stream-like.isNodeWritableStreamLike( value ): test if a value is Node writable stream-like.isObjectLike( value ): test if a value is object-like.isOdd( value ): test if a value is an odd number.isPlainObject( value ): test if a value is a plain object.isPositiveZero( value ): test if a value is a number equal to positive zero.isProbability( value ): test if a value is a probability.isRegExpString( value ): test if a value is a regular expression string.isRelativePath( value ): test if a value is a relative path.isSameValue( a, b ): test if two arguments are the same value.isStrictEqual( a, b ): test if two arguments are strictly equal.isTruthy( value ): test if a value is truthy.isUNCPath( value ): test if a value is a UNC path.isUndefinedOrNull( value ): test if a value is undefined or null.isUppercase( value ): test if a value is an uppercase string.isURI( value ): test if a value is a URI.isWhitespace( value ): test whether a string contains only white space characters.
var objectKeys = require( '@stdlib/utils/keys' );
var assert = require( '@stdlib/assert' );
console.log( objectKeys( assert ) );