Skip to content

Commit b58c04f

Browse files
committed
Auto-generated commit
1 parent 0dc8d41 commit b58c04f

File tree

11 files changed

+246
-14
lines changed

11 files changed

+246
-14
lines changed

.github/.keepalive

Lines changed: 0 additions & 1 deletion
This file was deleted.

README.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ Returns a list of array data types.
7777

7878
```javascript
7979
var out = dtypes();
80-
// e.g., returns [ 'float32', 'float64', 'generic', 'int16', 'int32', 'int8', 'uint16', 'uint32', 'uint8', 'uint8c', 'complex64', 'complex128' ]
80+
// e.g., returns [ 'float32', 'float64', ... ]
8181
```
8282

8383
When not provided a data type "kind", the function returns an array containing the following data types:
@@ -114,6 +114,13 @@ The function supports the following data type kinds:
114114
- `numeric`: numeric data types.
115115
- `all`: all data types.
116116

117+
Additionally, the function supports extending the "kinds" listed above by appending an `_and_generic` suffix to the kind name (e.g., `real_and_generic`).
118+
119+
```javascript
120+
var out = dtypes( 'floating_point_and_generic' );
121+
// returns [...]
122+
```
123+
117124
</section>
118125

119126
<!-- /.usage -->

benchmark/benchmark.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,3 +71,28 @@ bench( pkg+'::kind', function benchmark( b ) {
7171
b.pass( 'benchmark finished' );
7272
b.end();
7373
});
74+
75+
bench( pkg+'::kind,generic', function benchmark( b ) {
76+
var values;
77+
var out;
78+
var i;
79+
80+
values = [
81+
'floating_point_and_generic',
82+
'integer_and_generic'
83+
];
84+
85+
b.tic();
86+
for ( i = 0; i < b.iterations; i++ ) {
87+
out = dtypes( values[ i%values.length ] );
88+
if ( out.length === 0 ) {
89+
b.fail( 'should return a non-empty array' );
90+
}
91+
}
92+
b.toc();
93+
if ( !isStringArray( out ) ) {
94+
b.fail( 'should return an array of strings' );
95+
}
96+
b.pass( 'benchmark finished' );
97+
b.end();
98+
});

dist/index.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/repl.txt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@
3030
- numeric: numeric data types.
3131
- all: all data types.
3232

33+
Additionally, the function supports extending the "kinds" listed above by
34+
appending a '_and_generic' suffix to the kind name (e.g., real_and_generic).
35+
3336
Parameters
3437
----------
3538
kind: string (optional)
@@ -43,9 +46,11 @@
4346
Examples
4447
--------
4548
> var out = {{alias}}()
46-
<Array>
49+
[...]
4750
> out = {{alias}}( 'floating_point' )
48-
<Array>
51+
[...]
52+
> out = {{alias}}( 'floating_point_and_generic' )
53+
[...]
4954

5055
See Also
5156
--------

docs/types/index.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import { DataType, DataTypeKind } from '@stdlib/types/array';
3030
*
3131
* @example
3232
* var list = dtypes();
33-
* // e.g., returns [ 'float32', 'float64', 'generic', 'int16', 'int32', 'int8', 'uint16', 'uint32', 'uint8', 'uint8c', 'complex64', 'complex128' ]
33+
* // e.g., returns [ 'float32', 'float64', ... ]
3434
*
3535
* @example
3636
* var list = dtypes( 'floating_point' );

docs/types/test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import dtypes = require( './index' );
2525
{
2626
dtypes(); // $ExpectType DataType[]
2727
dtypes( 'floating_point' ); // $ExpectType DataType[]
28+
dtypes( 'floating_point_and_generic' ); // $ExpectType DataType[]
2829
}
2930

3031
// The compiler throws an error if the function is provided an unsupported number of arguments...

lib/main.js

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

2121
// MODULES //
2222

23+
var replace = require( '@stdlib/string-base-replace' );
2324
var DTYPES = require( './dtypes.json' );
2425

2526

27+
// VARIABLES //
28+
29+
var RE_SUFFIX = /_and_generic$/;
30+
31+
2632
// MAIN //
2733

2834
/**
@@ -33,19 +39,33 @@ var DTYPES = require( './dtypes.json' );
3339
*
3440
* @example
3541
* var list = dtypes();
36-
* // e.g., returns [ 'float32', 'float64', 'generic', 'int16', 'int32', 'int8', 'uint16', 'uint32', 'uint8', 'uint8c', 'complex64', 'complex128' ]
42+
* // e.g., returns [ 'float32', 'float64', ... ]
3743
*
3844
* @example
3945
* var list = dtypes( 'floating_point' );
4046
* // returns [...]
4147
*/
4248
function dtypes() {
49+
var kind;
4350
var out;
51+
var FLG;
4452
if ( arguments.length === 0 ) {
4553
return DTYPES.all.slice();
4654
}
47-
out = DTYPES[ arguments[ 0 ] ];
48-
return ( out ) ? out.slice() : [];
55+
FLG = false;
56+
kind = arguments[ 0 ];
57+
if ( RE_SUFFIX.test( kind ) ) {
58+
kind = replace( kind, RE_SUFFIX, '' );
59+
if ( kind !== 'all' ) {
60+
FLG = true;
61+
}
62+
}
63+
out = DTYPES[ kind ];
64+
out = ( out ) ? out.slice() : [];
65+
if ( FLG && out.length > 0 ) {
66+
out.push( 'generic' );
67+
}
68+
return out;
4969
}
5070

5171

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
"url": "https://github.com/stdlib-js/stdlib/issues"
3838
},
3939
"dependencies": {
40+
"@stdlib/string-base-replace": "^0.1.1",
4041
"@stdlib/types": "^0.2.0"
4142
},
4243
"devDependencies": {

0 commit comments

Comments
 (0)