Skip to content

Commit f354088

Browse files
committed
Auto-generated commit
1 parent 798fbb0 commit f354088

File tree

84 files changed

+6364
-43
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

84 files changed

+6364
-43
lines changed

base/arraylike2object/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ var obj = arraylike2object( [ 1, 2, 3, 4 ] );
6262
- The returned object has the following properties:
6363

6464
- **data**: reference to the input array.
65+
- **dtype**: input array data type. If unable to resolve the [data type][@stdlib/array/dtype] of the input array, the property value is `null`.
6566
- **accessorProtocol**: `boolean` indicating whether the input uses accessors for getting and setting elements.
6667
- **accessors**: a two-element array whose first element is an accessor for retrieving an array element (i.e., a getter) and whose second element is an accessor for setting an array element (i.e., a setter).
6768

@@ -128,6 +129,8 @@ console.log( obj );
128129

129130
<section class="links">
130131

132+
[@stdlib/array/dtype]: https://github.com/stdlib-js/array/tree/main/dtype
133+
131134
</section>
132135

133136
<!-- /.links -->

base/arraylike2object/docs/repl.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
The returned object has the following properties:
66

77
- data: reference to input array.
8+
- dtype: input array data type.
89
- accessorProtocol: boolean indicating whether the input array uses
910
accessors for getting and setting elements.
1011
- accessors: a two-element array whose first element is an accessor for
@@ -35,6 +36,9 @@
3536
out.data: ArrayLikeObject
3637
Reference to input array.
3738

39+
out.dtype: string|null
40+
Input array data type.
41+
3842
out.accessorProtocol: boolean
3943
Boolean indicating whether the input array use accessors for getting and
4044
setting elements.

base/arraylike2object/docs/types/index.d.ts

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
/* eslint-disable max-lines */
2+
13
/*
24
* @license Apache-2.0
35
*
@@ -285,6 +287,11 @@ interface Float64AccessorObject {
285287
*/
286288
data: Float64Array;
287289

