Skip to content

Commit 5fe348d

Browse files
committed
feat: add array/base/assert/is-boolean-data-type
1 parent ce7ccf7 commit 5fe348d

File tree

10 files changed

+787
-0
lines changed

10 files changed

+787
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
<!--
2+
3+
@license Apache-2.0
4+
5+
Copyright (c) 2024 The Stdlib Authors.
6+
7+
Licensed under the Apache License, Version 2.0 (the "License");
8+
you may not use this file except in compliance with the License.
9+
You may obtain a copy of the License at
10+
11+
http://www.apache.org/licenses/LICENSE-2.0
12+
13+
Unless required by applicable law or agreed to in writing, software
14+
distributed under the License is distributed on an "AS IS" BASIS,
15+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
See the License for the specific language governing permissions and
17+
limitations under the License.
18+
19+
-->
20+
21+
# isBooleanDataType
22+
23+
> Test if an input value is a supported array boolean data type.
24+
25+
<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
26+
27+
<section class="intro">
28+
29+
</section>
30+
31+
<!-- /.intro -->
32+
33+
<!-- Package usage documentation. -->
34+
35+
<section class="usage">
36+
37+
## Usage
38+
39+
```javascript
40+
var isBooleanDataType = require( '@stdlib/array/base/assert/is-boolean-data-type' );
41+
```
42+
43+
#### isBooleanDataType( value )
44+
45+
Tests if an input `value` is a supported array boolean data type.
46+
47+
```javascript
48+
var bool = isBooleanDataType( 'bool' );
49+
// returns true
50+
51+
bool = isBooleanDataType( 'uint32' );
52+
// returns false
53+
```
54+
55+
</section>
56+
57+
<!-- /.usage -->
58+
59+
<!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
60+
61+
<section class="notes">
62+
63+
</section>
64+
65+
<!-- /.notes -->
66+
67+
<!-- Package usage examples. -->
68+
69+
<section class="examples">
70+
71+
## Examples
72+
73+
<!-- eslint no-undef: "error" -->
74+
75+
```javascript
76+
var isBooleanDataType = require( '@stdlib/array/base/assert/is-boolean-data-type' );
77+
78+
var bool = isBooleanDataType( 'bool' );
79+
// returns true
80+
81+
bool = isBooleanDataType( 'complex64' );
82+
// returns false
83+
84+
bool = isBooleanDataType( 'complex128' );
85+
// returns false
86+
87+
bool = isBooleanDataType( 'float32' );
88+
// returns false
89+
90+
bool = isBooleanDataType( 'float64' );
91+
// returns false
92+
93+
bool = isBooleanDataType( 'generic' );
94+
// returns false
95+
96+
bool = isBooleanDataType( 'int16' );
97+
// returns false
98+
99+
bool = isBooleanDataType( 'int32' );
100+
// returns false
101+
102+
bool = isBooleanDataType( 'int8' );
103+
// returns false
104+
105+
bool = isBooleanDataType( 'uint16' );
106+
// returns false
107+
108+
bool = isBooleanDataType( 'uint32' );
109+
// returns false
110+
111+
bool = isBooleanDataType( 'uint8' );
112+
// returns false
113+
114+
bool = isBooleanDataType( 'uint8c' );
115+
// returns false
116+
117+
bool = isBooleanDataType( '' );
118+
// returns false
119+
120+
bool = isBooleanDataType( 'foo' );
121+
// returns false
122+
```
123+
124+
</section>
125+
126+
<!-- /.examples -->
127+
128+
<!-- Section to include cited references. If references are included, add a horizontal rule *before* the section. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
129+
130+
<section class="references">
131+
132+
</section>
133+
134+
<!-- /.references -->
135+
136+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
137+
138+
<section class="related">
139+
140+
</section>
141+
142+
<!-- /.related -->
143+
144+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
145+
146+
<section class="links">
147+
148+
</section>
149+
150+
<!-- /.links -->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2024 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
'use strict';
20+
21+
// MODULES //
22+
23+
var bench = require( '@stdlib/bench' );
24+
var isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive;
25+
var pkg = require( './../package.json' ).name;
26+
var isBooleanDataType = require( './../lib' );
27+
28+
29+
// MAIN //
30+
31+
bench( pkg, function benchmark( b ) {
32+
var values;
33+
var out;
34+
var v;
35+
var i;
36+
37+
values = [
38+
'binary',
39+
'bool',
40+
'complex128',
41+
'complex64',
42+
'float32',
43+
'float64',
44+
'generic',
45+
'int16',
46+
'int32',
47+
'int8',
48+
'uint16',
49+
'uint32',
50+
'uint8',
51+
'uint8c',
52+
'foo',
53+
'bar',
54+
'',
55+
'beep',
56+
'boop'
57+
];
58+
59+
b.tic();
60+
for ( i = 0; i < b.iterations; i++ ) {
61+
v = values[ i%values.length ];
62+
out = isBooleanDataType( v );
63+
if ( typeof out !== 'boolean' ) {
64+
b.fail( 'should return a boolean' );
65+
}
66+
}
67+
b.toc();
68+
if ( !isBoolean( out ) ) {
69+
b.fail( 'should return a boolean' );
70+
}
71+
b.pass( 'benchmark finished' );
72+
b.end();
73+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
2+
{{alias}}( value )
3+
Tests if an input value is a supported array boolean data type.
4+
5+
Parameters
6+
----------
7+
value: any
8+
Value to test.
9+
10+
Returns
11+
-------
12+
bool: boolean
13+
Boolean indicating if an input value is a supported array boolean data
14+
type.
15+
16+
Examples
17+
--------
18+
> var bool = {{alias}}( 'bool' )
19+
true
20+
> bool = {{alias}}( 'float64' )
21+
false
22+
> bool = {{alias}}( 'int16' )
23+
false
24+
> bool = {{alias}}( 'int32' )
25+
false
26+
> bool = {{alias}}( 'int8' )
27+
false
28+
> bool = {{alias}}( 'uint16' )
29+
false
30+
> bool = {{alias}}( 'uint32' )
31+
false
32+
> bool = {{alias}}( 'uint8' )
33+
false
34+
> bool = {{alias}}( 'uint8c' )
35+
false
36+
> bool = {{alias}}( '' )
37+
false
38+
> bool = {{alias}}( 'beep' )
39+
false
40+
41+
See Also
42+
--------
43+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
/*
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2024 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
// TypeScript Version: 4.1
20+
21+
/**
22+
* Tests whether an input value is a supported array boolean data type.
23+
*
24+
* @param v - value to test
25+
* @returns boolean indicating whether an input value is a supported array boolean data type
26+
*
27+
* @example
28+
* var bool = isBooleanDataType( 'bool' );
29+
* // returns true
30+
*
31+
* bool = isBooleanDataType( 'complex64' );
32+
* // returns false
33+
*
34+
* bool = isBooleanDataType( 'complex128' );
35+
* // returns false
36+
*
37+
* bool = isBooleanDataType( 'float32' );
38+
* // returns false
39+
*
40+
* bool = isBooleanDataType( 'float64' );
41+
* // returns false
42+
*
43+
* bool = isBooleanDataType( 'generic' );
44+
* // returns false
45+
*
46+
* bool = isBooleanDataType( 'int16' );
47+
* // returns false
48+
*
49+
* bool = isBooleanDataType( 'int32' );
50+
* // returns false
51+
*
52+
* bool = isBooleanDataType( 'int8' );
53+
* // returns false
54+
*
55+
* bool = isBooleanDataType( 'uint16' );
56+
* // returns false
57+
*
58+
* bool = isBooleanDataType( 'uint32' );
59+
* // returns false
60+
*
61+
* bool = isBooleanDataType( 'uint8' );
62+
* // returns false
63+
*
64+
* bool = isBooleanDataType( 'uint8c' );
65+
* // returns false
66+
*
67+
* bool = isBooleanDataType( 'foo' );
68+
* // returns false
69+
*/
70+
declare function isBooleanDataType( v: any ): boolean;
71+
72+
73+
// EXPORTS //
74+
75+
export = isBooleanDataType;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2024 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
import isBooleanDataType = require( './index' );
20+
21+
22+
// TESTS //
23+
24+
// The function returns a boolean...
25+
{
26+
isBooleanDataType( 'float32' ); // $ExpectType boolean
27+
isBooleanDataType( 'foo' ); // $ExpectType boolean
28+
}
29+
30+
// The compiler throws an error if the function is provided an unsupported number of arguments...
31+
{
32+
isBooleanDataType(); // $ExpectError
33+
isBooleanDataType( undefined, 123 ); // $ExpectError
34+
}

0 commit comments

Comments
 (0)