Skip to content

Commit eac188f

Browse files
committed
feat: add support for struct data types
--- 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: na - task: lint_repl_help status: na - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: na - 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: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed ---
1 parent 99ecc69 commit eac188f

File tree

3 files changed

+33
-5
lines changed

3 files changed

+33
-5
lines changed

lib/node_modules/@stdlib/ndarray/base/assert/is-data-type/README.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ var isDataType = require( '@stdlib/ndarray/base/assert/is-data-type' );
4242

4343
#### isDataType( value )
4444

45-
Tests if an input `value` is a supported ndarray data type.
45+
Tests if an input value is a supported ndarray data type.
4646

4747
```javascript
4848
var bool = isDataType( 'float32' );
@@ -60,6 +60,10 @@ bool = isDataType( 'int32' );
6060

6161
<section class="notes">
6262

63+
## Notes
64+
65+
- The function returns `true` when provided any supported ndarray [data type][@stdlib/ndarray/dtypes] and when provided a [struct][@stdlib/dstructs/struct] constructor describing a fixed-width composite data type.
66+
6367
</section>
6468

6569
<!-- /.notes -->
@@ -139,6 +143,10 @@ bool = isDataType( 'foo' );
139143

140144
<section class="links">
141145

146+
[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/dtypes
147+
148+
[@stdlib/dstructs/struct]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/dstructs/struct
149+
142150
</section>
143151

144152
<!-- /.links -->

lib/node_modules/@stdlib/ndarray/base/assert/is-data-type/lib/main.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,21 @@
2020

2121
// MODULES //
2222

23+
var isStructDataType = require( '@stdlib/ndarray/base/assert/is-struct-data-type' );
2324
var contains = require( '@stdlib/array/base/assert/contains' ).factory;
2425
var dtypes = require( '@stdlib/ndarray/dtypes' );
2526

2627

28+
// VARIABLES //
29+
30+
var isDType = contains( dtypes() );
31+
32+
2733
// MAIN //
2834

2935
/**
3036
* Tests whether an input value is a supported ndarray data type.
3137
*
32-
* @name isDataType
33-
* @type {Function}
3438
* @param {*} v - value to test
3539
* @returns {boolean} boolean indicating whether an input value is a supported ndarray data type
3640
*
@@ -71,7 +75,9 @@ var dtypes = require( '@stdlib/ndarray/dtypes' );
7175
* bool = isDataType( 'foo' );
7276
* // returns false
7377
*/
74-
var isDataType = contains( dtypes() );
78+
function isDataType( v ) {
79+
return ( isDType( v ) || isStructDataType( v ) );
80+
}
7581

7682

7783
// EXPORTS //

lib/node_modules/@stdlib/ndarray/base/assert/is-data-type/test/test.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,20 @@
2121
// MODULES //
2222

2323
var tape = require( 'tape' );
24+
var structFactory = require( '@stdlib/dstructs/struct' );
2425
var isDataType = require( './../lib' );
2526

2627

28+
// VARIABLES //
29+
30+
var Struct = structFactory([
31+
{
32+
'name': 'foo',
33+
'type': 'float64'
34+
}
35+
]);
36+
37+
2738
// TESTS //
2839

2940
tape( 'main export is a function', function test( t ) {
@@ -50,7 +61,10 @@ tape( 'the function returns `true` if provided a supported ndarray data type', f
5061
'uint16',
5162
'uint32',
5263
'uint8',
53-
'uint8c'
64+
'uint8c',
65+
66+
// Custom struct dtypes:
67+
Struct
5468
];
5569
for ( i = 0; i < values.length; i++ ) {
5670
bool = isDataType( values[ i ] );

0 commit comments

Comments
 (0)