Skip to content

Commit adfae95

Browse files
committed
feat: add support for enums
1 parent 7824100 commit adfae95

File tree

3 files changed

+110
-1
lines changed

3 files changed

+110
-1
lines changed
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) 2021 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+
// MAIN //
22+
23+
/**
24+
* Returns an object mapping supported function continuity type strings to enumeration constants.
25+
*
26+
* @private
27+
* @returns {Object} object mapping supported function continuity types to enumeration constants
28+
*
29+
* @example
30+
* var table = enumeration();
31+
* // returns <Object>
32+
*/
33+
function enumeration() {
34+
return {
35+
// Half-maximum:
36+
'half-maximum': 0,
37+
// Left-continuous:
38+
'left-continuous': 1,
39+
// Right-continuous:
40+
'right-continuous': 2,
41+
// Discontinuous:
42+
'discontinuous': 3
43+
};
44+
}
45+
46+
47+
// EXPORTS //
48+
49+
module.exports = enumeration;
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2021 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 objectInverse = require( '@stdlib/utils/object-inverse' );
24+
var enumeration = require( './enum.js' );
25+
26+
27+
// VARIABLES //
28+
29+
var hash = objectInverse( enumeration(), {
30+
'duplicates': false
31+
});
32+
33+
34+
// MAIN //
35+
36+
/**
37+
* Returns the data type string associated with a strided array data type enumeration constant.
38+
*
39+
* @param {integer} dtype - data type enumeration constant
40+
* @returns {(string|null)} data type string or null
41+
*
42+
* @example
43+
* var str2enum = require( '@stdlib/strided/base/dtype-str2enum' );
44+
*
45+
* var v = str2enum( 'float64' );
46+
* // returns <number>
47+
*
48+
* var dt = enum2str( v );
49+
* // returns 'float64'
50+
*/
51+
function enum2str( dtype ) {
52+
var v = hash[ dtype ];
53+
return ( typeof v === 'string' ) ? v : null; // note: we include this guard to prevent walking the prototype chain
54+
}
55+
56+
57+
// EXPORTS //
58+
59+
module.exports = enum2str;

lib/node_modules/@stdlib/math/base/special/heaviside/lib/native.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
// MODULES //
2222

2323
var addon = require( './../src/addon.node' );
24+
var str2enum = require( './str2enum.js' );
2425

2526

2627
// MAIN //
@@ -54,7 +55,7 @@ var addon = require( './../src/addon.node' );
5455
* // returns NaN
5556
*/
5657
function heaviside( x, continuity ) {
57-
return addon( x, continuity );
58+
return addon( x, str2enum( continuity ) );
5859
}
5960

6061

0 commit comments

Comments
 (0)