Skip to content

Latest commit

 

History

History

assert

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Assert

Standard library assertion utilities.

Usage

var assert = require( '@stdlib/assert' );

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:

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 true

Most of the assertion utilities have corresponding packages that test whether all elements of an array are of the given data type:

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 true

The namespace also contains functions to test for numbers in a certain range or arrays of such numbers:

The namespace exposes various methods for validating typed arrays:

It also contains functions for validating ndarrays of varying dimensions.

In addition, the namespace contains functions validating other special arrays or buffers:

To test for error objects, use any of the following functions:

The following constants are exposed to indicate the environment the current process is running on:

Use the following functions to check whether a runtime environment supports a certain feature:

The remaining functions of the assert namespace are:

Examples

var getKeys = require( 'object-keys' ).shim();
var assert = require( '@stdlib/assert' );

console.log( getKeys( assert ) );