@stdlib/array-to-fancy 0.1.1 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- /**
1
+ /*
2
2
  * @license Apache-2.0
3
3
  *
4
4
  * Copyright (c) 2024 The Stdlib Authors.
@@ -20,7 +20,7 @@
20
20
 
21
21
  /// <reference types="@stdlib/types"/>
22
22
 
23
- import { Collection, ArrayLike, AccessorArrayLike, Complex128Array, Complex64Array, ArrayIndexObject } from '@stdlib/types/array';
23
+ import { Collection, ArrayLike, AccessorArrayLike, ComplexTypedArray, TypedArray, BooleanTypedArray, IndexArrayObject } from '@stdlib/types/array';
24
24
  import ArrayIndex = require( '@stdlib/array-index' );
25
25
 
26
26
  /**
@@ -33,7 +33,7 @@ interface Cache {
33
33
  * @param id - identifier
34
34
  * @returns index data
35
35
  */
36
- get( id: any ): ArrayIndexObject | null;
36
+ get( id: any ): IndexArrayObject | null;
37
37
  }
38
38
 
39
39
  /**
@@ -74,17 +74,6 @@ interface Array2Fancy {
74
74
  *
75
75
  * var v = y[ ':' ];
76
76
  * // returns <Float64Array>[ 1.0, 2.0, 3.0, 4.0 ]
77
- */
78
- ( x: Float64Array, options?: Options ): Float64Array;
79
-
80
- /**
81
- * Converts an array to an object supporting fancy indexing.
82
- *
83
- * @param x - input array
84
- * @param options - function options
85
- * @param options.strict - boolean indicating whether to enforce strict bounds checking
86
- * @param options.cache - cache for resolving array index objects
87
- * @returns fancy array
88
77
  *
89
78
  * @example
90
79
  * var Float32Array = require( '@stdlib/array-float32' );
@@ -96,17 +85,6 @@ interface Array2Fancy {
96
85
  *
97
86
  * var v = y[ ':' ];
98
87
  * // returns <Float32Array>[ 1.0, 2.0, 3.0, 4.0 ]
99
- */
100
- ( x: Float32Array, options?: Options ): Float32Array;
101
-
102
- /**
103
- * Converts an array to an object supporting fancy indexing.
104
- *
105
- * @param x - input array
106
- * @param options - function options
107
- * @param options.strict - boolean indicating whether to enforce strict bounds checking
108
- * @param options.cache - cache for resolving array index objects
109
- * @returns fancy array
110
88
  *
111
89
  * @example
112
90
  * var Complex128Array = require( '@stdlib/array-complex128' );
@@ -118,17 +96,6 @@ interface Array2Fancy {
118
96
  *
119
97
  * var v = y[ ':' ];
120
98
  * // returns <Complex128Array>[ 1.0, 2.0, 3.0, 4.0 ]
121
- */
122
- ( x: Complex128Array, options?: Options ): Complex128Array;
123
-
124
- /**
125
- * Converts an array to an object supporting fancy indexing.
126
- *
127
- * @param x - input array
128
- * @param options - function options
129
- * @param options.strict - boolean indicating whether to enforce strict bounds checking
130
- * @param options.cache - cache for resolving array index objects
131
- * @returns fancy array
132
99
  *
133
100
  * @example
134
101
  * var Complex64Array = require( '@stdlib/array-complex64' );
@@ -140,17 +107,6 @@ interface Array2Fancy {
140
107
  *
141
108
  * var v = y[ ':' ];
142
109
  * // returns <Complex64Array>[ 1.0, 2.0, 3.0, 4.0 ]
143
- */
144
- ( x: Complex64Array, options?: Options ): Complex64Array;
145
-
146
- /**
147
- * Converts an array to an object supporting fancy indexing.
148
- *
149
- * @param x - input array
150
- * @param options - function options
151
- * @param options.strict - boolean indicating whether to enforce strict bounds checking
152
- * @param options.cache - cache for resolving array index objects
153
- * @returns fancy array
154
110
  *
155
111
  * @example
156
112
  * var Int32Array = require( '@stdlib/array-int32' );
@@ -162,17 +118,6 @@ interface Array2Fancy {
162
118
  *
163
119
  * var v = y[ ':' ];
164
120
  * // returns <Int32Array>[ 1, 2, 3, 4 ]
165
- */
166
- ( x: Int32Array, options?: Options ): Int32Array;
167
-
168
- /**
169
- * Converts an array to an object supporting fancy indexing.
170
- *
171
- * @param x - input array
172
- * @param options - function options
173
- * @param options.strict - boolean indicating whether to enforce strict bounds checking
174
- * @param options.cache - cache for resolving array index objects
175
- * @returns fancy array
176
121
  *
177
122
  * @example
178
123
  * var Int16Array = require( '@stdlib/array-int16' );
@@ -184,17 +129,6 @@ interface Array2Fancy {
184
129
  *
185
130
  * var v = y[ ':' ];
186
131
  * // returns <Int16Array>[ 1, 2, 3, 4 ]
187
- */
188
- ( x: Int16Array, options?: Options ): Int16Array;
189
-
190
- /**
191
- * Converts an array to an object supporting fancy indexing.
192
- *
193
- * @param x - input array
194
- * @param options - function options
195
- * @param options.strict - boolean indicating whether to enforce strict bounds checking
196
- * @param options.cache - cache for resolving array index objects
197
- * @returns fancy array
198
132
  *
199
133
  * @example
200
134
  * var Int8Array = require( '@stdlib/array-int8' );
@@ -206,17 +140,6 @@ interface Array2Fancy {
206
140
  *
207
141
  * var v = y[ ':' ];
208
142
  * // returns <Int8Array>[ 1, 2, 3, 4 ]
209
- */
210
- ( x: Int8Array, options?: Options ): Int8Array;
211
-
212
- /**
213
- * Converts an array to an object supporting fancy indexing.
214
- *
215
- * @param x - input array
216
- * @param options - function options
217
- * @param options.strict - boolean indicating whether to enforce strict bounds checking
218
- * @param options.cache - cache for resolving array index objects
219
- * @returns fancy array
220
143
  *
221
144
  * @example
222
145
  * var Uint32Array = require( '@stdlib/array-uint32' );
@@ -228,17 +151,6 @@ interface Array2Fancy {
228
151
  *
229
152
  * var v = y[ ':' ];
230
153
  * // returns <Uint32Array>[ 1, 2, 3, 4 ]
231
- */
232
- ( x: Uint32Array, options?: Options ): Uint32Array;
233
-
234
- /**
235
- * Converts an array to an object supporting fancy indexing.
236
- *
237
- * @param x - input array
238
- * @param options - function options
239
- * @param options.strict - boolean indicating whether to enforce strict bounds checking
240
- * @param options.cache - cache for resolving array index objects
241
- * @returns fancy array
242
154
  *
243
155
  * @example
244
156
  * var Uint16Array = require( '@stdlib/array-uint16' );
@@ -250,17 +162,6 @@ interface Array2Fancy {
250
162
  *
251
163
  * var v = y[ ':' ];
252
164
  * // returns <Uint16Array>[ 1, 2, 3, 4 ]
253
- */
254
- ( x: Uint16Array, options?: Options ): Uint16Array;
255
-
256
- /**
257
- * Converts an array to an object supporting fancy indexing.
258
- *
259
- * @param x - input array
260
- * @param options - function options
261
- * @param options.strict - boolean indicating whether to enforce strict bounds checking
262
- * @param options.cache - cache for resolving array index objects
263
- * @returns fancy array
264
165
  *
265
166
  * @example
266
167
  * var Uint8Array = require( '@stdlib/array-uint8' );
@@ -272,17 +173,6 @@ interface Array2Fancy {
272
173
  *
273
174
  * var v = y[ ':' ];
274
175
  * // returns <Uint8Array>[ 1, 2, 3, 4 ]
275
- */
276
- ( x: Uint8Array, options?: Options ): Uint8Array;
277
-
278
- /**
279
- * Converts an array to an object supporting fancy indexing.
280
- *
281
- * @param x - input array
282
- * @param options - function options
283
- * @param options.strict - boolean indicating whether to enforce strict bounds checking
284
- * @param options.cache - cache for resolving array index objects
285
- * @returns fancy array
286
176
  *
287
177
  * @example
288
178
  * var Uint8ClampedArray = require( '@stdlib/array-uint8c' );
@@ -295,7 +185,7 @@ interface Array2Fancy {
295
185
  * var v = y[ ':' ];
296
186
  * // returns <Uint8ClampedArray>[ 1, 2, 3, 4 ]
297
187
  */
