@stdlib/assert-is-symbol-array

Test if a value is an array-like object containing only symbols.

Usage no npm install needed!

<script type="module">
  import stdlibAssertIsSymbolArray from 'https://cdn.skypack.dev/@stdlib/assert-is-symbol-array';
</script>

README

isSymbolArray

NPM version Build Status Coverage Status

Test if a value is an array-like object containing only symbols.

Installation

npm install @stdlib/assert-is-symbol-array

Usage

var isSymbolArray = require( '@stdlib/assert-is-symbol-array' );

isSymbolArray( value )

Tests if a value is an array-like object containing only symbols.

var Symbol = require( '@stdlib/symbol-ctor' );

var bool = isSymbolArray( [ Symbol( 'beep' ), Symbol( 'boop' ) ] );
// returns true

bool = isSymbolArray( [ 'beep', 'boop' ] );
// returns false

isSymbolArray.primitives( value )

Tests if a value is an array-like object containing only symbol primitives.

var Symbol = require( '@stdlib/symbol-ctor' );

var bool = isSymbolArray.primitives( [ Symbol( 'beep' ), Symbol( 'boop' ) ] );
// returns true

bool = isSymbolArray.primitives( [ Symbol( 'beep' ), Object( Symbol( 'boop' ) ) ] );
// returns false

isSymbolArray.objects( value )

Tests if a value is an array-like object containing only Symbol objects.

var Symbol = require( '@stdlib/symbol-ctor' );

var bool = isSymbolArray.objects( [ Object( Symbol( 'beep' ) ), Object( Symbol( 'boop' ) ) ] );
// returns true

bool = isSymbolArray.objects( [ Symbol( 'beep' ), Symbol( 'boop' ) ] );
// returns false

Examples

var hasSymbolSupport = require( '@stdlib/assert-has-symbol-support' );
var Symbol = require( '@stdlib/symbol-ctor' );
var isSymbolArray = require( '@stdlib/assert-is-symbol-array' );

var hasSymbols = hasSymbolSupport();
var bool;

if ( hasSymbols ) {
    bool = isSymbolArray( [ Symbol( 'beep' ), Symbol( 'boop' ) ] );
    // returns true

    bool = isSymbolArray( [ Symbol( 'beep' ), 'boop' ] );
    // returns false

    bool = isSymbolArray( Symbol( 'beep' ) );
    // returns false
} else {
    console.log( 'Environment does not support symbols.' );
}
bool = isSymbolArray( [ 'beep', 'boop' ] );
// returns false

bool = isSymbolArray( [] );
// returns false

bool = isSymbolArray( 'abc' );
// returns false

bool = isSymbolArray( null );
// returns false

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.

Community

Chat


License

See LICENSE.

Copyright

Copyright © 2016-2022. The Stdlib Authors.