Skip to content

feat: add assert/is-booleanarray #2299

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Jun 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
138 changes: 138 additions & 0 deletions lib/node_modules/@stdlib/assert/is-booleanarray/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
<!--

@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.

-->

# isBooleanArray

> Test if a value is a [BooleanArray][@stdlib/array/bool].

<section class="usage">

## Usage

```javascript
var isBooleanArray = require( '@stdlib/assert/is-booleanarray' );
```

#### isBooleanArray( value )

Tests if a value is a [`BooleanArray`][@stdlib/array/bool].

```javascript
var BooleanArray = require( '@stdlib/array/bool' );

var bool = isBooleanArray( new BooleanArray( 10 ) );
// returns true

bool = isBooleanArray( [] );
// returns false
```

</section>

<!-- /.usage -->

<section class="examples">

## Examples

<!-- eslint no-undef: "error" -->

```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/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( new Float64Array( 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( new Int16Array( 10 ) );
// returns false

bool = isBooleanArray( new Uint16Array( 10 ) );
// returns false

bool = isBooleanArray( new Int32Array( 10 ) );
// returns false

bool = isBooleanArray( new Uint32Array( 10 ) );
// returns false

bool = isBooleanArray( new Float32Array( 10 ) );
// returns false

bool = isBooleanArray( new Array( 10 ) );
// returns false

bool = isBooleanArray( {} );
// returns false

bool = isBooleanArray( null );
// returns false
```

</section>

<!-- /.examples -->

<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->

<section class="related">

</section>

<!-- /.related -->

<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->

<section class="links">

[@stdlib/array/bool]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/bool

</section>

<!-- /.links -->
135 changes: 135 additions & 0 deletions lib/node_modules/@stdlib/assert/is-booleanarray/benchmark/benchmark.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
/**
* @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 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 Complex64Array = require( '@stdlib/array/complex64' );
var Complex128Array = require( '@stdlib/array/complex128' );
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, function benchmark( b ) {
var values;
var bool;
var i;

values = [
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 Complex64Array( 10 ),
new Complex128Array( 10 ),
new BooleanArray( 10 )
];

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
bool = isBooleanArray( values[ i%values.length ] );
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+'::true', function benchmark( b ) {
var values;
var bool;
var i;

values = [
new BooleanArray( 10 ),
new BooleanArray( 10 )
];

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
bool = isBooleanArray( values[ i%values.length ] );
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+'::false', function benchmark( b ) {
var values;
var bool;
var i;

values = [
new Complex128Array( 10 ),
new Complex64Array( 10 ),
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 )
];

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
bool = isBooleanArray( values[ i%values.length ] );
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();
});
24 changes: 24 additions & 0 deletions lib/node_modules/@stdlib/assert/is-booleanarray/docs/repl.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@

{{alias}}( value )
Tests if a value is a BooleanArray.

Parameters
----------
value: any
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

See Also
--------

Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* @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

/// <reference types="@stdlib/types"/>

import { 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 bool = isBooleanArray( new BooleanArray( 10 ) );
* // returns true
*
* @example
* var bool = isBooleanArray( [] );
* // returns false
*/
declare function isBooleanArray( value: any ): value is BooleanArray;

Check warning on line 41 in lib/node_modules/@stdlib/assert/is-booleanarray/docs/types/index.d.ts

View workflow job for this annotation

GitHub Actions / Lint Changed Files

Unexpected any. Specify a different type


// EXPORTS //

export = isBooleanArray;
33 changes: 33 additions & 0 deletions lib/node_modules/@stdlib/assert/is-booleanarray/docs/types/test.ts
Original file line number Diff line number Diff line change
@@ -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
}
Loading
Loading