Skip to content

Commit 76720ca

Browse files
committed
feat: add ndarray/base/assert/is-input-casting-policy
--- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: passed - task: lint_package_json status: passed - task: lint_repl_help status: passed - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: passed - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: passed - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: passed - task: lint_license_headers status: passed ---
1 parent edbd922 commit 76720ca

File tree

10 files changed

+596
-0
lines changed

10 files changed

+596
-0
lines changed
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
<!--
2+
3+
@license Apache-2.0
4+
5+
Copyright (c) 2025 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+
# isInputCastingPolicy
22+
23+
> Test if an input value is a supported input ndarray casting [policy][@stdlib/ndarray/input-casting-policies].
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 isInputCastingPolicy = require( '@stdlib/ndarray/base/assert/is-input-casting-policy' );
41+
```
42+
43+
#### isInputCastingPolicy( value )
44+
45+
Tests if an input value is a supported input ndarray casting [policy][@stdlib/ndarray/input-casting-policies].
46+
47+
```javascript
48+
var bool = isInputCastingPolicy( 'none' );
49+
// returns true
50+
51+
bool = isInputCastingPolicy( 'foo' );
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 isInputCastingPolicy = require( '@stdlib/ndarray/base/assert/is-input-casting-policy' );
77+
78+
var bool = isInputCastingPolicy( 'none' );
79+
// returns true
80+
81+
bool = isInputCastingPolicy( 'promoted' );
82+
// returns true
83+
84+
bool = isInputCastingPolicy( 'output' );
85+
// returns true
86+
87+
bool = isInputCastingPolicy( '' );
88+
// returns false
89+
90+
bool = isInputCastingPolicy( 'foo' );
91+
// returns false
92+
```
93+
94+
</section>
95+
96+
<!-- /.examples -->
97+
98+
<!-- 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. -->
99+
100+
<section class="references">
101+
102+
</section>
103+
104+
<!-- /.references -->
105+
106+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
107+
108+
<section class="related">
109+
110+
</section>
111+
112+
<!-- /.related -->
113+
114+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
115+
116+
<section class="links">
117+
118+
[@stdlib/ndarray/input-casting-policies]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/input-casting-policies
119+
120+
</section>
121+
122+
<!-- /.links -->
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2025 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 isInputCastingPolicy = 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+
'none',
39+
'promoted',
40+
'output',
41+
'numeric',
42+
'boolean_and_generic',
43+
'foo',
44+
'bar',
45+
'',
46+
'beep',
47+
'boop'
48+
];
49+
50+
b.tic();
51+
for ( i = 0; i < b.iterations; i++ ) {
52+
v = values[ i%values.length ];
53+
out = isInputCastingPolicy( v );
54+
if ( typeof out !== 'boolean' ) {
55+
b.fail( 'should return a boolean' );
56+
}
57+
}
58+
b.toc();
59+
if ( !isBoolean( out ) ) {
60+
b.fail( 'should return a boolean' );
61+
}
62+
b.pass( 'benchmark finished' );
63+
b.end();
64+
});
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
2+
{{alias}}( value )
3+
Tests if an input value is a supported input ndarray casting policy.
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 input ndarray
14+
casting policy.
15+
16+
Examples
17+
--------
18+
> var bool = {{alias}}( 'none' )
19+
true
20+
> bool = {{alias}}( 'promoted' )
21+
true
22+
> bool = {{alias}}( 'output' )
23+
true
24+
> bool = {{alias}}( '' )
25+
false
26+
> bool = {{alias}}( 'beep' )
27+
false
28+
29+
See Also
30+
--------
31+
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2025 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 ndarray input casting policy.
23+
*
24+
* @param v - value to test
25+
* @returns boolean indicating whether an input value is a supported ndarray input casting policy
26+
*
27+
* @example
28+
* var bool = isInputCastingPolicy( 'none' );
29+
* // returns true
30+
*
31+
* bool = isInputCastingPolicy( 'promoted' );
32+
* // returns true
33+
*
34+
* bool = isInputCastingPolicy( 'output' );
35+
* // returns true
36+
*
37+
* bool = isInputCastingPolicy( 'foo' );
38+
* // returns false
39+
*/
40+
declare function isInputCastingPolicy( v: any ): boolean;
41+
42+
43+
// EXPORTS //
44+
45+
export = isInputCastingPolicy;
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2025 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 isInputCastingPolicy = require( './index' );
20+
21+
22+
// TESTS //
23+
24+
// The function returns a boolean...
25+
{
26+
isInputCastingPolicy( 'none' ); // $ExpectType boolean
27+
isInputCastingPolicy( 'foo' ); // $ExpectType boolean
28+
}
29+
30+
// The compiler throws an error if the function is provided an unsupported number of arguments...
31+
{
32+
isInputCastingPolicy(); // $ExpectError
33+
isInputCastingPolicy( undefined, 123 ); // $ExpectError
34+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2025 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+
var isInputCastingPolicy = require( './../lib' );
22+
23+
var bool = isInputCastingPolicy( 'none' );
24+
console.log( bool );
25+
// => true
26+
27+
bool = isInputCastingPolicy( 'promoted' );
28+
console.log( bool );
29+
// => true
30+
31+
bool = isInputCastingPolicy( 'output' );
32+
console.log( bool );
33+
// => true
34+
35+
bool = isInputCastingPolicy( '' );
36+
console.log( bool );
37+
// => false
38+
39+
bool = isInputCastingPolicy( 'foo' );
40+
console.log( bool );
41+
// => false
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2025 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+
/**
22+
* Test whether an input value is a supported input ndarray casting policy.
23+
*
24+
* @module @stdlib/ndarray/base/assert/is-input-casting-policy
25+
*
26+
* @example
27+
* var isInputCastingPolicy = require( '@stdlib/ndarray/base/assert/is-input-casting-policy' );
28+
*
29+
* var bool = isInputCastingPolicy( 'none' );
30+
* // returns true
31+
*
32+
* bool = isInputCastingPolicy( 'promoted' );
33+
* // returns true
34+
*
35+
* bool = isInputCastingPolicy( 'output' );
36+
* // returns true
37+
*
38+
* bool = isInputCastingPolicy( 'foo' );
39+
* // returns false
40+
*/
41+
42+
// MODULES //
43+
44+
var main = require( './main.js' );
45+
46+
47+
// EXPORTS //
48+
49+
module.exports = main;

0 commit comments

Comments
 (0)