diff --git a/lib/node_modules/@stdlib/array/base/assert/is-booleanarray/README.md b/lib/node_modules/@stdlib/array/base/assert/is-booleanarray/README.md new file mode 100644 index 00000000000..33f266db84c --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/assert/is-booleanarray/README.md @@ -0,0 +1,157 @@ + + +# isBooleanArray + +> Test if a value is a [`BooleanArray`][@stdlib/array/bool]. + +
+ +
+ + + +
+ +## Usage + +```javascript +var isBooleanArray = require( '@stdlib/array/base/assert/is-booleanarray' ); +``` + +#### isBooleanArray( value ) + +Tests if a value is a [`BooleanArray`][@stdlib/array/bool]. + +```javascript +var BooleanArray = require( '@stdlib/array/bool' ); + +var arr = new BooleanArray( 10 ); +var bool = isBooleanArray( arr ); +// returns true +``` + +
+ + + +
+ +## Notes + +- This function is not robust and that is intentional. This function provides a lower cost way to reasonably determine whether an input value is a [`BooleanArray`][@stdlib/array/bool] in order to avoid walking the prototype chain and resolving constructors, which is necessary for robust identification of cross-realm instances. For more robust validation, see [`@stdlib/assert/is-booleanarray`][@stdlib/assert/is-booleanarray]. + +
+ + + +
+ +## Examples + + + + + +```javascript +var Int8Array = require( '@stdlib/array/int8' ); +var Uint8Array = require( '@stdlib/array/uint8' ); +var Uint8ClampedArray = require( '@stdlib/array/uint8c' ); +var Int16Array = require( '@stdlib/array/int16' ); +var Uint16Array = require( '@stdlib/array/uint16' ); +var Int32Array = require( '@stdlib/array/int32' ); +var Uint32Array = require( '@stdlib/array/uint32' ); +var Float32Array = require( '@stdlib/array/float32' ); +var Float64Array = require( '@stdlib/array/float64' ); +var Complex128Array = require( '@stdlib/array/complex128' ); +var Complex64Array = require( '@stdlib/array/complex64' ); +var BooleanArray = require( '@stdlib/array/bool' ); +var isBooleanArray = require( '@stdlib/array/base/assert/is-booleanarray' ); + +var bool = isBooleanArray( new BooleanArray( 10 ) ); +// returns true + +bool = isBooleanArray( new Complex64Array( 10 ) ); +// returns false + +bool = isBooleanArray( new Complex128Array( 10 ) ); +// returns false + +bool = isBooleanArray( [] ); +// returns false + +bool = isBooleanArray( new Float64Array( 10 ) ); +// returns false + +bool = isBooleanArray( new Float32Array( 10 ) ); +// returns false + +bool = isBooleanArray( new Int32Array( 10 ) ); +// returns false + +bool = isBooleanArray( new Uint32Array( 10 ) ); +// returns false + +bool = isBooleanArray( new Int16Array( 10 ) ); +// returns false + +bool = isBooleanArray( new Uint16Array( 10 ) ); +// returns false + +bool = isBooleanArray( new Int8Array( 10 ) ); +// returns false + +bool = isBooleanArray( new Uint8Array( 10 ) ); +// returns false + +bool = isBooleanArray( new Uint8ClampedArray( 10 ) ); +// returns false + +bool = isBooleanArray( { 'length': 0 } ); +// returns false +``` + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/array/base/assert/is-booleanarray/benchmark/benchmark.js b/lib/node_modules/@stdlib/array/base/assert/is-booleanarray/benchmark/benchmark.js new file mode 100644 index 00000000000..dc263bb578d --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/assert/is-booleanarray/benchmark/benchmark.js @@ -0,0 +1,165 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var Float32Array = require( '@stdlib/array/float32' ); +var Complex64Array = require( '@stdlib/array/complex64' ); +var BooleanArray = require( '@stdlib/array/bool' ); +var isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive; +var pkg = require( './../package.json' ).name; +var isBooleanArray = require( './../lib' ); + + +// MAIN // + +bench( pkg+'::array', function benchmark( b ) { + var bool; + var obj; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + obj = [ i, i+1 ]; + bool = isBooleanArray( obj ); + if ( typeof bool !== 'boolean' ) { + b.fail( 'should return a boolean' ); + } + } + b.toc(); + if ( !isBoolean( bool ) ) { + b.fail( 'should return a boolean' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::boolean_array', function benchmark( b ) { + var values; + var bool; + var obj; + var N; + var i; + + values = [ + new BooleanArray( [ true, false ] ), + new BooleanArray( [ false, true ] ) + ]; + N = values.length; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + obj = values[ i%N ]; + bool = isBooleanArray( obj ); + if ( typeof bool !== 'boolean' ) { + b.fail( 'should return a boolean' ); + } + } + b.toc(); + if ( !isBoolean( bool ) ) { + b.fail( 'should return a boolean' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::real_typed_array', function benchmark( b ) { + var values; + var bool; + var obj; + var N; + var i; + + values = [ + new Float32Array( [ 1.0, 2.0 ] ), + new Float32Array( [ 3.0, 4.0 ] ) + ]; + N = values.length; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + obj = values[ i%N ]; + bool = isBooleanArray( obj ); + if ( typeof bool !== 'boolean' ) { + b.fail( 'should return a boolean' ); + } + } + b.toc(); + if ( !isBoolean( bool ) ) { + b.fail( 'should return a boolean' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::complex_typed_array', function benchmark( b ) { + var values; + var bool; + var obj; + var N; + var i; + + values = [ + new Complex64Array( [ 1.0, 2.0 ] ), + new Complex64Array( [ 3.0, 4.0 ] ) + ]; + N = values.length; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + obj = values[ i%N ]; + bool = isBooleanArray( obj ); + if ( typeof bool !== 'boolean' ) { + b.fail( 'should return a boolean' ); + } + } + b.toc(); + if ( !isBoolean( bool ) ) { + b.fail( 'should return a boolean' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+'::array_like_object', function benchmark( b ) { + var bool; + var obj; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + obj = { + 'length': 2, + '0': i, + '1': i + 1 + }; + bool = isBooleanArray( obj ); + if ( typeof bool !== 'boolean' ) { + b.fail( 'should return a boolean' ); + } + } + b.toc(); + if ( !isBoolean( bool ) ) { + b.fail( 'should return a boolean' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/array/base/assert/is-booleanarray/docs/repl.txt b/lib/node_modules/@stdlib/array/base/assert/is-booleanarray/docs/repl.txt new file mode 100644 index 00000000000..34707329149 --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/assert/is-booleanarray/docs/repl.txt @@ -0,0 +1,26 @@ + +{{alias}}( value ) + Tests if a value is a BooleanArray. + + Parameters + ---------- + value: ArrayLikeObject + Value to test. + + Returns + ------- + bool: boolean + Boolean indicating whether a value is a BooleanArray. + + Examples + -------- + > var bool = {{alias}}( new {{alias:@stdlib/array/bool}}( 10 ) ) + true + > bool = {{alias}}( [] ) + false + > bool = {{alias}}( { 'length': 0 } ) + false + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/array/base/assert/is-booleanarray/docs/types/index.d.ts b/lib/node_modules/@stdlib/array/base/assert/is-booleanarray/docs/types/index.d.ts new file mode 100644 index 00000000000..5625c711675 --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/assert/is-booleanarray/docs/types/index.d.ts @@ -0,0 +1,47 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +// TypeScript Version: 4.1 + +/// + +import { Collection, BooleanArray } from '@stdlib/types/array'; + +/** +* Tests if a value is a `BooleanArray`. +* +* @param value - value to test +* @returns boolean indicating whether a value is a `BooleanArray` +* +* @example +* var BooleanArray = require( '@stdlib/array/bool' ); +* +* var arr = new BooleanArray( 10 ); +* var bool = isBooleanArray( arr ); +* // returns true +* +* @example +* var bool = isBooleanArray( [] ); +* // returns false +*/ +declare function isBooleanArray( value: Collection | BooleanArray ): value is BooleanArray; + + +// EXPORTS // + +export = isBooleanArray; diff --git a/lib/node_modules/@stdlib/array/base/assert/is-booleanarray/docs/types/test.ts b/lib/node_modules/@stdlib/array/base/assert/is-booleanarray/docs/types/test.ts new file mode 100644 index 00000000000..dd955f8b2ea --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/assert/is-booleanarray/docs/types/test.ts @@ -0,0 +1,33 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +import isBooleanArray = require( './index' ); + + +// TESTS // + +// The function returns a boolean... +{ + isBooleanArray( [] ); // $ExpectType boolean +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + isBooleanArray(); // $ExpectError + isBooleanArray( [], 123 ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/array/base/assert/is-booleanarray/examples/index.js b/lib/node_modules/@stdlib/array/base/assert/is-booleanarray/examples/index.js new file mode 100644 index 00000000000..938f142a48b --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/assert/is-booleanarray/examples/index.js @@ -0,0 +1,77 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/* eslint-disable object-curly-newline */ + +'use strict'; + +var Int8Array = require( '@stdlib/array/int8' ); +var Uint8Array = require( '@stdlib/array/uint8' ); +var Uint8ClampedArray = require( '@stdlib/array/uint8c' ); +var Int16Array = require( '@stdlib/array/int16' ); +var Uint16Array = require( '@stdlib/array/uint16' ); +var Int32Array = require( '@stdlib/array/int32' ); +var Uint32Array = require( '@stdlib/array/uint32' ); +var Float32Array = require( '@stdlib/array/float32' ); +var Float64Array = require( '@stdlib/array/float64' ); +var Complex128Array = require( '@stdlib/array/complex128' ); +var Complex64Array = require( '@stdlib/array/complex64' ); +var BooleanArray = require( '@stdlib/array/bool' ); +var isBooleanArray = require( './../lib' ); + +console.log( isBooleanArray( new BooleanArray( 10 ) ) ); +// => true + +console.log( isBooleanArray( new Complex64Array( 10 ) ) ); +// => false + +console.log( isBooleanArray( new Complex128Array( 10 ) ) ); +// => false + +console.log( isBooleanArray( [] ) ); +// => false + +console.log( isBooleanArray( new Float64Array( 10 ) ) ); +// => false + +console.log( isBooleanArray( new Float32Array( 10 ) ) ); +// => false + +console.log( isBooleanArray( new Int32Array( 10 ) ) ); +// => false + +console.log( isBooleanArray( new Uint32Array( 10 ) ) ); +// => false + +console.log( isBooleanArray( new Int16Array( 10 ) ) ); +// => false + +console.log( isBooleanArray( new Uint16Array( 10 ) ) ); +// => false + +console.log( isBooleanArray( new Int8Array( 10 ) ) ); +// => false + +console.log( isBooleanArray( new Uint8Array( 10 ) ) ); +// => false + +console.log( isBooleanArray( new Uint8ClampedArray( 10 ) ) ); +// => false + +console.log( isBooleanArray( { 'length': 0 } ) ); +// => false diff --git a/lib/node_modules/@stdlib/array/base/assert/is-booleanarray/lib/index.js b/lib/node_modules/@stdlib/array/base/assert/is-booleanarray/lib/index.js new file mode 100644 index 00000000000..f1d5519c026 --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/assert/is-booleanarray/lib/index.js @@ -0,0 +1,44 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +/** +* Test if a value is a `BooleanArray`. +* +* @module @stdlib/array/base/assert/is-booleanarray +* +* @example +* var BooleanArray = require( '@stdlib/array/bool' ); +* var isBooleanArray = require( '@stdlib/array/base/assert/is-booleanarray' ); +* +* var bool = isBooleanArray( new BooleanArray( 10 ) ); +* // returns true +* +* bool = isBooleanArray( [] ); +* // returns false +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/array/base/assert/is-booleanarray/lib/main.js b/lib/node_modules/@stdlib/array/base/assert/is-booleanarray/lib/main.js new file mode 100644 index 00000000000..62a6ce6dc57 --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/assert/is-booleanarray/lib/main.js @@ -0,0 +1,56 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// VARIABLES // + +var BYTES_PER_ELEMENT = 1; // 1 bytes per uint8 + + +// MAIN // + +/** +* Returns a boolean indicating if a value is a `BooleanArray`. +* +* @param {*} value - value to test +* @returns {boolean} boolean indicating if a value is a `BooleanArray` +* +* @example +* var BooleanArray = require( '@stdlib/array/bool' ); +* +* var bool = isBooleanArray( new BooleanArray( 10 ) ); +* // returns true +* +* bool = isBooleanArray( [] ); +* // returns false +*/ +function isBooleanArray( value ) { + // Note: the following is not robust and that is intentional. In this case, we are seeking a lower cost way to reasonably determine whether an input value is a `BooleanArray` in order to avoid walking the prototype chain and resolving constructors, which is necessary for robust identification of cross-realm instances. For more robust validation, see `@stdlib/assert/is-booleanarray`. + return ( + typeof value === 'object' && + value !== null && + value.constructor.name === 'BooleanArray' && + value.BYTES_PER_ELEMENT === BYTES_PER_ELEMENT + ); +} + + +// EXPORTS // + +module.exports = isBooleanArray; diff --git a/lib/node_modules/@stdlib/array/base/assert/is-booleanarray/package.json b/lib/node_modules/@stdlib/array/base/assert/is-booleanarray/package.json new file mode 100644 index 00000000000..7e8782c5421 --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/assert/is-booleanarray/package.json @@ -0,0 +1,73 @@ +{ + "name": "@stdlib/array/base/assert/is-booleanarray", + "version": "0.0.0", + "description": "Test if a value is a BooleanArray.", + "license": "Apache-2.0", + "author": { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + }, + "contributors": [ + { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + } + ], + "main": "./lib", + "directories": { + "benchmark": "./benchmark", + "doc": "./docs", + "example": "./examples", + "lib": "./lib", + "test": "./test" + }, + "types": "./docs/types", + "scripts": {}, + "homepage": "https://github.com/stdlib-js/stdlib", + "repository": { + "type": "git", + "url": "git://github.com/stdlib-js/stdlib.git" + }, + "bugs": { + "url": "https://github.com/stdlib-js/stdlib/issues" + }, + "dependencies": {}, + "devDependencies": {}, + "engines": { + "node": ">=0.10.0", + "npm": ">2.7.0" + }, + "os": [ + "aix", + "darwin", + "freebsd", + "linux", + "macos", + "openbsd", + "sunos", + "win32", + "windows" + ], + "keywords": [ + "stdlib", + "stdassert", + "assertion", + "assert", + "utilities", + "utility", + "utils", + "util", + "base", + "array", + "typed array", + "collection", + "booleanarray", + "is", + "isarray", + "type", + "check", + "test", + "valid", + "validate" + ] +} diff --git a/lib/node_modules/@stdlib/array/base/assert/is-booleanarray/test/test.js b/lib/node_modules/@stdlib/array/base/assert/is-booleanarray/test/test.js new file mode 100644 index 00000000000..35484207535 --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/assert/is-booleanarray/test/test.js @@ -0,0 +1,92 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var constructorName = require( '@stdlib/utils/constructor-name' ); +var Int8Array = require( '@stdlib/array/int8' ); +var Uint8Array = require( '@stdlib/array/uint8' ); +var Uint8ClampedArray = require( '@stdlib/array/uint8c' ); +var Int16Array = require( '@stdlib/array/int16' ); +var Uint16Array = require( '@stdlib/array/uint16' ); +var Int32Array = require( '@stdlib/array/int32' ); +var Uint32Array = require( '@stdlib/array/uint32' ); +var Float32Array = require( '@stdlib/array/float32' ); +var Float64Array = require( '@stdlib/array/float64' ); +var Complex128Array = require( '@stdlib/array/complex128' ); +var Complex64Array = require( '@stdlib/array/complex64' ); +var BooleanArray = require( '@stdlib/array/bool' ); +var allocUnsafe = require( '@stdlib/buffer/alloc-unsafe' ); +var isBooleanArray = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof isBooleanArray, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function returns `true` if provided a BooleanArray', function test( t ) { + var values; + var i; + + values = [ + new BooleanArray( 20 ), + new BooleanArray( 10 ) + ]; + + for ( i = 0; i < values.length; i++ ) { + t.strictEqual( isBooleanArray( values[i] ), true, 'returns expected value when provided '+constructorName( values[i] ) ); + } + t.end(); +}); + +tape( 'the function returns `false` if not provided a BooleanArray', function test( t ) { + var values; + var i; + + values = [ + void 0, + null, + {}, + [], + { 'length': 10 }, // eslint-disable-line object-curly-newline + new Float64Array( 10 ), + new Float32Array( 10 ), + new Int32Array( 10 ), + new Uint32Array( 10 ), + new Int16Array( 10 ), + new Uint16Array( 10 ), + new Int8Array( 10 ), + new Uint8Array( 10 ), + new Uint8ClampedArray( 10 ), + new Complex128Array( 10 ), + new Complex64Array( 10 ), + allocUnsafe( 10 ) + ]; + + for ( i = 0; i < values.length; i++ ) { + t.strictEqual( isBooleanArray( values[i] ), false, 'returns expected value when provided '+constructorName( values[i] ) ); + } + t.end(); +});