Skip to content

Commit ce65fb7

Browse files
committed
Export enumeration constants
1 parent 6fc1e54 commit ce65fb7

File tree

3 files changed

+103
-42
lines changed

3 files changed

+103
-42
lines changed
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
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 setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' );
24+
var objectKeys = require( '@stdlib/utils/keys' );
25+
26+
27+
// MAIN //
28+
29+
/**
30+
* Copies all enumerable own properties from a source object to a target object as non-enumerable read-only properties.
31+
*
32+
* @private
33+
* @param {Object} target - target object
34+
* @param {Object} source - source object
35+
* @returns {Object} modified target object
36+
*
37+
* @example
38+
* var source = {
39+
* 'beep': 'boop'
40+
* };
41+
* var target = {};
42+
*
43+
* var out = assign( target, source );
44+
* // returns <Object>
45+
*
46+
* var bool = ( out === target );
47+
* // returns true
48+
*
49+
* var v = target.beep;
50+
* // returns 'boop'
51+
*/
52+
function assign( target, source ) {
53+
var keys;
54+
var k;
55+
var i;
56+
57+
keys = objectKeys( source );
58+
for ( i = 0; i < keys.length; i++ ) {
59+
k = keys[ i ];
60+
setReadOnly( target, k, source[ k ] );
61+
}
62+
return target;
63+
}
64+
65+
66+
// EXPORTS //
67+
68+
module.exports = assign;

lib/node_modules/@stdlib/strided/dtypes/lib/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,14 @@ var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-propert
3636
var dtypes = require( './main.js' );
3737
var enumeration = require( './enum.js' );
3838
var enumerator = require( './enumerator.js' );
39+
var assign = require( './assign.js' );
3940

4041

4142
// MAIN //
4243

4344
setReadOnly( dtypes, 'enum', enumeration );
4445
setReadOnly( dtypes, 'enumerator', enumerator );
46+
assign( dtypes, enumeration() );
4547

4648

4749
// EXPORTS //

lib/node_modules/@stdlib/strided/dtypes/test/test.js

Lines changed: 33 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,27 @@ var isNonNegativeInteger = require( '@stdlib/assert/is-nonnegative-integer' ).is
2626
var dtypes = require( './../lib' );
2727

2828

29+
// VARIABLES //
30+
31+
// List of native C types which should be supported...
32+
var DTYPES = [
33+
'int8',
34+
'uint8',
35+
'int16',
36+
'uint16',
37+
'int32',
38+
'uint32',
39+
'int64',
40+
'uint64',
41+
42+
'float32',
43+
'float64',
44+
45+
'complex64',
46+
'complex128'
47+
];
48+
49+
2950
// TESTS //
3051

3152
tape( 'main export is a function', function test( t ) {
@@ -61,7 +82,6 @@ tape( 'the function returns a list of strided array data types', function test(
6182

6283
tape( 'attached to the main function is an `enum` method to return an object mapping dtypes to integer values for C inter-operation', function test( t ) {
6384
var obj;
64-
var dt;
6585
var i;
6686

6787
t.strictEqual( hasOwnProp( dtypes, 'enum' ), true, 'has property' );
@@ -70,59 +90,30 @@ tape( 'attached to the main function is an `enum` method to return an object map
7090
obj = dtypes.enum();
7191
t.strictEqual( typeof obj, 'object', 'returns expected value type' );
7292

73-
// List of native C types which should be supported...
74-
dt = [
75-
'int8',
76-
'uint8',
77-
'uint8c',
78-
'int16',
79-
'uint16',
80-
'int32',
81-
'uint32',
82-
'int64',
83-
'uint64',
84-
85-
'float32',
86-
'float64',
87-
88-
'complex64',
89-
'complex128'
90-
];
91-
for ( i = 0; i < dt.length; i++ ) {
92-
t.strictEqual( hasOwnProp( obj, dt[ i ] ), true, 'has property `' + dt[ i ] + '`' );
93-
t.strictEqual( isNonNegativeInteger( obj[ dt[i] ] ), true, 'returns expected value' );
93+
for ( i = 0; i < DTYPES.length; i++ ) {
94+
t.strictEqual( hasOwnProp( obj, DTYPES[ i ] ), true, 'has property `' + DTYPES[ i ] + '`' );
95+
t.strictEqual( isNonNegativeInteger( obj[ DTYPES[i] ] ), true, 'returns expected value' );
9496
}
9597

9698
t.end();
9799
});
98100

99101
tape( 'attached to the main function is an `enumerator` method to the integer value associated with a provided dtype for C inter-operation', function test( t ) {
100-
var dt;
101102
var i;
102103

103104
t.strictEqual( hasOwnProp( dtypes, 'enumerator' ), true, 'has property' );
104105
t.strictEqual( typeof dtypes.enumerator, 'function', 'has method' );
105106

106-
// List of native C types which should be supported...
107-
dt = [
108-
'int8',
109-
'uint8',
110-
'uint8c',
111-
'int16',
112-
'uint16',
113-
'int32',
114-
'uint32',
115-
'int64',
116-
'uint64',
117-
118-
'float32',
119-
'float64',
107+
for ( i = 0; i < DTYPES.length; i++ ) {
108+
t.strictEqual( isNonNegativeInteger( dtypes.enumerator( DTYPES[i] ) ), true, 'returns expected value' );
109+
}
110+
t.end();
111+
});
120112

121-
'complex64',
122-
'complex128'
123-
];
124-
for ( i = 0; i < dt.length; i++ ) {
125-
t.strictEqual( isNonNegativeInteger( dtypes.enumerator( dt[i] ) ), true, 'returns expected value' );
113+
tape( 'attached to the main function are dtype enumeration constants', function test( t ) {
114+
var i;
115+
for ( i = 0; i < DTYPES.length; i++ ) {
116+
t.strictEqual( isNonNegativeInteger( dtypes[ DTYPES[i] ] ), true, 'returns expected value' );
126117
}
127118
t.end();
128119
});

0 commit comments

Comments
 (0)