Skip to content

Commit c326c3f

Browse files
committed
feat: add ndarray/base/assert/is-numeric-data-type
1 parent d3d2708 commit c326c3f

File tree

10 files changed

+754
-0
lines changed

10 files changed

+754
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
<!--
2+
3+
@license Apache-2.0
4+
5+
Copyright (c) 2023 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+
# isNumericDataType
22+
23+
> Test if an input value is a supported ndarray numeric 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 isNumericDataType = require( '@stdlib/ndarray/base/assert/is-numeric-data-type' );
41+
```
42+
43+
#### isNumericDataType( value )
44+
45+
Tests if an input `value` is a supported ndarray numeric data type.
46+
47+
```javascript
48+
var bool = isNumericDataType( 'float32' );
49+
// returns true
50+
51+
bool = isNumericDataType( 'uint32' );
52+
// returns true
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 isNumericDataType = require( '@stdlib/ndarray/base/assert/is-numeric-data-type' );
77+
78+
var bool = isNumericDataType( 'binary' );
79+
// returns false
80+
81+
bool = isNumericDataType( 'float32' );
82+
// returns true
83+
84+
bool = isNumericDataType( 'float64' );
85+
// returns true
86+
87+
bool = isNumericDataType( 'generic' );
88+
// returns false
89+
90+
bool = isNumericDataType( 'int16' );
91+
// returns true
92+
93+
bool = isNumericDataType( 'int32' );
94+
// returns true
95+
96+
bool = isNumericDataType( 'int8' );
97+
// returns true
98+
99+
bool = isNumericDataType( 'uint16' );
100+
// returns true
101+
102+
bool = isNumericDataType( 'uint32' );
103+
// returns true
104+
105+
bool = isNumericDataType( 'uint8' );
106+
// returns true
107+
108+
bool = isNumericDataType( 'uint8c' );
109+
// returns true
110+
111+
bool = isNumericDataType( '' );
112+
// returns false
113+
114+
bool = isNumericDataType( 'foo' );
115+
// returns false
116+
```
117+
118+
</section>
119+
120+
<!-- /.examples -->
121+
122+
<!-- 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. -->
123+
124+
<section class="references">
125+
126+
</section>
127+
128+
<!-- /.references -->
129+
130+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
131+
132+
<section class="related">
133+
134+
</section>
135+
136+
<!-- /.related -->
137+
138+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
139+
140+
<section class="links">
141+
142+
</section>
143+
144+
<!-- /.links -->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2023 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 isNumericDataType = 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+
'float32',
40+
'float64',
41+
'generic',
42+
'int16',
43+
'int32',
44+
'int8',
45+
'uint16',
46+
'uint32',
47+
'uint8',
48+
'uint8c',
49+
'foo',
50+
'bar',
51+
'',
52+
'beep',
53+
'boop'
54+
];
55+
56+
b.tic();
57+
for ( i = 0; i < b.iterations; i++ ) {
58+
v = values[ i%values.length ];
59+
out = isNumericDataType( v );
60+
if ( typeof out !== 'boolean' ) {
61+
b.fail( 'should return a boolean' );
62+
}
63+
}
64+
b.toc();
65+
if ( !isBoolean( out ) ) {
66+
b.fail( 'should return a boolean' );
67+
}
68+
b.pass( 'benchmark finished' );
69+
b.end();
70+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
2+
{{alias}}( value )
3+
Tests if an input value is a supported ndarray numeric 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 ndarray numeric data
14+
type.
15+
16+
Examples
17+
--------
18+
> var bool = {{alias}}( 'binary' )
19+
false
20+
> bool = {{alias}}( 'float32' )
21+
true
22+
> bool = {{alias}}( 'float64' )
23+
true
24+
> bool = {{alias}}( 'int16' )
25+
true
26+
> bool = {{alias}}( 'int32' )
27+
true
28+
> bool = {{alias}}( 'int8' )
29+
true
30+
> bool = {{alias}}( 'uint16' )
31+
true
32+
> bool = {{alias}}( 'uint32' )
33+
true
34+
> bool = {{alias}}( 'uint8' )
35+
true
36+
> bool = {{alias}}( 'uint8c' )
37+
true
38+
> bool = {{alias}}( '' )
39+
false
40+
> bool = {{alias}}( 'beep' )
41+
false
42+
43+
See Also
44+
--------
45+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/*
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2023 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: 2.0
20+
21+
/**
22+
* Tests whether an input value is a supported ndarray numeric data type.
23+
*
24+
* @param v - value to test
25+
* @returns boolean indicating whether an input value is a supported ndarray numeric data type
26+
*
27+
* @example
28+
* var bool = isNumericDataType( 'binary' );
29+
* // returns false
30+
*
31+
* bool = isNumericDataType( 'float32' );
32+
* // returns true
33+
*
34+
* bool = isNumericDataType( 'float64' );
35+
* // returns true
36+
*
37+
* bool = isNumericDataType( 'generic' );
38+
* // returns false
39+
*
40+
* bool = isNumericDataType( 'int16' );
41+
* // returns true
42+
*
43+
* bool = isNumericDataType( 'int32' );
44+
* // returns true
45+
*
46+
* bool = isNumericDataType( 'int8' );
47+
* // returns true
48+
*
49+
* bool = isNumericDataType( 'uint16' );
50+
* // returns true
51+
*
52+
* bool = isNumericDataType( 'uint32' );
53+
* // returns true
54+
*
55+
* bool = isNumericDataType( 'uint8' );
56+
* // returns true
57+
*
58+
* bool = isNumericDataType( 'uint8c' );
59+
* // returns true
60+
*
61+
* bool = isNumericDataType( 'foo' );
62+
* // returns false
63+
*/
64+
declare function isNumericDataType( v: any ): boolean;
65+
66+
67+
// EXPORTS //
68+
69+
export = isNumericDataType;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2023 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 isNumericDataType = require( './index' );
20+
21+
22+
// TESTS //
23+
24+
// The function returns a boolean...
25+
{
26+
isNumericDataType( 'binary' ); // $ExpectType boolean
27+
isNumericDataType( 'foo' ); // $ExpectType boolean
28+
}
29+
30+
// The compiler throws an error if the function is provided an unsupported number of arguments...
31+
{
32+
isNumericDataType(); // $ExpectError
33+
isNumericDataType( undefined, 123 ); // $ExpectError
34+
}

0 commit comments

Comments
 (0)