Skip to content

Commit

Permalink
Auto-generated commit
Browse files Browse the repository at this point in the history
  • Loading branch information
stdlib-bot committed Jun 17, 2024
1 parent 92ceb7e commit cc3988f
Show file tree
Hide file tree
Showing 9 changed files with 80 additions and 17 deletions.
23 changes: 23 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -1681,6 +1681,28 @@ This release closes the following issue:

<!-- /.package -->

<section class="package" id="array-to-json-unreleased">

#### [@stdlib/array/to-json](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/to-json)

<details>

<section class="features">

##### Features

- [`c0a9532`](https://github.com/stdlib-js/stdlib/commit/c0a953262445a079c4ee610fcaa94108b7bbcc77) - add boolean dtype support in `array/to-json` [(#2392)](https://github.com/stdlib-js/stdlib/pull/2392)

</section>

<!-- /.features -->

</details>

</section>

<!-- /.package -->

<section class="package" id="array-typed-unreleased">

#### [@stdlib/array/typed](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/typed)
Expand Down Expand Up @@ -1880,6 +1902,7 @@ A total of 13 people contributed to this release. Thank you to the following con

<details>

- [`c0a9532`](https://github.com/stdlib-js/stdlib/commit/c0a953262445a079c4ee610fcaa94108b7bbcc77) - **feat:** add boolean dtype support in `array/to-json` [(#2392)](https://github.com/stdlib-js/stdlib/pull/2392) _(by Jaysukh Makvana)_
- [`8f4b5c4`](https://github.com/stdlib-js/stdlib/commit/8f4b5c410ffb5d06bb5cce02b84c5f7043c31fa7) - **feat:** add boolean dtype support to `array/typed-ctors` [(#2391)](https://github.com/stdlib-js/stdlib/pull/2391) _(by Jaysukh Makvana, Athan Reines)_
- [`717af94`](https://github.com/stdlib-js/stdlib/commit/717af947ab270abc5422b6d8af7dacd8f0078ca4) - **docs:** update namespace table of contents [(##2389)](#2389) _(by stdlib-bot, Philipp Burckhardt)_
- [`79d01c7`](https://github.com/stdlib-js/stdlib/commit/79d01c7866193a9ff63510316e2ea36cafc72f8a) - **refactor:** special case boolean arrays _(by Athan Reines)_
Expand Down
15 changes: 14 additions & 1 deletion to-json/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
@license Apache-2.0
Copyright (c) 2018 The Stdlib Authors.
Copyright (c) 2024 The Stdlib Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -76,6 +76,7 @@ For guidance on reviving a JSON-serialized typed array, see [`reviver()`][@stdli
- [`Float32Array`][@stdlib/array/float32]
- [`Complex128Array`][@stdlib/array/complex128]
- [`Complex64Array`][@stdlib/array/complex64]
- [`BooleanArray`][@stdlib/array/bool]
- [`Int32Array`][@stdlib/array/int32]
- [`Uint32Array`][@stdlib/array/uint32]
- [`Int16Array`][@stdlib/array/int16]
Expand Down Expand Up @@ -130,6 +131,7 @@ var Uint8Array = require( '@stdlib/array/uint8' );
var Uint8ClampedArray = require( '@stdlib/array/uint8c' );
var Complex64Array = require( '@stdlib/array/complex64' );
var Complex128Array = require( '@stdlib/array/complex128' );
var BooleanArray = require( '@stdlib/array/bool' );
var typedarray2json = require( '@stdlib/array/to-json' );
var arr = new Float64Array( [ 5.0, 3.0 ] );
Expand Down Expand Up @@ -168,6 +170,15 @@ json = typedarray2json( arr );
}
*/
arr = new BooleanArray( [ true, false ] );
json = typedarray2json( arr );
/* returns
{
'type': 'BooleanArray',
'data': [ 1, 0 ]
}
*/
arr = new Int32Array( [ -5, 3 ] );
json = typedarray2json( arr );
/* returns
Expand Down Expand Up @@ -272,6 +283,8 @@ json = typedarray2json( arr );

[@stdlib/array/complex64]: https://github.com/stdlib-js/array/tree/main/complex64

[@stdlib/array/bool]: https://github.com/stdlib-js/array/tree/main/bool

[@stdlib/array/int32]: https://github.com/stdlib-js/array/tree/main/int32

[@stdlib/array/uint32]: https://github.com/stdlib-js/array/tree/main/uint32
Expand Down
1 change: 1 addition & 0 deletions to-json/docs/repl.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
- Uint8ClampedArray
- Complex64Array
- Complex128Array
- BooleanArray

The returned JSON object has the following properties:

Expand Down
4 changes: 2 additions & 2 deletions to-json/docs/types/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* @license Apache-2.0
*
* Copyright (c) 2021 The Stdlib Authors.
* Copyright (c) 2024 The Stdlib Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -25,7 +25,7 @@ import { RealOrComplexTypedArray } from '@stdlib/types/array';
/**
* Typed array data type.
*/
type dtype = 'Float64Array' | 'Float32Array' | 'Int32Array' | 'Uint32Array' | 'Int16Array' | 'Uint16Array' | 'Int8Array' | 'Uint8Array' | 'Uint8ClampedArray' | 'Complex64Array' | 'Complex128Array';
type dtype = 'Float64Array' | 'Float32Array' | 'Int32Array' | 'Uint32Array' | 'Int16Array' | 'Uint16Array' | 'Int8Array' | 'Uint8Array' | 'Uint8ClampedArray' | 'Complex64Array' | 'Complex128Array' | 'BooleanArray';

/**
* JSON representation of typed array.
Expand Down
12 changes: 11 additions & 1 deletion to-json/examples/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2018 The Stdlib Authors.
* Copyright (c) 2024 The Stdlib Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -29,6 +29,7 @@ var Uint8Array = require( './../../uint8' );
var Uint8ClampedArray = require( './../../uint8c' );
var Complex64Array = require( './../../complex64' );
var Complex128Array = require( './../../complex128' );
var BooleanArray = require( './../../bool' );
var typedarray2json = require( './../lib' );

var arr = new Float64Array( [ 5.0, 3.0 ] );
Expand Down Expand Up @@ -67,6 +68,15 @@ console.log( typedarray2json( arr ) );
}
*/

arr = new BooleanArray( [ true, false ] );
console.log( typedarray2json( arr ) );
/* =>
{
'type': 'BooleanArray',
'data': [ 1, 0 ]
}
*/

arr = new Int32Array( [ -5, 3 ] );
console.log( typedarray2json( arr ) );
/* =>
Expand Down
6 changes: 4 additions & 2 deletions to-json/lib/ctors.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2018 The Stdlib Authors.
* Copyright (c) 2024 The Stdlib Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -31,6 +31,7 @@ var Float32Array = require( './../../float32' );
var Float64Array = require( './../../float64' );
var Complex64Array = require( './../../complex64' );
var Complex128Array = require( './../../complex128' );
var BooleanArray = require( './../../bool' );


// MAIN //
Expand All @@ -46,7 +47,8 @@ var CTORS = [
[ Uint8Array, 'Uint8Array' ],
[ Uint8ClampedArray, 'Uint8ClampedArray' ],
[ Complex64Array, 'Complex64Array' ],
[ Complex128Array, 'Complex128Array' ]
[ Complex128Array, 'Complex128Array' ],
[ BooleanArray, 'BooleanArray' ]
];


Expand Down
6 changes: 5 additions & 1 deletion to-json/lib/main.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2018 The Stdlib Authors.
* Copyright (c) 2024 The Stdlib Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -22,8 +22,10 @@

var isTypedArray = require( '@stdlib/assert/is-typed-array' );
var isComplexTypedArray = require( '@stdlib/assert/is-complex-typed-array' );
var isBooleanArray = require( '@stdlib/assert/is-booleanarray' );
var reinterpret64 = require( '@stdlib/strided/base/reinterpret-complex64' );
var reinterpret128 = require( '@stdlib/strided/base/reinterpret-complex128' );
var reinterpretBoolean = require( '@stdlib/strided/base/reinterpret-boolean' );
var format = require( '@stdlib/string/format' );
var typeName = require( './type.js' );

Expand Down Expand Up @@ -63,6 +65,8 @@ function typedarray2json( arr ) {
} else { // arr.BYTES_PER_ELEMENT === 16
data = reinterpret128( arr, 0 );
}
} else if ( isBooleanArray( arr ) ) {
data = reinterpretBoolean( arr, 0 );
} else {
throw new TypeError( format( 'invalid argument. Must provide a typed array. Value: `%s`.', arr ) );
}
Expand Down
15 changes: 10 additions & 5 deletions to-json/test/test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2018 The Stdlib Authors.
* Copyright (c) 2024 The Stdlib Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -36,6 +36,7 @@ var Float32Array = require( './../../float32' );
var Float64Array = require( './../../float64' );
var Complex64Array = require( './../../complex64' );
var Complex128Array = require( './../../complex128' );
var BooleanArray = require( './../../bool' );
var toJSON = require( './../lib' );


Expand Down Expand Up @@ -119,7 +120,8 @@ tape( 'the JSON object includes a typed array type', function test( t ) {
new Uint8Array( 1 ),
new Uint8ClampedArray( 1 ),
new Complex64Array( 1 ),
new Complex128Array( 1 )
new Complex128Array( 1 ),
new BooleanArray( 1 )
];

expected = [
Expand All @@ -133,7 +135,8 @@ tape( 'the JSON object includes a typed array type', function test( t ) {
'Uint8Array',
'Uint8ClampedArray',
'Complex64Array',
'Complex128Array'
'Complex128Array',
'BooleanArray'
];

for ( i = 0; i < values.length; i++ ) {
Expand All @@ -160,7 +163,8 @@ tape( 'the JSON object includes a data property', function test( t ) {
new Uint8Array( [ 8.0 ] ),
new Uint8ClampedArray( [ 9.0 ] ),
new Complex64Array( [ 1.0, 2.0 ] ),
new Complex128Array( [ 1.0, 2.0 ] )
new Complex128Array( [ 1.0, 2.0 ] ),
new BooleanArray( [ true, false ] )
];

expected = [
Expand All @@ -174,7 +178,8 @@ tape( 'the JSON object includes a data property', function test( t ) {
[ 8.0 ],
[ 9.0 ],
[ 1.0, 2.0 ],
[ 1.0, 2.0 ]
[ 1.0, 2.0 ],
[ 1, 0 ]
];

for ( i = 0; i < values.length; i++ ) {
Expand Down
15 changes: 10 additions & 5 deletions to-json/test/test.type.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2018 The Stdlib Authors.
* Copyright (c) 2024 The Stdlib Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -33,6 +33,7 @@ var Float32Array = require( './../../float32' );
var Float64Array = require( './../../float64' );
var Complex64Array = require( './../../complex64' );
var Complex128Array = require( './../../complex128' );
var BooleanArray = require( './../../bool' );
var typeName = require( './../lib/type.js' );


Expand Down Expand Up @@ -60,7 +61,8 @@ tape( 'if provided a typed array, the function returns the closest typed array t
new Uint8Array( [ 5, 3 ] ),
new Uint8ClampedArray( [ 5, 3 ] ),
new Complex64Array( [ 5.0, 3.0 ] ),
new Complex128Array( [ 5.0, 3.0 ] )
new Complex128Array( [ 5.0, 3.0 ] ),
new BooleanArray( [ true, false ] )
];

expected = [
Expand All @@ -74,7 +76,8 @@ tape( 'if provided a typed array, the function returns the closest typed array t
'Uint8Array',
'Uint8ClampedArray',
'Complex64Array',
'Complex128Array'
'Complex128Array',
'BooleanArray'
];

for ( i = 0; i < values.length; i++ ) {
Expand Down Expand Up @@ -104,7 +107,8 @@ tape( 'if provided a typed array from a different realm, the function returns th
new Uint8Array( [ 5, 3 ] ),
new Uint8ClampedArray( [ 5, 3 ] ),
new Complex64Array( [ 5.0, 3.0 ] ),
new Complex128Array( [ 5.0, 3.0 ] )
new Complex128Array( [ 5.0, 3.0 ] ),
new BooleanArray( [ true, false ] )
];

expected = [
Expand All @@ -118,7 +122,8 @@ tape( 'if provided a typed array from a different realm, the function returns th
'Uint8Array',
'Uint8ClampedArray',
'Complex64Array',
'Complex128Array'
'Complex128Array',
'BooleanArray'
];

for ( i = 0; i < values.length; i++ ) {
Expand Down

0 comments on commit cc3988f

Please sign in to comment.