Usage
var assert = require( '@stdlib/assert' );
assert
Included in this namespace is a comprehensive suite of assertion utilities, such as utilities for testing for various data types and others for testing for JavaScript feature support.
var o = assert;
To validate the built-in JavaScript data types, the namespace includes the following assertion utilities:
For primitive types having corresponding object wrappers, assertion utilities provide isObject
and isPrimitive
methods to test for either objects or primitives, respectively.
var isBoolean = require( '@stdlib/assert/is-boolean' );
var bool = isBoolean.isObject( new Boolean( false ) );
bool = isBoolean.isObject( false );
bool = isBoolean.isPrimitive( false );
Many of the assertion utilities have corresponding packages that test whether array elements are of the given data type:
Where applicable, similar to the assertion utilities for built-in data types, array assertion utilities provides methods for testing for an array of primitives or objects.
var isStringArray = require( '@stdlib/assert/is-string-array' );
var bool = isStringArray( [ 'hello', 'world' ] );
bool = isStringArray.primitives( [ 'hello', 'world' ] );
bool = isStringArray.objects( [ 'hello', 'world' ] );
bool = isStringArray.objects( [ new String( 'hello' ), new String( 'world' ) ] );
The namespace also contains utilities to test for numbers within a certain range or for numbers satisfying a particular "type":
The namespace provides various utilities for validating typed arrays:
The namespace includes utilities for validating ndarray
s (n-dimensional arrays).
The namespace includes utilities for validating complex numbers and arrays of complex numbers:
The namespace includes utilities for validating other special arrays or buffers:
To test for error objects, the namespace includes the following utilities:
The namespace exposes the following constants concerning the current running process:
To test whether a runtime environment supports certain features, the namespace includes the following utilities:
The remaining namespace utilities are as follows:
contains( val, searchValue[, position] )
: test if an array-like value contains a search value.deepEqual( a, b )
: test for deep equality between two values.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.hasUTF16SurrogatePairAt( string, position )
: test if a position in a string marks the start of a UTF-16 surrogate pair.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.isAccessorPropertyIn( value, property )
: test if an object's own or inherited property has an accessor descriptor.isAccessorProperty( value, property )
: test if an object's own property has an accessor descriptor.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.IS_BIG_ENDIAN
: check if an environment is big endian.isBinaryString( value )
: test if a value is a binary string.isBoxedPrimitive( value )
: test if a value is a JavaScript boxed primitive.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.isComposite( value )
: test if a value is a composite number.isConfigurablePropertyIn( value, property )
: test if an object's own or inherited property is configurable.isConfigurableProperty( value, property )
: test if an object's own property is configurable.isDataPropertyIn( value, property )
: test if an object's own or inherited property has a data descriptor.isDataProperty( value, property )
: test if an object's own property has a data descriptor.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.isEnumerablePropertyIn( value, property )
: test if an object's own or inherited property is enumerable.isEnumerableProperty( value, property )
: test if an object's own 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 is generator
object-like.isGeneratorObject( value )
: test if a value is a generator
object.isgzipBuffer( value )
: test if a value is a gzip buffer.isHexString( value )
: test whether a string contains only hexadecimal digits.isInfinite( value )
: test if a value is an infinite number.isInheritedProperty( value, property )
: test if an object has an inherited property.isIterableLike( value )
: test if a value is iterable
-like.isIteratorLike( value )
: test if a value is iterator
-like.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.isMethodIn( value, property )
: test if an object has a specified method name, either own or inherited.isMethod( value, property )
: test if an object has a specified method name.isNamedTypedTupleLike( value )
: test if a value is named typed tuple-like.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.isNonConfigurablePropertyIn( value, property )
: test if an object's own or inherited property is non-configurable.isNonConfigurableProperty( value, property )
: test if an object's own property is non-configurable.isNonEnumerablePropertyIn( value, property )
: test if an object's own or inherited property is non-enumerable.isNonEnumerableProperty( value, property )
: test if an object's own property is non-enumerable.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.isPrime( value )
: test if a value is a prime number.isPrimitive( value )
: test if a value is a JavaScript primitive.isPRNGLike( value )
: test if a value is PRNG-like.isProbability( value )
: test if a value is a probability.isPrototypeOf( obj, prototype )
: test if an object's prototype chain contains a provided prototype.isReadOnlyPropertyIn( value, property )
: test if an object's own or inherited property is read-only.isReadOnlyProperty( value, property )
: test if an object's own property is read-only.isReadWritePropertyIn( value, property )
: test if an object's own or inherited property is readable and writable.isReadWriteProperty( value, property )
: test if an object's own property is readable and writable.isReadablePropertyIn( value, property )
: test if an object's own or inherited property is readable.isReadableProperty( value, property )
: test if an object's own property is readable.isRegExpString( value )
: test if a value is a regular expression string.isRelativePath( value )
: test if a value is a relative path.isSameValueZero( a, b )
: test if two arguments are the same value.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.isWritablePropertyIn( value, property )
: test if an object's own or inherited property is writable.isWritableProperty( value, property )
: test if an object's own property is writable.isWriteOnlyPropertyIn( value, property )
: test if an object's own or inherited property is write-only.isWriteOnlyProperty( value, property )
: test if an object's own property is write-only.
Notice
This package is part of stdlib, a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more.
For more information on the project, filing bug reports and feature requests, and guidance on how to develop stdlib, see the main project repository.
License
See LICENSE.
Copyright
Copyright © 2016-2021. The Stdlib Authors.