290+
/**
291+
* Data type.
292+
*/
293+
dtype: 'float64';
294+
288295
/**
289296
* Boolean indicating whether the provided array-like object supports the get/set protocol (i.e., uses accessors for getting and setting elements).
290297
*/
@@ -305,6 +312,11 @@ interface Float32AccessorObject {
305312
*/
306313
data: Float32Array;
307314

315+
/**
316+
* Data type.
317+
*/
318+
dtype: 'float32';
319+
308320
/**
309321
* Boolean indicating whether the provided array-like object supports the get/set protocol (i.e., uses accessors for getting and setting elements).
310322
*/
@@ -325,6 +337,11 @@ interface Int32AccessorObject {
325337
*/
326338
data: Int32Array;
327339

340+
/**
341+
* Data type.
342+
*/
343+
dtype: 'int32';
344+
328345
/**
329346
* Boolean indicating whether the provided array-like object supports the get/set protocol (i.e., uses accessors for getting and setting elements).
330347
*/
@@ -345,6 +362,11 @@ interface Int16AccessorObject {
345362
*/
346363
data: Int16Array;
347364

365+
/**
366+
* Data type.
367+
*/
368+
dtype: 'int16';
369+
348370
/**
349371
* Boolean indicating whether the provided array-like object supports the get/set protocol (i.e., uses accessors for getting and setting elements).
350372
*/
@@ -365,6 +387,11 @@ interface Int8AccessorObject {
365387
*/
366388
data: Int8Array;
367389

390+
/**
391+
* Data type.
392+
*/
393+
dtype: 'int8';
394+
368395
/**
369396
* Boolean indicating whether the provided array-like object supports the get/set protocol (i.e., uses accessors for getting and setting elements).
370397
*/
@@ -385,6 +412,11 @@ interface Uint32AccessorObject {
385412
*/
386413
data: Uint32Array;
387414

415+
/**
416+
* Data type.
417+
*/
418+
dtype: 'uint32';
419+
388420
/**
389421
* Boolean indicating whether the provided array-like object supports the get/set protocol (i.e., uses accessors for getting and setting elements).
390422
*/
@@ -405,6 +437,11 @@ interface Uint16AccessorObject {
405437
*/
406438
data: Uint16Array;
407439

440+
/**
441+
* Data type.
442+
*/
443+
dtype: 'uint16';
444+
408445
/**
409446
* Boolean indicating whether the provided array-like object supports the get/set protocol (i.e., uses accessors for getting and setting elements).
410447
*/
@@ -425,6 +462,11 @@ interface Uint8AccessorObject {
425462
*/
426463
data: Uint8Array;
427464

465+
/**
466+
* Data type.
467+
*/
468+
dtype: 'uint8';
469+
428470
/**
429471
* Boolean indicating whether the provided array-like object supports the get/set protocol (i.e., uses accessors for getting and setting elements).
430472
*/
@@ -445,6 +487,11 @@ interface Uint8cAccessorObject {
445487
*/
446488
data: Uint8ClampedArray;
447489

490+
/**
491+
* Data type.
492+
*/
493+
dtype: 'uint8c';
494+
448495
/**
449496
* Boolean indicating whether the provided array-like object supports the get/set protocol (i.e., uses accessors for getting and setting elements).
450497
*/
@@ -465,6 +512,11 @@ interface Complex128AccessorObject {
465512
*/
466513
data: Complex128Array;
467514

515+
/**
516+
* Data type.
517+
*/
518+
dtype: 'complex128';
519+
468520
/**
469521
* Boolean indicating whether the provided array-like object supports the get/set protocol (i.e., uses accessors for getting and setting elements).
470522
*/
@@ -485,6 +537,11 @@ interface Complex64AccessorObject {
485537
*/
486538
data: Complex64Array;
487539

540+
/**
541+
* Data type.
542+
*/
543+
dtype: 'complex64';
544+
488545
/**
489546
* Boolean indicating whether the provided array-like object supports the get/set protocol (i.e., uses accessors for getting and setting elements).
490547
*/
@@ -505,6 +562,11 @@ interface GenericAccessorObject<T> {
505562
*/
506563
data: Array<T>;
507564

565+
/**
566+
* Data type.
567+
*/
568+
dtype: 'generic';
569+
508570
/**
509571
* Boolean indicating whether the provided array-like object supports the get/set protocol (i.e., uses accessors for getting and setting elements).
510572
*/
@@ -525,6 +587,11 @@ interface IndexedAccessorObject<T> {
525587
*/
526588
data: Collection<T>;
527589

590+
/**
591+
* Data type.
592+
*/
593+
dtype: string | null;
594+
528595
/**
529596
* Boolean indicating whether the provided array-like object supports the get/set protocol (i.e., uses accessors for getting and setting elements).
530597
*/
@@ -545,6 +612,11 @@ interface GetSetAccessorObject<T> {
545612
*/
546613
data: AccessorArrayLike<T>;
547614

615+
/**
616+
* Data type.
617+
*/
618+
dtype: string | null;
619+
548620
/**
549621
* Boolean indicating whether the provided array-like object supports the get/set protocol (i.e., uses accessors for getting and setting elements).
550622
*/

base/arraylike2object/lib/main.js

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,12 @@
2020

2121
// MODULES //
2222

23-
var accessors = require( './../../../base/accessors' );
23+
var isAccessorArray = require( './../../../base/assert/is-accessor-array' );
24+
var getter = require( './../../../base/getter' );
25+
var setter = require( './../../../base/setter' );
26+
var accessorGetter = require( './../../../base/accessor-getter' );
27+
var accessorSetter = require( './../../../base/accessor-setter' );
28+
var dtype = require( './../../../dtype' );
2429

2530

2631
// MAIN //
@@ -35,6 +40,7 @@ var accessors = require( './../../../base/accessors' );
3540
* - The returned object has the following properties:
3641
*
3742
* - **data**: reference to the input array.
43+
* - **dtype**: array data type.
3844
* - **accessorProtocol**: `boolean` indicating whether the input array uses accessors for getting and setting elements.
3945
* - **accessors**: a two-element array whose first element is an accessor for retrieving an array element and whose second element is an accessor for setting an array element.
4046
*
@@ -46,11 +52,26 @@ var accessors = require( './../../../base/accessors' );
4652
* // returns {...}
4753
*/
4854
function arraylike2object( x ) {
49-
var o = accessors( x );
55+
var dt = dtype( x );
56+
if ( isAccessorArray( x ) ) {
57+
return {
58+
'data': x,
59+
'dtype': dt,
60+
'accessorProtocol': true,
61+
'accessors': [
62+
accessorGetter( dt ),
63+
accessorSetter( dt )
64+
]
65+
};
66+
}
5067
return {
5168
'data': x,
52-
'accessorProtocol': o.accessorProtocol,
53-
'accessors': o.accessors
69+
'dtype': dt,
70+
'accessorProtocol': false,
71+
'accessors': [
72+
getter( dt ),
73+
setter( dt )
74+
]
5475
};
5576
}
5677

base/arraylike2object/test/test.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,13 @@ tape( 'the function converts an array to a standardized object', function test(
4747

4848
expected = {
4949
'data': x,
50+
'dtype': 'float64',
5051
'accessorProtocol': false
5152
};
5253
actual = arraylike2object( x );
5354

5455
t.strictEqual( actual.data, expected.data, 'returns expected value' );
56+
t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' );
5557
t.strictEqual( actual.accessorProtocol, expected.accessorProtocol, 'returns expected value' );
5658
t.strictEqual( typeof actual.accessors[ 0 ], 'function', 'returns expected value' );
5759
t.strictEqual( actual.accessors[ 0 ].length, 2, 'returns expected value' );
@@ -77,11 +79,13 @@ tape( 'the function converts an array-like object to a standardized object', fun
7779

7880
expected = {
7981
'data': x,
82+
'dtype': null,
8083
'accessorProtocol': false
8184
};
8285
actual = arraylike2object( x );
8386

8487
t.strictEqual( actual.data, expected.data, 'returns expected value' );
88+
t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' );
8589
t.strictEqual( actual.accessorProtocol, expected.accessorProtocol, 'returns expected value' );
8690
t.strictEqual( typeof actual.accessors[ 0 ], 'function', 'returns expected value' );
8791
t.strictEqual( actual.accessors[ 0 ].length, 2, 'returns expected value' );
@@ -105,11 +109,13 @@ tape( 'the function converts an array to a standardized object (data buffer acce
105109

106110
expected = {
107111
'data': x,
112+
'dtype': 'complex64',
108113
'accessorProtocol': true
109114
};
110115
actual = arraylike2object( x );
111116

112117
t.strictEqual( actual.data, expected.data, 'returns expected value' );
118+
t.strictEqual( actual.dtype, expected.dtype, 'returns expected value' );
113119
t.strictEqual( actual.accessorProtocol, expected.accessorProtocol, 'returns expected value' );
114120
t.strictEqual( typeof actual.accessors[ 0 ], 'function', 'returns expected value' );
115121
t.strictEqual( actual.accessors[ 0 ].length, 2, 'returns expected value' );

0 commit comments

Comments
 (0)