From cc3988f7ca62e66945a32a22e8c4b9f415d6d6e8 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 17 Jun 2024 23:00:32 +0000 Subject: [PATCH] Auto-generated commit --- CHANGELOG.md | 23 +++++++++++++++++++++++ to-json/README.md | 15 ++++++++++++++- to-json/docs/repl.txt | 1 + to-json/docs/types/index.d.ts | 4 ++-- to-json/examples/index.js | 12 +++++++++++- to-json/lib/ctors.js | 6 ++++-- to-json/lib/main.js | 6 +++++- to-json/test/test.js | 15 ++++++++++----- to-json/test/test.type.js | 15 ++++++++++----- 9 files changed, 80 insertions(+), 17 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4ffeca23..7e13017b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1681,6 +1681,28 @@ This release closes the following issue: +
+ +#### [@stdlib/array/to-json](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/to-json) + +
+ +
+ +##### 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) + +
+ + + +
+ +
+ + +
#### [@stdlib/array/typed](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/typed) @@ -1880,6 +1902,7 @@ A total of 13 people contributed to this release. Thank you to the following con
+- [`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)_ diff --git a/to-json/README.md b/to-json/README.md index 7dd4b37f..4104b885 100644 --- a/to-json/README.md +++ b/to-json/README.md @@ -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. @@ -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] @@ -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 ] ); @@ -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 @@ -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 diff --git a/to-json/docs/repl.txt b/to-json/docs/repl.txt index 3ec0098b..704694f1 100644 --- a/to-json/docs/repl.txt +++ b/to-json/docs/repl.txt @@ -15,6 +15,7 @@ - Uint8ClampedArray - Complex64Array - Complex128Array + - BooleanArray The returned JSON object has the following properties: diff --git a/to-json/docs/types/index.d.ts b/to-json/docs/types/index.d.ts index 751e4157..83b55c95 100644 --- a/to-json/docs/types/index.d.ts +++ b/to-json/docs/types/index.d.ts @@ -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. @@ -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. diff --git a/to-json/examples/index.js b/to-json/examples/index.js index a09d799a..ccd81318 100644 --- a/to-json/examples/index.js +++ b/to-json/examples/index.js @@ -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. @@ -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 ] ); @@ -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 ) ); /* => diff --git a/to-json/lib/ctors.js b/to-json/lib/ctors.js index 739ba8d0..9e967bdf 100644 --- a/to-json/lib/ctors.js +++ b/to-json/lib/ctors.js @@ -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. @@ -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 // @@ -46,7 +47,8 @@ var CTORS = [ [ Uint8Array, 'Uint8Array' ], [ Uint8ClampedArray, 'Uint8ClampedArray' ], [ Complex64Array, 'Complex64Array' ], - [ Complex128Array, 'Complex128Array' ] + [ Complex128Array, 'Complex128Array' ], + [ BooleanArray, 'BooleanArray' ] ]; diff --git a/to-json/lib/main.js b/to-json/lib/main.js index ea786fed..4bb52114 100644 --- a/to-json/lib/main.js +++ b/to-json/lib/main.js @@ -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. @@ -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' ); @@ -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 ) ); } diff --git a/to-json/test/test.js b/to-json/test/test.js index bbb731c3..dfdd4813 100644 --- a/to-json/test/test.js +++ b/to-json/test/test.js @@ -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. @@ -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' ); @@ -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 = [ @@ -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++ ) { @@ -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 = [ @@ -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++ ) { diff --git a/to-json/test/test.type.js b/to-json/test/test.type.js index 2bd2a5c6..0cea582a 100644 --- a/to-json/test/test.type.js +++ b/to-json/test/test.type.js @@ -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. @@ -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' ); @@ -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 = [ @@ -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++ ) { @@ -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 = [ @@ -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++ ) {