298
- ( x: Uint8ClampedArray, options?: Options ): Uint8ClampedArray;
188
+ <T extends TypedArray | ComplexTypedArray | BooleanTypedArray>( x: T, options?: Options ): T;
299
189
 
300
190
  /**
301
191
  * Converts an array to an object supporting fancy indexing.
package/lib/ctor.js CHANGED
@@ -27,6 +27,7 @@
27
27
  * @param {Function} array2fancy - function for creating a proxied array
28
28
  * @param {Object} opts - options
29
29
  * @param {boolean} opts.strict - boolean indicating whether to perform strict bounds checking
30
+ * @param {Function} opts.cache - cache for resolving array index objects
30
31
  * @returns {Function} handler
31
32
  */
32
33
  function factory( array2fancy, opts ) {
package/lib/factory.js CHANGED
@@ -20,6 +20,7 @@
20
20
 
21
21
  // MODULES //
22
22
 
23
+ var isCollection = require( '@stdlib/assert-is-collection' );
23
24
  var isArrayLike = require( '@stdlib/assert-is-array-like' );
24
25
  var Proxy = require( '@stdlib/proxy-ctor' );
25
26
  var arraylike2object = require( '@stdlib/array-base-arraylike2object' );
@@ -124,7 +125,7 @@ function factory() {
124
125
  var arr;
125
126
  var dt;
126
127
  var o;
127
- if ( !isArrayLike( x ) ) {
128
+ if ( !isArrayLike( x ) && !isCollection( x ) ) {
128
129
  throw new TypeError( format( 'invalid argument. First argument must be array-like. Value: `%s`.', x ) );
129
130
  }
130
131
  if ( hasProxySupport ) {
@@ -34,6 +34,7 @@ var resolveIndex = require( './resolve_index.js' );
34
34
  * @param {Object} ctx - context object
35
35
  * @param {Function} ctx.getter - accessor for retrieving array elements
36
36
  * @param {boolean} ctx.strict - boolean indicating whether to enforce strict bounds checking
37
+ * @throws {RangeError} index exceeds array bounds
37
38
  * @returns {*} result
38
39
  */
39
40
  function getElement( target, property, ctx ) {
@@ -36,7 +36,6 @@ var prop2array = require( './prop2array.js' );
36
36
  * @param {Object} target - target object
37
37
  * @param {string} property - index string
38
38
  * @param {Object} ctx - context object
39
- * @param {boolean} ctx.strict - boolean indicating whether to enforce strict bounds checking
40
39
  * @param {Object} ctx.cache - cache for resolving array index objects
41
40
  * @param {Function} ctx.postGetArray - function to process a retrieved array
42
41
  * @throws {Error} invalid array index
package/lib/set.js CHANGED
@@ -23,6 +23,8 @@
23
23
  var isString = require( '@stdlib/assert-is-string' ).isPrimitive;
24
24
  var hasProperty = require( '@stdlib/assert-has-property' );
25
25
  var isIntegerString = require( './is_integer_string.js' );
26
+ var isArrayIndexString = require( './is_array_index_string.js' );
27
+ var setElements = require( './set_elements.js' );
26
28
  var setElement = require( './set_element.js' );
27
29
  var setValue = require( './set_value.js' );
28
30
  var setSlice = require( './set_slice.js' );
@@ -35,7 +37,6 @@ var setSlice = require( './set_slice.js' );
35
37
  *
36
38
  * @private
37
39
  * @param {Object} ctx - context object
38
- * @param {Function} ctx.setter - accessor for setting array elements
39
40
  * @param {string} ctx.dtype - array data type
40
41
  * @param {boolean} ctx.strict - boolean indicating whether to enforce strict bounds checking
41
42
  * @param {Function} ctx.validator - function for validating new values
@@ -68,9 +69,12 @@ function factory( ctx ) {
68
69
  if ( isIntegerString( property ) ) {
69
70
  return setElement( target, property, value, ctx );
70
71
  }
71
- if ( hasProperty( property ) || !isString( property ) ) {
72
+ if ( hasProperty( target, property ) || !isString( property ) ) {
72
73
  return setValue( target, property, value, ctx );
73
74
  }
75
+ if ( isArrayIndexString( property ) ) {
76
+ return setElements( target, property, value, ctx );
77
+ }
74
78
  out = setSlice( target, property, value, receiver, ctx );
75
79
  if ( out ) {
76
80
  return out;
@@ -40,6 +40,7 @@ var resolveIndex = require( './resolve_index.js' );
40
40
  * @param {(Function|null)} ctx.preSetElement - function for normalizing new values (if necessary)
41
41
  * @throws {TypeError} assigned value cannot be safely cast to the target array data type
42
42
  * @throws {TypeError} target array must have a supported data type
43
+ * @throws {RangeError} index exceeds array bounds
43
44
  * @returns {boolean} boolean indicating whether assignment succeeded
44
45
  */
45
46
  function setElement( target, property, value, ctx ) {
@@ -0,0 +1,130 @@
1
+ /**
2
+ * @license Apache-2.0
3
+ *
4
+ * Copyright (c) 2024 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 isMostlySafeCast = require( '@stdlib/array-base-assert-is-mostly-safe-data-type-cast' );
24
+ var isRealDataType = require( '@stdlib/array-base-assert-is-real-data-type' );
25
+ var isComplexDataType = require( '@stdlib/array-base-assert-is-complex-floating-point-data-type' );
26
+ var isCollection = require( '@stdlib/assert-is-collection' );
27
+ var scalar2array = require( '@stdlib/array-from-scalar' );
28
+ var dtype = require( '@stdlib/array-dtype' );
29
+ var put = require( '@stdlib/array-put' );
30
+ var place = require( '@stdlib/array-place' );
31
+ var convert = require( '@stdlib/array-convert' );
32
+ var where = require( '@stdlib/array-base-where' ).assign;
33
+ var format = require( '@stdlib/string-format' );
34
+ var prop2array = require( './prop2array.js' );
35
+ var errMessage = require( './error_message.js' );
36
+
37
+
38
+ // MAIN //
39
+
40
+ /**
41
+ * Replaces the elements specified by an array index.
42
+ *
43
+ * @private
44
+ * @param {Object} target - target object
45
+ * @param {string} property - index string
46
+ * @param {*} value - new value(s)
47
+ * @param {Object} ctx - context object
48
+ * @param {string} ctx.dtype - array data type
49
+ * @param {Object} ctx.cache - cache for resolving array index objects
50
+ * @param {Function} ctx.validator - function for validating new values
51
+ * @param {(Function|null)} ctx.preSetElement - function for normalizing new values (if necessary)
52
+ * @throws {Error} invalid array index
53
+ * @throws {RangeError} index exceeds array bounds
54
+ * @throws {Error} assigned value must be broadcast compatible with target array selection
55
+ * @throws {TypeError} assigned value cannot be safely cast to the target array data type
56
+ * @throws {TypeError} target array must have a supported data type
57
+ * @returns {boolean} boolean indicating whether assignment succeeded
58
+ */
59
+ function setElements( target, property, value, ctx ) {
60
+ var tdt;
61
+ var vdt;
62
+ var idx;
63
+ var err;
64
+ var v;
65
+
66
+ idx = prop2array( property, ctx.cache );
67
+ tdt = ctx.dtype || 'generic';
68
+ if ( isCollection( value ) ) {
69
+ // When handling collections, we delegate to implementation APIs (see below) to perform argument validation (e.g., ensuring a (mostly) safe cast, broadcast compatibility, etc), so we just reassign the value here:
70
+ v = value;
71
+ } else {
72
+ // When provided a "scalar", we need to check whether the value can be safely cast to the target array data type:
73
+ err = ctx.validator( value, tdt );
74
+ if ( err ) {
75
+ throw err;
76
+ }
77
+ if ( ctx.preSetElement ) {
78
+ v = ctx.preSetElement( value );
79
+ } else {
80
+ v = value;
81
+ }
82
+ // As the scalar can be safely cast, convert the scalar to an array having the same data type as the target array to allow for broadcasting during assignment:
83
+ v = scalar2array( v, tdt );
84
+ vdt = tdt;
85
+ }
86
+ if ( idx.type === 'int' ) {
87
+ try {
88
+ put( target, idx.data, v ); // note: defer to `put` for ensuring a mostly safe cast
89
+ } catch ( err ) {
90
+ throw new err.constructor( errMessage( err.message ) );
91
+ }
92
+ return true;
93
+ }
94
+ if ( idx.type === 'bool' ) {
95
+ try {
96
+ place( target, idx.data, v, {
97
+ 'mode': 'strict_broadcast'
98
+ });
99
+ } catch ( err ) {
100
+ throw new err.constructor( errMessage( err.message ) );
101
+ }
102
+ return true;
103
+ }
104
+ if ( vdt === void 0 ) {
105
+ vdt = dtype( value ) || 'generic';
106
+ }
107
+ // Safe casts are always allowed and allow same kind casts (i.e., downcasts) only when the target array data type is floating-point...
108
+ if ( !isMostlySafeCast( vdt, tdt ) ) {
109
+ throw new TypeError( format( 'invalid operation. Assigned value cannot be safely cast to the target array data type. Data types: [%s, %s].', vdt, tdt ) );
110
+ }
111
+ // When performing a real-to-complex assignment, interpret the real-valued array as containing real components with implied imaginary components equal to zero and explicitly convert to a complex-valued array...
112
+ if ( isComplexDataType( tdt ) && isRealDataType( vdt ) ) {
113
+ v = convert( v, tdt );
114
+ }
115
+ if ( idx.type === 'mask' ) {
116
+ // NOTE: we intentionally deviate from boolean array indexing here and interpret the mask as applying to both the target and values array, thus requiring that the assigned value array be broadcast compatible with the target array and NOT just the selected elements as in boolean array indexing
117
+ try {
118
+ where( idx.data, target, v, target, 1, 0 );
119
+ } catch ( err ) {
120
+ throw new err.constructor( errMessage( err.message ) );
121
+ }
122
+ return true;
123
+ }
124
+ throw new Error( format( 'invalid operation. Unrecognized array index type. Value: `%s`.', idx.type ) );
125
+ }
126
+
127
+
128
+ // EXPORTS //
129
+
130
+ module.exports = setElements;
package/lib/set_slice.js CHANGED
@@ -40,6 +40,7 @@ var errMessage = require( './error_message.js' );
40
40
  * @param {Object} ctx - context object
41
41
  * @param {string} ctx.dtype - array data type
42
42
  * @param {boolean} ctx.strict - boolean indicating whether to enforce strict bounds checking
43
+ * @param {Function} ctx.validator - function for validating new values
43
44
  * @throws {Error} invalid slice operation
44
45
  * @throws {RangeError} slice exceeds array bounds
45
46
  * @throws {Error} assigned value must be broadcast compatible with target array view
@@ -67,14 +68,14 @@ function setSlice( target, property, value, receiver, ctx ) {
67
68
  throw err;
68
69
  }
69
70
  // As the scalar can be safely cast, convert the scalar to an array having the same data type as the target array to allow for broadcasting during slice assignment:
70
- v = scalar2array( value, ctx.dtype );
71
+ v = scalar2array( value, ctx.dtype || 'generic' );
71
72
  }
72
73
  try {
73
74
  sliceAssign( v, receiver, s, ctx.strict );
74
- return true;
75
75
  } catch ( err ) {
76
76
  throw new err.constructor( errMessage( err.message ) );
77
77
  }
78
+ return true;
78
79
  }
79
80
 
80
81
 
package/lib/validator.js CHANGED
@@ -22,10 +22,12 @@
22
22
 
23
23
  var isNumber = require( '@stdlib/assert-is-number' ).isPrimitive;
24
24
  var isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive;
25
+ var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;
25
26
  var isComplexLike = require( '@stdlib/assert-is-complex-like' );
26
27
  var isRealFloatingDataType = require( '@stdlib/array-base-assert-is-real-floating-point-data-type' );
27
28
  var isUnsignedIntegerDataType = require( '@stdlib/array-base-assert-is-unsigned-integer-data-type' );
28
29
  var isSignedIntegerDataType = require( '@stdlib/array-base-assert-is-signed-integer-data-type' );
30
+ var isBooleanDataType = require( '@stdlib/array-base-assert-is-boolean-data-type' );
29
31
  var isSafeCast = require( '@stdlib/array-base-assert-is-safe-data-type-cast' );
30
32
  var minDataType = require( '@stdlib/array-min-dtype' );
31
33
  var minSignedIntegerDataType = require( '@stdlib/array-base-min-signed-integer-dtype' );
@@ -52,7 +54,32 @@ function validateGeneric() {
52
54
  }
53
55
 
54
56
  /**
55
- * Verifies whether a provided value can be safely assigned to an element in an array have a real-valued floating-point data type.
57
+ * Verifies whether a provided value can be safely assigned to an element in an array having a boolean data type.
58
+ *
59
+ * @private
60
+ * @param {*} value - input value
61
+ * @param {string} dtype - array data type
62
+ * @returns {(Error|null)} error object or null
63
+ *
64
+ * @example
65
+ * var err = validateBoolean( true, 'bool' );
66
+ * // returns null
67
+ *
68
+ * @example
69
+ * var Complex128 = require( '@stdlib/complex-float64-ctor' );
70
+ *
71
+ * var err = validateBoolean( new Complex128( 5.0, 6.0 ), 'bool' );
72
+ * // returns <TypeError>
73
+ */
74
+ function validateBoolean( value, dtype ) {
75
+ if ( isBoolean( value ) ) {
76
+ return null;
77
+ }
78
+ return new TypeError( format( 'invalid operation. Assigned value cannot be safely cast to the target array data type. Data types: [%s, %s].', typeof value, dtype ) );
79
+ }
80
+
81
+ /**
82
+ * Verifies whether a provided value can be safely assigned to an element in an array having a real-valued floating-point data type.
56
83
  *
57
84
  * @private
58
85
  * @param {*} value - input value
@@ -64,7 +91,7 @@ function validateGeneric() {
64
91
  * // returns null
65
92
  *
66
93
  * @example
67
- * var Complex128 = require( '@stdlib/complex-float64' );
94
+ * var Complex128 = require( '@stdlib/complex-float64-ctor' );
68
95
  *
69
96
  * var err = validateRealFloating( new Complex128( 5.0, 6.0 ), 'float64' );
70
97
  * // returns <TypeError>
@@ -80,7 +107,7 @@ function validateRealFloating( value, dtype ) {
80
107
  }
81
108
 
82
109
  /**
83
- * Verifies whether a provided value can be safely assigned to an element in an array have a complex-valued floating-point data type.
110
+ * Verifies whether a provided value can be safely assigned to an element in an array having a complex-valued floating-point data type.
84
111
  *
85
112
  * @private
86
113
  * @param {*} value - input value
@@ -88,7 +115,7 @@ function validateRealFloating( value, dtype ) {
88
115
  * @returns {(Error|null)} error object or null
89
116
  *
90
117
  * @example
91
- * var Complex128 = require( '@stdlib/complex-float64' );
118
+ * var Complex128 = require( '@stdlib/complex-float64-ctor' );
92
119
  *
93
120
  * var err = validateComplexFloating( new Complex128( 5.0, 6.0 ), 'complex128' );
94
121
  * // returns null
@@ -105,7 +132,7 @@ function validateComplexFloating( value, dtype ) {
105
132
  }
106
133
 
107
134
  /**
108
- * Verifies whether a provided value can be safely assigned to an element in an array have a signed integer data type.
135
+ * Verifies whether a provided value can be safely assigned to an element in an array having a signed integer data type.
109
136
  *
110
137
  * @private
111
138
  * @param {*} value - input value
@@ -139,7 +166,7 @@ function validateSignedInteger( value, dtype ) {
139
166
  }
140
167
 
141
168
  /**
142
- * Verifies whether a provided value can be safely assigned to an element in an array have an unsigned integer data type.
169
+ * Verifies whether a provided value can be safely assigned to an element in an array having an unsigned integer data type.
143
170
  *
144
171
  * @private
145
172
  * @param {*} value - input value
@@ -201,6 +228,9 @@ function validator( dtype ) {
201
228
  if ( isSignedIntegerDataType( dtype ) ) {
202
229
  return validateSignedInteger;
203
230
  }
231
+ if ( isBooleanDataType( dtype ) ) {
232
+ return validateBoolean;
233
+ }
204
234
  // Case: isComplexDataType( dtype ) === true
205
235
  return validateComplexFloating;
206
236
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stdlib/array-to-fancy",
3
- "version": "0.1.1",
3
+ "version": "0.2.1",
4
4
  "description": "Convert an array to an object supporting fancy indexing.",
5
5
  "license": "Apache-2.0",
6
6
  "author": {
@@ -31,44 +31,52 @@
31
31
  },
32
32
  "dependencies": {
33
33
  "@stdlib/array-base-arraylike2object": "^0.2.1",
34
+ "@stdlib/array-base-assert-is-boolean-data-type": "^0.0.1",
34
35
  "@stdlib/array-base-assert-is-complex-floating-point-data-type": "^0.2.1",
36
+ "@stdlib/array-base-assert-is-mostly-safe-data-type-cast": "^0.2.2",
37
+ "@stdlib/array-base-assert-is-real-data-type": "^0.2.1",
35
38
  "@stdlib/array-base-assert-is-real-floating-point-data-type": "^0.2.1",
36
- "@stdlib/array-base-assert-is-safe-data-type-cast": "^0.3.1",
39
+ "@stdlib/array-base-assert-is-safe-data-type-cast": "^0.3.2",
37
40
  "@stdlib/array-base-assert-is-signed-integer-data-type": "^0.2.1",
38
41
  "@stdlib/array-base-assert-is-unsigned-integer-data-type": "^0.2.1",
39
42
  "@stdlib/array-base-fancy-slice": "^0.3.1",
40
43
  "@stdlib/array-base-fancy-slice-assign": "^0.2.1",
41
- "@stdlib/array-base-min-signed-integer-dtype": "^0.2.1",
42
- "@stdlib/array-from-scalar": "^0.2.1",
43
- "@stdlib/array-index": "^0.2.1",
44
- "@stdlib/array-min-dtype": "^0.2.1",
45
- "@stdlib/array-mskfilter": "^0.1.1",
46
- "@stdlib/array-mskreject": "^0.1.1",
47
- "@stdlib/array-take": "^0.1.1",
48
- "@stdlib/assert-has-own-property": "^0.2.1",
49
- "@stdlib/assert-has-property": "^0.2.1",
50
- "@stdlib/assert-is-array-like": "^0.2.1",
51
- "@stdlib/assert-is-boolean": "^0.2.1",
52
- "@stdlib/assert-is-collection": "^0.2.1",
53
- "@stdlib/assert-is-complex-like": "^0.2.1",
54
- "@stdlib/assert-is-function": "^0.2.1",
55
- "@stdlib/assert-is-integer": "^0.2.1",
56
- "@stdlib/assert-is-method-in": "^0.2.1",
57
- "@stdlib/assert-is-number": "^0.2.1",
58
- "@stdlib/assert-is-plain-object": "^0.2.1",
59
- "@stdlib/assert-is-string": "^0.2.1",
60
- "@stdlib/complex-dtype": "^0.2.1",
61
- "@stdlib/ndarray-base-normalize-index": "^0.2.1",
62
- "@stdlib/object-assign": "^0.2.1",
63
- "@stdlib/proxy-ctor": "^0.2.1",
64
- "@stdlib/slice-base-seq2slice": "^0.2.1",
65
- "@stdlib/slice-base-str2slice": "^0.2.1",
66
- "@stdlib/string-base-replace": "^0.2.1",
67
- "@stdlib/string-base-starts-with": "^0.2.1",
68
- "@stdlib/string-base-trim": "^0.2.1",
69
- "@stdlib/string-format": "^0.2.1",
70
- "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.1",
71
- "@stdlib/error-tools-fmtprodmsg": "^0.2.1"
44
+ "@stdlib/array-base-min-signed-integer-dtype": "^0.2.2",
45
+ "@stdlib/array-base-where": "^0.0.2",
46
+ "@stdlib/array-convert": "^0.3.0",
47
+ "@stdlib/array-dtype": "^0.3.0",
48
+ "@stdlib/array-from-scalar": "^0.3.0",
49
+ "@stdlib/array-index": "^0.3.0",
50
+ "@stdlib/array-min-dtype": "^0.3.0",
51
+ "@stdlib/array-mskfilter": "^0.1.2",
52
+ "@stdlib/array-mskreject": "^0.1.2",
53
+ "@stdlib/array-place": "^0.1.1",
54
+ "@stdlib/array-put": "^0.0.2",
55
+ "@stdlib/array-take": "^0.1.2",
56
+ "@stdlib/assert-has-own-property": "^0.2.2",
57
+ "@stdlib/assert-has-property": "^0.2.2",
58
+ "@stdlib/assert-is-array-like": "^0.2.2",
59
+ "@stdlib/assert-is-boolean": "^0.2.2",
60
+ "@stdlib/assert-is-collection": "^0.2.2",
61
+ "@stdlib/assert-is-complex-like": "^0.2.2",
62
+ "@stdlib/assert-is-function": "^0.2.2",
63
+ "@stdlib/assert-is-integer": "^0.2.2",
64
+ "@stdlib/assert-is-method-in": "^0.2.2",
65
+ "@stdlib/assert-is-number": "^0.2.2",
66
+ "@stdlib/assert-is-plain-object": "^0.2.2",
67
+ "@stdlib/assert-is-string": "^0.2.2",
68
+ "@stdlib/complex-dtype": "^0.2.2",
69
+ "@stdlib/ndarray-base-normalize-index": "^0.2.2",
70
+ "@stdlib/object-assign": "^0.2.2",
71
+ "@stdlib/proxy-ctor": "^0.2.2",
72
+ "@stdlib/slice-base-seq2slice": "^0.2.2",
73
+ "@stdlib/slice-base-str2slice": "^0.2.2",
74
+ "@stdlib/string-base-replace": "^0.2.2",
75
+ "@stdlib/string-base-starts-with": "^0.2.2",
76
+ "@stdlib/string-base-trim": "^0.2.2",
77
+ "@stdlib/string-format": "^0.2.2",
78
+ "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.2",
79
+ "@stdlib/error-tools-fmtprodmsg": "^0.2.2"
72
80
  },
73
81
  "devDependencies": {},
74
82
  "engines": {