From 7cf3195ca6bc77f3534e0fc8199731e61f74b27a Mon Sep 17 00:00:00 2001 From: headlessNode Date: Thu, 26 Mar 2026 00:42:32 +0500 Subject: [PATCH 1/4] feat: add blas/ext/base/gconjoin --- .../@stdlib/blas/ext/base/gconjoin/README.md | 187 +++++++++++++ .../ext/base/gconjoin/benchmark/benchmark.js | 97 +++++++ .../gconjoin/benchmark/benchmark.ndarray.js | 97 +++++++ .../blas/ext/base/gconjoin/docs/repl.txt | 95 +++++++ .../ext/base/gconjoin/docs/types/index.d.ts | 105 +++++++ .../blas/ext/base/gconjoin/docs/types/test.ts | 263 ++++++++++++++++++ .../blas/ext/base/gconjoin/examples/index.js | 30 ++ .../blas/ext/base/gconjoin/lib/accessors.js | 113 ++++++++ .../blas/ext/base/gconjoin/lib/index.js | 57 ++++ .../blas/ext/base/gconjoin/lib/main.js | 54 ++++ .../blas/ext/base/gconjoin/lib/ndarray.js | 109 ++++++++ .../blas/ext/base/gconjoin/package.json | 69 +++++ .../blas/ext/base/gconjoin/test/test.js | 38 +++ .../blas/ext/base/gconjoin/test/test.main.js | 153 ++++++++++ .../ext/base/gconjoin/test/test.ndarray.js | 159 +++++++++++ 15 files changed, 1626 insertions(+) create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gconjoin/README.md create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gconjoin/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gconjoin/benchmark/benchmark.ndarray.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gconjoin/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gconjoin/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gconjoin/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gconjoin/examples/index.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gconjoin/lib/accessors.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gconjoin/lib/index.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gconjoin/lib/main.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gconjoin/lib/ndarray.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gconjoin/package.json create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gconjoin/test/test.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gconjoin/test/test.main.js create mode 100644 lib/node_modules/@stdlib/blas/ext/base/gconjoin/test/test.ndarray.js diff --git a/lib/node_modules/@stdlib/blas/ext/base/gconjoin/README.md b/lib/node_modules/@stdlib/blas/ext/base/gconjoin/README.md new file mode 100644 index 000000000000..db26e09506ed --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gconjoin/README.md @@ -0,0 +1,187 @@ + + +# gconjoin + +> Return a string created by joining strided array elements using a conjunction. + + + +
+ +
+ + + + + +
+ +## Usage + +```javascript +var gconjoin = require( '@stdlib/blas/ext/base/gconjoin' ); +``` + +#### gconjoin( N, prefix, suffix, conjunction, oxfordComma, x, strideX ) + +Returns a string created by joining strided array elements using a conjunction. + +```javascript +var x = [ 1, 2, 3, 4 ]; + +var str = gconjoin( x.length, '', '', 'and', true, x, 1 ); +// returns '1, 2, 3, and 4' +``` + +The function has the following parameters: + +- **N**: number of indexed elements. +- **prefix**: string to prepend. +- **suffix**: string to append. +- **conjunction**: conjunction before the last element. +- **oxfordComma**: boolean specifying whether to include an Oxford comma. +- **x**: input array. +- **strideX**: stride length. + +The `N` and stride parameters determine which elements in the strided array are accessed at runtime. For example, to join every other element: + +```javascript +var x = [ 1, 2, 3, 4, 5, 6 ]; + +var str = gconjoin( 3, '', '', 'and', true, x, 2 ); +// returns '1, 3, and 5' +``` + +Note that indexing is relative to the first index. To introduce an offset, use [`typed array`][mdn-typed-array] views. + +```javascript +var Float64Array = require( '@stdlib/array/float64' ); + +// Initial array: +var x0 = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); + +// Create an offset view: +var x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element + +// Join elements: +var str = gconjoin( 3, '', '', 'and', true, x1, 2 ); +// returns '2, 4, and 6' +``` + + + +#### gconjoin.ndarray( N, prefix, suffix, conjunction, oxfordComma, x, strideX, offsetX ) + + + +Returns a string created by joining strided array elements using a conjunction and alternative indexing semantics. + +```javascript +var x = [ 1, 2, 3, 4 ]; + +var str = gconjoin.ndarray( x.length, '', '', 'and', true, x, 1, 0 ); +// returns '1, 2, 3, and 4' +``` + +The function has the following additional parameters: + +- **offsetX**: starting index. + +While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying buffer, the offset parameter supports indexing semantics based on a starting index. For example, to access only the last three elements of the strided array: + +```javascript +var x = [ 1, 2, 3, 4, 5, 6 ]; + +var str = gconjoin.ndarray( 3, '', '', 'and', true, x, 1, x.length-3 ); +// returns '4, 5, and 6' +``` + +
+ + + + + +
+ +## Notes + +- If `N <= 0`, both functions return an empty string. +- If `N < 3`, the `oxfordComma` parameter has no effect. +- If an array element is either `null` or `undefined`, both functions will serialize the element as an empty string. +- Both functions support array-like objects having getter and setter accessors for array element access (e.g., [`@stdlib/array/base/accessor`][@stdlib/array/base/accessor]). + +
+ + + + + +
+ +## Examples + + + +```javascript +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var gconjoin = require( '@stdlib/blas/ext/base/gconjoin' ); + +var x = discreteUniform( 5, -100, 100, { + 'dtype': 'generic' +}); +console.log( x ); + +var out = gconjoin( x.length, '', '', 'and', true, x, 1 ); +console.log( out ); +``` + +
+ + + + + +
+ +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/blas/ext/base/gconjoin/benchmark/benchmark.js b/lib/node_modules/@stdlib/blas/ext/base/gconjoin/benchmark/benchmark.js new file mode 100644 index 000000000000..ca81577fd584 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gconjoin/benchmark/benchmark.js @@ -0,0 +1,97 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var isString = require( '@stdlib/assert/is-string' ).isPrimitive; +var oneTo = require( '@stdlib/array/one-to' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var gconjoin = require( './../lib' ); + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var x = oneTo( len, 'float64' ); + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var out; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = gconjoin( x.length, '', '', 'and', true, x, 1 ); + if ( out !== out ) { + b.fail( 'should return a string' ); + } + } + b.toc(); + if ( !isString( out ) ) { + b.fail( 'should return a string' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + + f = createBenchmark( len ); + bench( format( '%s:len=%d', pkg, len ), f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/blas/ext/base/gconjoin/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/gconjoin/benchmark/benchmark.ndarray.js new file mode 100644 index 000000000000..1e102bd2189f --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gconjoin/benchmark/benchmark.ndarray.js @@ -0,0 +1,97 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var isString = require( '@stdlib/assert/is-string' ).isPrimitive; +var oneTo = require( '@stdlib/array/one-to' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var gconjoin = require( './../lib/ndarray.js' ); + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var x = oneTo( len, 'float64' ); + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var out; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = gconjoin( x.length, '', '', 'and', true, x, 1, 0 ); + if ( out !== out ) { + b.fail( 'should return a string' ); + } + } + b.toc(); + if ( !isString( out ) ) { + b.fail( 'should return a string' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + + f = createBenchmark( len ); + bench( format( '%s:ndarray:len=%d', pkg, len ), f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/blas/ext/base/gconjoin/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/base/gconjoin/docs/repl.txt new file mode 100644 index 000000000000..b6b020a0a40d --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gconjoin/docs/repl.txt @@ -0,0 +1,95 @@ + +{{alias}}( N, prefix, suffix, conjunction, oxfordComma, x, strideX ) + Returns a string created by joining strided array elements using a + conjunction. + + The `N` and stride parameters determine which elements in the strided array + are accessed at runtime. + + Indexing is relative to the first index. To introduce an offset, use a typed + array view. + + If `N <= 0`, the function returns an empty string. + + Parameters + ---------- + N: integer + Number of indexed elements. + + prefix: string + String to prepend. + + suffix: string + String to append. + + conjunction: string + Conjunction before the last element. + + oxfordComma: boolean + Boolean specifying whether to include an Oxford comma. + + x: Array|TypedArray + Input array. + + strideX: integer + Stride length. + + Returns + ------- + str: string + Joined string. + + Examples + -------- + > var x = [ 1, 2, 3, 4 ]; + > var str = {{alias}}( x.length, '', '', 'and', true, x, 1 ) + '1, 2, 3, and 4' + + +{{alias}}.ndarray( N, prefix, suffix, conjunction, oxfordComma, x, sx, ox ) + Returns a string created by joining strided array elements using a + conjunction and alternative indexing semantics. + + While typed array views mandate a view offset based on the underlying + buffer, the offset parameter supports indexing semantics based on a starting + index. + + Parameters + ---------- + N: integer + Number of indexed elements. + + prefix: string + String to prepend. + + suffix: string + String to append. + + conjunction: string + Conjunction before the last element. + + oxfordComma: boolean + Boolean specifying whether to include an Oxford comma. + + x: Array|TypedArray + Input array. + + sx: integer + Stride length. + + ox: integer + Starting index. + + Returns + ------- + str: string + Joined string. + + Examples + -------- + > var x = [ 1, 2, 3, 4 ]; + > var str = {{alias}}.ndarray( x.length, '', '', 'and', true, x, 1, 0 ) + '1, 2, 3, and 4' + + See Also + -------- diff --git a/lib/node_modules/@stdlib/blas/ext/base/gconjoin/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/ext/base/gconjoin/docs/types/index.d.ts new file mode 100644 index 000000000000..411ee03d4a23 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gconjoin/docs/types/index.d.ts @@ -0,0 +1,105 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2026 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. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +// TypeScript Version: 4.1 + +/// + +import { Collection, AccessorArrayLike } from '@stdlib/types/array'; + +/** +* Input array. +*/ +type InputArray = Collection | AccessorArrayLike; + +/** +* Interface describing `gconjoin`. +*/ +interface Routine { + /** + * Returns a string created by joining strided array elements using a conjunction. + * + * @param N - number of indexed elements + * @param prefix - string to prepend + * @param suffix - string to append + * @param conjunction - conjunction before the last element + * @param oxfordComma - boolean specifying whether to include an Oxford comma + * @param x - input array + * @param strideX - stride length + * @returns joined string + * + * @example + * var x = [ 1, 2, 3, 4 ]; + * + * var str = gconjoin( x.length, '', '', 'and', true, x, 1 ); + * // returns '1, 2, 3, and 4' + */ + ( N: number, prefix: string, suffix: string, conjunction: string, oxfordComma: boolean, x: InputArray, strideX: number ): string; + + /** + * Returns a string created by joining strided array elements using a conjunction and alternative indexing semantics. + * + * @param N - number of indexed elements + * @param prefix - string to prepend + * @param suffix - string to append + * @param conjunction - conjunction before the last element + * @param oxfordComma - boolean specifying whether to include an Oxford comma + * @param x - input array + * @param strideX - stride length + * @param offsetX - starting index + * @returns joined string + * + * @example + * var x = [ 1, 2, 3, 4 ]; + * + * var str = gconjoin.ndarray( x.length, '', '', 'and', true, x, 1, 0 ); + * // returns '1, 2, 3, and 4' + */ + ndarray( N: number, prefix: string, suffix: string, conjunction: string, oxfordComma: boolean, x: InputArray, strideX: number, offsetX: number ): string; +} + +/** +* Returns a string created by joining strided array elements using a conjunction. +* +* @param N - number of indexed elements +* @param prefix - string to prepend +* @param suffix - string to append +* @param conjunction - conjunction before the last element +* @param oxfordComma - boolean specifying whether to include an Oxford comma +* @param x - input array +* @param strideX - stride length +* @returns joined string +* +* @example +* var x = [ 1, 2, 3, 4 ]; +* +* var str = gconjoin( x.length, '', '', 'and', true, x, 1 ); +* // returns '1, 2, 3, and 4' +* +* @example +* var x = [ 1, 2, 3, 4 ]; +* +* var str = gconjoin.ndarray( x.length, '', '', 'and', true, x, 1, 0 ); +* // returns '1, 2, 3, and 4' +*/ +declare var gconjoin: Routine; + + +// EXPORTS // + +export = gconjoin; diff --git a/lib/node_modules/@stdlib/blas/ext/base/gconjoin/docs/types/test.ts b/lib/node_modules/@stdlib/blas/ext/base/gconjoin/docs/types/test.ts new file mode 100644 index 000000000000..dd4580321281 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gconjoin/docs/types/test.ts @@ -0,0 +1,263 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2026 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. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +import gconjoin = require( './index' ); + + +// TESTS // + +// The function returns a string... +{ + const x = [ 1, 2, 3, 4 ]; + + gconjoin( x.length, '', '', 'and', true, x, 1 ); // $ExpectType string +} + +// The compiler throws an error if the function is provided a first argument which is not a number... +{ + const x = [ 1, 2, 3, 4 ]; + + gconjoin( '5', '', '', 'and', true, x, 1 ); // $ExpectError + gconjoin( true, '', '', 'and', true, x, 1 ); // $ExpectError + gconjoin( false, '', '', 'and', true, x, 1 ); // $ExpectError + gconjoin( null, '', '', 'and', true, x, 1 ); // $ExpectError + gconjoin( undefined, '', '', 'and', true, x, 1 ); // $ExpectError + gconjoin( [], '', '', 'and', true, x, 1 ); // $ExpectError + gconjoin( {}, '', '', 'and', true, x, 1 ); // $ExpectError + gconjoin( ( x: number ): number => x, '', '', 'and', true, x, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a second argument which is not a string... +{ + const x = [ 1, 2, 3, 4 ]; + + gconjoin( x.length, 5, '', 'and', true, x, 1 ); // $ExpectError + gconjoin( x.length, true, '', 'and', true, x, 1 ); // $ExpectError + gconjoin( x.length, false, '', 'and', true, x, 1 ); // $ExpectError + gconjoin( x.length, null, '', 'and', true, x, 1 ); // $ExpectError + gconjoin( x.length, undefined, '', 'and', true, x, 1 ); // $ExpectError + gconjoin( x.length, [], '', 'and', true, x, 1 ); // $ExpectError + gconjoin( x.length, {}, '', 'and', true, x, 1 ); // $ExpectError + gconjoin( x.length, ( x: number ): number => x, '', 'and', true, x, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a third argument which is not a string... +{ + const x = [ 1, 2, 3, 4 ]; + + gconjoin( x.length, '', 5, 'and', true, x, 1 ); // $ExpectError + gconjoin( x.length, '', true, 'and', true, x, 1 ); // $ExpectError + gconjoin( x.length, '', false, 'and', true, x, 1 ); // $ExpectError + gconjoin( x.length, '', null, 'and', true, x, 1 ); // $ExpectError + gconjoin( x.length, '', undefined, 'and', true, x, 1 ); // $ExpectError + gconjoin( x.length, '', [], 'and', true, x, 1 ); // $ExpectError + gconjoin( x.length, '', {}, 'and', true, x, 1 ); // $ExpectError + gconjoin( x.length, '', ( x: number ): number => x, 'and', true, x, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a fourth argument which is not a string... +{ + const x = [ 1, 2, 3, 4 ]; + + gconjoin( x.length, '', '', 5, true, x, 1 ); // $ExpectError + gconjoin( x.length, '', '', true, true, x, 1 ); // $ExpectError + gconjoin( x.length, '', '', false, true, x, 1 ); // $ExpectError + gconjoin( x.length, '', '', null, true, x, 1 ); // $ExpectError + gconjoin( x.length, '', '', undefined, true, x, 1 ); // $ExpectError + gconjoin( x.length, '', '', [], true, x, 1 ); // $ExpectError + gconjoin( x.length, '', '', {}, true, x, 1 ); // $ExpectError + gconjoin( x.length, '', '', ( x: number ): number => x, true, x, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a fifth argument which is not a boolean... +{ + const x = [ 1, 2, 3, 4 ]; + + gconjoin( x.length, '', '', 'and', '5', x, 1 ); // $ExpectError + gconjoin( x.length, '', '', 'and', 5, x, 1 ); // $ExpectError + gconjoin( x.length, '', '', 'and', null, x, 1 ); // $ExpectError + gconjoin( x.length, '', '', 'and', undefined, x, 1 ); // $ExpectError + gconjoin( x.length, '', '', 'and', [], x, 1 ); // $ExpectError + gconjoin( x.length, '', '', 'and', {}, x, 1 ); // $ExpectError + gconjoin( x.length, '', '', 'and', ( x: number ): number => x, x, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a sixth argument which is not an array-like object... +{ + gconjoin( 4, '', '', 'and', true, 5, 1 ); // $ExpectError + gconjoin( 4, '', '', 'and', true, true, 1 ); // $ExpectError + gconjoin( 4, '', '', 'and', true, false, 1 ); // $ExpectError + gconjoin( 4, '', '', 'and', true, null, 1 ); // $ExpectError + gconjoin( 4, '', '', 'and', true, undefined, 1 ); // $ExpectError + gconjoin( 4, '', '', 'and', true, {}, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a seventh argument which is not a number... +{ + const x = [ 1, 2, 3, 4 ]; + + gconjoin( x.length, '', '', 'and', true, x, '5' ); // $ExpectError + gconjoin( x.length, '', '', 'and', true, x, true ); // $ExpectError + gconjoin( x.length, '', '', 'and', true, x, false ); // $ExpectError + gconjoin( x.length, '', '', 'and', true, x, null ); // $ExpectError + gconjoin( x.length, '', '', 'and', true, x, undefined ); // $ExpectError + gconjoin( x.length, '', '', 'and', true, x, [] ); // $ExpectError + gconjoin( x.length, '', '', 'and', true, x, {} ); // $ExpectError + gconjoin( x.length, '', '', 'and', true, x, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided insufficient arguments... +{ + const x = [ 1, 2, 3, 4 ]; + + gconjoin(); // $ExpectError + gconjoin( x.length ); // $ExpectError + gconjoin( x.length, '' ); // $ExpectError + gconjoin( x.length, '', '' ); // $ExpectError + gconjoin( x.length, '', '', 'and' ); // $ExpectError + gconjoin( x.length, '', '', 'and', true ); // $ExpectError + gconjoin( x.length, '', '', 'and', true, x ); // $ExpectError +} + +// Attached to the main export is an `ndarray` method which returns a string... +{ + const x = [ 1, 2, 3, 4 ]; + + gconjoin.ndarray( x.length, '', '', 'and', true, x, 1, 0 ); // $ExpectType string +} + +// The compiler throws an error if the `ndarray` method is provided a first argument which is not a number... +{ + const x = [ 1, 2, 3, 4 ]; + + gconjoin.ndarray( '5', '', '', 'and', true, x, 1, 0 ); // $ExpectError + gconjoin.ndarray( true, '', '', 'and', true, x, 1, 0 ); // $ExpectError + gconjoin.ndarray( false, '', '', 'and', true, x, 1, 0 ); // $ExpectError + gconjoin.ndarray( null, '', '', 'and', true, x, 1, 0 ); // $ExpectError + gconjoin.ndarray( undefined, '', '', 'and', true, x, 1, 0 ); // $ExpectError + gconjoin.ndarray( [], '', '', 'and', true, x, 1, 0 ); // $ExpectError + gconjoin.ndarray( {}, '', '', 'and', true, x, 1, 0 ); // $ExpectError + gconjoin.ndarray( ( x: number ): number => x, '', '', 'and', true, x, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a second argument which is not a string... +{ + const x = [ 1, 2, 3, 4 ]; + + gconjoin.ndarray( x.length, 5, '', 'and', true, x, 1, 0 ); // $ExpectError + gconjoin.ndarray( x.length, true, '', 'and', true, x, 1, 0 ); // $ExpectError + gconjoin.ndarray( x.length, false, '', 'and', true, x, 1, 0 ); // $ExpectError + gconjoin.ndarray( x.length, null, '', 'and', true, x, 1, 0 ); // $ExpectError + gconjoin.ndarray( x.length, undefined, '', 'and', true, x, 1, 0 ); // $ExpectError + gconjoin.ndarray( x.length, [], '', 'and', true, x, 1, 0 ); // $ExpectError + gconjoin.ndarray( x.length, {}, '', 'and', true, x, 1, 0 ); // $ExpectError + gconjoin.ndarray( x.length, ( x: number ): number => x, '', 'and', true, x, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a third argument which is not a string... +{ + const x = [ 1, 2, 3, 4 ]; + + gconjoin.ndarray( x.length, '', 5, 'and', true, x, 1, 0 ); // $ExpectError + gconjoin.ndarray( x.length, '', true, 'and', true, x, 1, 0 ); // $ExpectError + gconjoin.ndarray( x.length, '', false, 'and', true, x, 1, 0 ); // $ExpectError + gconjoin.ndarray( x.length, '', null, 'and', true, x, 1, 0 ); // $ExpectError + gconjoin.ndarray( x.length, '', undefined, 'and', true, x, 1, 0 ); // $ExpectError + gconjoin.ndarray( x.length, '', [], 'and', true, x, 1, 0 ); // $ExpectError + gconjoin.ndarray( x.length, '', {}, 'and', true, x, 1, 0 ); // $ExpectError + gconjoin.ndarray( x.length, '', ( x: number ): number => x, 'and', true, x, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a fourth argument which is not a string... +{ + const x = [ 1, 2, 3, 4 ]; + + gconjoin.ndarray( x.length, '', '', 5, true, x, 1, 0 ); // $ExpectError + gconjoin.ndarray( x.length, '', '', true, true, x, 1, 0 ); // $ExpectError + gconjoin.ndarray( x.length, '', '', false, true, x, 1, 0 ); // $ExpectError + gconjoin.ndarray( x.length, '', '', null, true, x, 1, 0 ); // $ExpectError + gconjoin.ndarray( x.length, '', '', undefined, true, x, 1, 0 ); // $ExpectError + gconjoin.ndarray( x.length, '', '', [], true, x, 1, 0 ); // $ExpectError + gconjoin.ndarray( x.length, '', '', {}, true, x, 1, 0 ); // $ExpectError + gconjoin.ndarray( x.length, '', '', ( x: number ): number => x, true, x, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a fifth argument which is not a boolean... +{ + const x = [ 1, 2, 3, 4 ]; + + gconjoin.ndarray( x.length, '', '', 'and', '5', x, 1, 0 ); // $ExpectError + gconjoin.ndarray( x.length, '', '', 'and', 5, x, 1, 0 ); // $ExpectError + gconjoin.ndarray( x.length, '', '', 'and', null, x, 1, 0 ); // $ExpectError + gconjoin.ndarray( x.length, '', '', 'and', undefined, x, 1, 0 ); // $ExpectError + gconjoin.ndarray( x.length, '', '', 'and', [], x, 1, 0 ); // $ExpectError + gconjoin.ndarray( x.length, '', '', 'and', {}, x, 1, 0 ); // $ExpectError + gconjoin.ndarray( x.length, '', '', 'and', ( x: number ): number => x, x, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a sixth argument which is not an array-like object... +{ + gconjoin.ndarray( 4, '', '', 'and', true, 5, 1, 0 ); // $ExpectError + gconjoin.ndarray( 4, '', '', 'and', true, true, 1, 0 ); // $ExpectError + gconjoin.ndarray( 4, '', '', 'and', true, false, 1, 0 ); // $ExpectError + gconjoin.ndarray( 4, '', '', 'and', true, null, 1, 0 ); // $ExpectError + gconjoin.ndarray( 4, '', '', 'and', true, undefined, 1, 0 ); // $ExpectError + gconjoin.ndarray( 4, '', '', 'and', true, {}, 1, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided a seventh argument which is not a number... +{ + const x = [ 1, 2, 3, 4 ]; + + gconjoin.ndarray( x.length, '', '', 'and', true, x, '5', 0 ); // $ExpectError + gconjoin.ndarray( x.length, '', '', 'and', true, x, true, 0 ); // $ExpectError + gconjoin.ndarray( x.length, '', '', 'and', true, x, false, 0 ); // $ExpectError + gconjoin.ndarray( x.length, '', '', 'and', true, x, null, 0 ); // $ExpectError + gconjoin.ndarray( x.length, '', '', 'and', true, x, undefined, 0 ); // $ExpectError + gconjoin.ndarray( x.length, '', '', 'and', true, x, [], 0 ); // $ExpectError + gconjoin.ndarray( x.length, '', '', 'and', true, x, {}, 0 ); // $ExpectError + gconjoin.ndarray( x.length, '', '', 'and', true, x, ( x: number ): number => x, 0 ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided an eighth argument which is not a number... +{ + const x = [ 1, 2, 3, 4 ]; + + gconjoin.ndarray( x.length, '', '', 'and', true, x, 1, '5' ); // $ExpectError + gconjoin.ndarray( x.length, '', '', 'and', true, x, 1, true ); // $ExpectError + gconjoin.ndarray( x.length, '', '', 'and', true, x, 1, false ); // $ExpectError + gconjoin.ndarray( x.length, '', '', 'and', true, x, 1, null ); // $ExpectError + gconjoin.ndarray( x.length, '', '', 'and', true, x, 1, undefined ); // $ExpectError + gconjoin.ndarray( x.length, '', '', 'and', true, x, 1, [] ); // $ExpectError + gconjoin.ndarray( x.length, '', '', 'and', true, x, 1, {} ); // $ExpectError + gconjoin.ndarray( x.length, '', '', 'and', true, x, 1, ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the `ndarray` method is provided insufficient arguments... +{ + const x = [ 1, 2, 3, 4 ]; + + gconjoin.ndarray(); // $ExpectError + gconjoin.ndarray( x.length ); // $ExpectError + gconjoin.ndarray( x.length, '' ); // $ExpectError + gconjoin.ndarray( x.length, '', '' ); // $ExpectError + gconjoin.ndarray( x.length, '', '', 'and' ); // $ExpectError + gconjoin.ndarray( x.length, '', '', 'and', true ); // $ExpectError + gconjoin.ndarray( x.length, '', '', 'and', true, x ); // $ExpectError + gconjoin.ndarray( x.length, '', '', 'and', true, x, 1 ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/gconjoin/examples/index.js b/lib/node_modules/@stdlib/blas/ext/base/gconjoin/examples/index.js new file mode 100644 index 000000000000..11ea4aecdba6 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gconjoin/examples/index.js @@ -0,0 +1,30 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var gconjoin = require( './../lib' ); + +var x = discreteUniform( 5, -100, 100, { + 'dtype': 'generic' +}); +console.log( x ); + +var out = gconjoin( x.length, '', '', 'and', true, x, 1 ); +console.log( out ); diff --git a/lib/node_modules/@stdlib/blas/ext/base/gconjoin/lib/accessors.js b/lib/node_modules/@stdlib/blas/ext/base/gconjoin/lib/accessors.js new file mode 100644 index 000000000000..b379604a296b --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gconjoin/lib/accessors.js @@ -0,0 +1,113 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var isUndefinedOrNull = require( '@stdlib/assert/is-undefined-or-null' ); + + +// FUNCTIONS // + +/** +* Returns the string representation of an array element. +* +* @private +* @param {Function} get - accessor function +* @param {Collection} xbuf - data buffer +* @param {integer} idx - element index +* @returns {string} string representation +*/ +function str( get, xbuf, idx ) { + var v = get( xbuf, idx ); + if ( isUndefinedOrNull( v ) ) { + return ''; + } + return String( v ); +} + + +// MAIN // + +/** +* Returns a string created by joining strided array elements using a conjunction. +* +* @private +* @param {PositiveInteger} N - number of indexed elements +* @param {string} prefix - string to prepend +* @param {string} suffix - string to append +* @param {string} conjunction - conjunction before the last element +* @param {boolean} oxfordComma - boolean specifying whether to include an Oxford comma +* @param {Object} x - input array object +* @param {Collection} x.data - input array data +* @param {Array} x.accessors - array element accessors +* @param {integer} strideX - stride length +* @param {NonNegativeInteger} offsetX - starting index +* @returns {string} joined string +* +* @example +* var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); +* var arraylike2object = require( '@stdlib/array/base/arraylike2object' ); +* +* var x = [ 1, 2, 3, 4 ]; +* +* var out = gconjoin( x.length, '', '', 'and', true, arraylike2object( toAccessorArray( x ) ), 1, 0 ); +* // returns '1, 2, 3, and 4' +*/ +function gconjoin( N, prefix, suffix, conjunction, oxfordComma, x, strideX, offsetX ) { // eslint-disable-line max-len + var xbuf; + var out; + var get; + var ix; + var i; + + // Cache reference to array data: + xbuf = x.data; + + // Cache a reference to the element accessor: + get = x.accessors[ 0 ]; + + // First element... + ix = offsetX; + out = prefix + str( get, xbuf, ix ); + ix += strideX; + + // Middle elements... + for ( i = 1; i < N - 1; i++ ) { + out += ', ' + str( get, xbuf, ix ); + ix += strideX; + } + + // Last element (when N >= 2)... + if ( N >= 2 ) { + if ( conjunction === '' ) { + out += ', ' + str( get, xbuf, ix ); + } else if ( N >= 3 && oxfordComma ) { + out += ', ' + conjunction + ' ' + str( get, xbuf, ix ); + } else { + out += ' ' + conjunction + ' ' + str( get, xbuf, ix ); + } + } + return out + suffix; +} + + +// EXPORTS // + +module.exports = gconjoin; diff --git a/lib/node_modules/@stdlib/blas/ext/base/gconjoin/lib/index.js b/lib/node_modules/@stdlib/blas/ext/base/gconjoin/lib/index.js new file mode 100644 index 000000000000..71353cfd006b --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gconjoin/lib/index.js @@ -0,0 +1,57 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +/** +* Return a string created by joining strided array elements using a conjunction. +* +* @module @stdlib/blas/ext/base/gconjoin +* +* @example +* var gconjoin = require( '@stdlib/blas/ext/base/gconjoin' ); +* +* var x = [ 1, 2, 3, 4 ]; +* +* var str = gconjoin( x.length, '', '', 'and', true, x, 1 ); +* // returns '1, 2, 3, and 4' +* +* @example +* var gconjoin = require( '@stdlib/blas/ext/base/gconjoin' ); +* +* var x = [ 1, 2, 3, 4 ]; +* +* var str = gconjoin.ndarray( x.length, '', '', 'and', true, x, 1, 0 ); +* // returns '1, 2, 3, and 4' +*/ + +// MODULES // + +var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); +var main = require( './main.js' ); +var ndarray = require( './ndarray.js' ); + + +// MAIN // + +setReadOnly( main, 'ndarray', ndarray ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/blas/ext/base/gconjoin/lib/main.js b/lib/node_modules/@stdlib/blas/ext/base/gconjoin/lib/main.js new file mode 100644 index 000000000000..e10f4fe78e05 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gconjoin/lib/main.js @@ -0,0 +1,54 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var stride2offset = require( '@stdlib/strided/base/stride2offset' ); +var ndarray = require( './ndarray.js' ); + + +// MAIN // + +/** +* Returns a string created by joining strided array elements using a conjunction. +* +* @param {PositiveInteger} N - number of indexed elements +* @param {string} prefix - string to prepend +* @param {string} suffix - string to append +* @param {string} conjunction - conjunction before the last element +* @param {boolean} oxfordComma - boolean specifying whether to include an Oxford comma +* @param {Collection} x - input array +* @param {integer} strideX - stride length +* @returns {string} joined string +* +* @example +* var x = [ 1, 2, 3, 4 ]; +* +* var out = gconjoin( x.length, '', '', 'and', true, x, 1 ); +* // returns '1, 2, 3, and 4' +*/ +function gconjoin( N, prefix, suffix, conjunction, oxfordComma, x, strideX ) { + return ndarray( N, prefix, suffix, conjunction, oxfordComma, x, strideX, stride2offset( N, strideX ) ); // eslint-disable-line max-len +} + + +// EXPORTS // + +module.exports = gconjoin; diff --git a/lib/node_modules/@stdlib/blas/ext/base/gconjoin/lib/ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/gconjoin/lib/ndarray.js new file mode 100644 index 000000000000..59633f19374b --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gconjoin/lib/ndarray.js @@ -0,0 +1,109 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var isUndefinedOrNull = require( '@stdlib/assert/is-undefined-or-null' ); +var arraylike2object = require( '@stdlib/array/base/arraylike2object' ); +var accessors = require( './accessors.js' ); + + +// FUNCTIONS // + +/** +* Returns the string representation of an array element. +* +* @private +* @param {Collection} x - input array +* @param {integer} idx - element index +* @returns {string} string representation +*/ +function str( x, idx ) { + var v = x[ idx ]; + if ( isUndefinedOrNull( v ) ) { + return ''; + } + return String( v ); +} + + +// MAIN // + +/** +* Returns a string created by joining strided array elements using a conjunction and alternative indexing semantics. +* +* @param {PositiveInteger} N - number of indexed elements +* @param {string} prefix - string to prepend +* @param {string} suffix - string to append +* @param {string} conjunction - conjunction before the last element +* @param {boolean} oxfordComma - boolean specifying whether to include an Oxford comma +* @param {Collection} x - input array +* @param {integer} strideX - stride length +* @param {NonNegativeInteger} offsetX - starting index +* @returns {string} joined string +* +* @example +* var x = [ 1, 2, 3, 4 ]; +* +* var out = gconjoin( x.length, '', '', 'and', true, x, 1, 0 ); +* // returns '1, 2, 3, and 4' +*/ +function gconjoin( N, prefix, suffix, conjunction, oxfordComma, x, strideX, offsetX ) { // eslint-disable-line max-len + var out; + var ix; + var o; + var i; + + if ( N <= 0 ) { + return ''; + } + o = arraylike2object( x ); + if ( o.accessorProtocol ) { + return accessors( N, prefix, suffix, conjunction, oxfordComma, o, strideX, offsetX ); // eslint-disable-line max-len + } + + // First element... + ix = offsetX; + out = prefix + str( x, ix ); + ix += strideX; + + // Middle elements... + for ( i = 1; i < N - 1; i++ ) { + out += ', ' + str( x, ix ); + ix += strideX; + } + + // Last element (when N >= 2)... + if ( N >= 2 ) { + if ( conjunction === '' ) { + out += ', ' + str( x, ix ); + } else if ( N >= 3 && oxfordComma ) { + out += ', ' + conjunction + ' ' + str( x, ix ); + } else { + out += ' ' + conjunction + ' ' + str( x, ix ); + } + } + return out + suffix; +} + + +// EXPORTS // + +module.exports = gconjoin; diff --git a/lib/node_modules/@stdlib/blas/ext/base/gconjoin/package.json b/lib/node_modules/@stdlib/blas/ext/base/gconjoin/package.json new file mode 100644 index 000000000000..e07f4e0abd24 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gconjoin/package.json @@ -0,0 +1,69 @@ +{ + "name": "@stdlib/blas/ext/base/gconjoin", + "version": "0.0.0", + "description": "Return a string created by joining strided array elements using a conjunction.", + "license": "Apache-2.0", + "author": { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + }, + "contributors": [ + { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + } + ], + "main": "./lib", + "directories": { + "benchmark": "./benchmark", + "doc": "./docs", + "example": "./examples", + "lib": "./lib", + "test": "./test" + }, + "types": "./docs/types", + "scripts": {}, + "homepage": "https://github.com/stdlib-js/stdlib", + "repository": { + "type": "git", + "url": "git://github.com/stdlib-js/stdlib.git" + }, + "bugs": { + "url": "https://github.com/stdlib-js/stdlib/issues" + }, + "dependencies": {}, + "devDependencies": {}, + "engines": { + "node": ">=0.10.0", + "npm": ">2.7.0" + }, + "os": [ + "aix", + "darwin", + "freebsd", + "linux", + "macos", + "openbsd", + "sunos", + "win32", + "windows" + ], + "keywords": [ + "stdlib", + "stdmath", + "mathematics", + "math", + "blas", + "extended", + "join", + "conjoin", + "conjunction", + "oxford", + "comma", + "string", + "strided", + "array", + "ndarray" + ], + "__stdlib__": {} +} diff --git a/lib/node_modules/@stdlib/blas/ext/base/gconjoin/test/test.js b/lib/node_modules/@stdlib/blas/ext/base/gconjoin/test/test.js new file mode 100644 index 000000000000..3660cc70ea2c --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gconjoin/test/test.js @@ -0,0 +1,38 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var gconjoin = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof gconjoin, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the main export is a method providing an ndarray interface', function test( t ) { + t.strictEqual( typeof gconjoin.ndarray, 'function', 'method is a function' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/ext/base/gconjoin/test/test.main.js b/lib/node_modules/@stdlib/blas/ext/base/gconjoin/test/test.main.js new file mode 100644 index 000000000000..87c8fde00a84 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gconjoin/test/test.main.js @@ -0,0 +1,153 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); +var gconjoin = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof gconjoin, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 7', function test( t ) { + t.strictEqual( gconjoin.length, 7, 'has expected arity' ); + t.end(); +}); + +tape( 'the function returns a string created by joining strided array elements using a conjunction', function test( t ) { + var actual; + var x; + + x = [ 1, 2, 3, 4 ]; + + // Three or more elements with Oxford comma... + actual = gconjoin( x.length, 'result: ', '', 'and', true, x, 1 ); + t.strictEqual( actual, 'result: 1, 2, 3, and 4', 'returns expected value' ); + + // Three or more elements without Oxford comma... + actual = gconjoin( x.length, 'result: ', '', 'and', false, x, 1 ); + t.strictEqual( actual, 'result: 1, 2, 3 and 4', 'returns expected value' ); + + // Two elements... + actual = gconjoin( 2, 'result: ', '', 'and', true, x, 1 ); + t.strictEqual( actual, 'result: 1 and 2', 'returns expected value' ); + + // Single element... + actual = gconjoin( 1, 'result: ', '', 'and', true, x, 1 ); + t.strictEqual( actual, 'result: 1', 'returns expected value' ); + + // Empty conjunction... + actual = gconjoin( x.length, '[ ', ' ]', '', true, x, 1 ); + t.strictEqual( actual, '[ 1, 2, 3, 4 ]', 'returns expected value' ); + + // Prefix and suffix... + actual = gconjoin( 3, '(', ')', 'or', false, [ 1, 2, 3 ], 1 ); + t.strictEqual( actual, '(1, 2 or 3)', 'returns expected value' ); + + // Nonnegative stride... + actual = gconjoin( 3, '', '', 'and', true, [ 1, 2, 3, 4, 5, 6 ], 2 ); + t.strictEqual( actual, '1, 3, and 5', 'returns expected value' ); + + // Negative stride... + actual = gconjoin( 3, '', '', 'and', true, [ 1, 2, 3, 4, 5, 6 ], -2 ); + t.strictEqual( actual, '5, 3, and 1', 'returns expected value' ); + + // Null and undefined values... + x = [ 1, null, 3, undefined, 5 ]; + actual = gconjoin( x.length, '', '', 'and', true, x, 1 ); + t.strictEqual( actual, '1, , 3, , and 5', 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns a string created by joining strided array elements using a conjunction (accessors)', function test( t ) { + var actual; + var x; + + x = toAccessorArray( [ 1, 2, 3, 4 ] ); + + // Three or more elements with Oxford comma... + actual = gconjoin( x.length, 'result: ', '', 'and', true, x, 1 ); + t.strictEqual( actual, 'result: 1, 2, 3, and 4', 'returns expected value' ); + + // Three or more elements without Oxford comma... + actual = gconjoin( x.length, 'result: ', '', 'and', false, x, 1 ); + t.strictEqual( actual, 'result: 1, 2, 3 and 4', 'returns expected value' ); + + // Two elements... + actual = gconjoin( 2, 'result: ', '', 'and', true, x, 1 ); + t.strictEqual( actual, 'result: 1 and 2', 'returns expected value' ); + + // Single element... + actual = gconjoin( 1, 'result: ', '', 'and', true, x, 1 ); + t.strictEqual( actual, 'result: 1', 'returns expected value' ); + + // Empty conjunction... + actual = gconjoin( x.length, '[ ', ' ]', '', true, x, 1 ); + t.strictEqual( actual, '[ 1, 2, 3, 4 ]', 'returns expected value' ); + + // Nonnegative stride... + x = toAccessorArray( [ 1, 2, 3, 4, 5, 6 ] ); + actual = gconjoin( 3, '', '', 'and', true, x, 2 ); + t.strictEqual( actual, '1, 3, and 5', 'returns expected value' ); + + // Negative stride... + x = toAccessorArray( [ 1, 2, 3, 4 ] ); + actual = gconjoin( x.length, '', '', 'and', true, x, -1 ); + t.strictEqual( actual, '4, 3, 2, and 1', 'returns expected value' ); + + // Null and undefined values... + x = toAccessorArray( [ 1, null, 3, undefined, 5 ] ); + actual = gconjoin( x.length, '', '', 'and', true, x, 1 ); + t.strictEqual( actual, '1, , 3, , and 5', 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns an empty string if provided an `N` parameter less than or equal to zero', function test( t ) { + var actual; + + actual = gconjoin( 0, '', '', 'and', true, [ 1, 2, 3 ], 1 ); + t.strictEqual( actual, '', 'returns expected value' ); + + actual = gconjoin( -1, '', '', 'and', true, [ 1, 2, 3 ], 1 ); + t.strictEqual( actual, '', 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns an empty string if provided an `N` parameter less than or equal to zero (accessors)', function test( t ) { + var actual; + + actual = gconjoin( 0, '', '', 'and', true, toAccessorArray( [ 1, 2, 3 ] ), 1 ); + t.strictEqual( actual, '', 'returns expected value' ); + + actual = gconjoin( -1, '', '', 'and', true, toAccessorArray( [ 1, 2, 3 ] ), 1 ); + t.strictEqual( actual, '', 'returns expected value' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/blas/ext/base/gconjoin/test/test.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/gconjoin/test/test.ndarray.js new file mode 100644 index 000000000000..03076c1235d0 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gconjoin/test/test.ndarray.js @@ -0,0 +1,159 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); +var gconjoin = require( './../lib/ndarray.js' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof gconjoin, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function has an arity of 8', function test( t ) { + t.strictEqual( gconjoin.length, 8, 'has expected arity' ); + t.end(); +}); + +tape( 'the function returns a string created by joining strided array elements using a conjunction', function test( t ) { + var actual; + var x; + + x = [ 1, 2, 3, 4 ]; + + // Three or more elements with Oxford comma... + actual = gconjoin( x.length, 'result: ', '', 'and', true, x, 1, 0 ); + t.strictEqual( actual, 'result: 1, 2, 3, and 4', 'returns expected value' ); + + // Three or more elements without Oxford comma... + actual = gconjoin( x.length, 'result: ', '', 'and', false, x, 1, 0 ); + t.strictEqual( actual, 'result: 1, 2, 3 and 4', 'returns expected value' ); + + // Two elements... + actual = gconjoin( 2, 'result: ', '', 'and', true, x, 1, 0 ); + t.strictEqual( actual, 'result: 1 and 2', 'returns expected value' ); + + // Single element... + actual = gconjoin( 1, 'result: ', '', 'and', true, x, 1, 0 ); + t.strictEqual( actual, 'result: 1', 'returns expected value' ); + + // Empty conjunction... + actual = gconjoin( x.length, '[ ', ' ]', '', true, x, 1, 0 ); + t.strictEqual( actual, '[ 1, 2, 3, 4 ]', 'returns expected value' ); + + // Prefix and suffix... + actual = gconjoin( 3, '(', ')', 'or', false, [ 1, 2, 3 ], 1, 0 ); + t.strictEqual( actual, '(1, 2 or 3)', 'returns expected value' ); + + // Nonnegative stride with offset... + actual = gconjoin( 3, '', '', 'and', true, [ 1, 2, 3, 4, 5, 6 ], 2, 0 ); + t.strictEqual( actual, '1, 3, and 5', 'returns expected value' ); + + actual = gconjoin( 3, '', '', 'and', true, [ 1, 2, 3, 4, 5, 6 ], 1, 1 ); + t.strictEqual( actual, '2, 3, and 4', 'returns expected value' ); + + // Negative stride... + actual = gconjoin( 3, '', '', 'and', true, [ 1, 2, 3, 4, 5, 6 ], -2, 5 ); + t.strictEqual( actual, '6, 4, and 2', 'returns expected value' ); + + actual = gconjoin( 3, '', '', 'and', true, [ 1, 2, 3, 4, 5, 6 ], -1, 5 ); + t.strictEqual( actual, '6, 5, and 4', 'returns expected value' ); + + // Null and undefined values... + x = [ 1, null, 3, undefined, 5 ]; + actual = gconjoin( x.length, '', '', 'and', true, x, 1, 0 ); + t.strictEqual( actual, '1, , 3, , and 5', 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns a string created by joining strided array elements using a conjunction (accessors)', function test( t ) { + var actual; + var x; + + x = toAccessorArray( [ 1, 2, 3, 4 ] ); + + // Three or more elements with Oxford comma... + actual = gconjoin( x.length, 'result: ', '', 'and', true, x, 1, 0 ); + t.strictEqual( actual, 'result: 1, 2, 3, and 4', 'returns expected value' ); + + // Three or more elements without Oxford comma... + actual = gconjoin( x.length, 'result: ', '', 'and', false, x, 1, 0 ); + t.strictEqual( actual, 'result: 1, 2, 3 and 4', 'returns expected value' ); + + // Two elements... + actual = gconjoin( 2, 'result: ', '', 'and', true, x, 1, 0 ); + t.strictEqual( actual, 'result: 1 and 2', 'returns expected value' ); + + // Single element... + actual = gconjoin( 1, 'result: ', '', 'and', true, x, 1, 0 ); + t.strictEqual( actual, 'result: 1', 'returns expected value' ); + + // Empty conjunction... + actual = gconjoin( x.length, '[ ', ' ]', '', true, x, 1, 0 ); + t.strictEqual( actual, '[ 1, 2, 3, 4 ]', 'returns expected value' ); + + // Nonnegative stride... + x = toAccessorArray( [ 1, 2, 3, 4, 5, 6 ] ); + actual = gconjoin( 3, '', '', 'and', true, x, 2, 0 ); + t.strictEqual( actual, '1, 3, and 5', 'returns expected value' ); + + // Negative stride... + x = toAccessorArray( [ 1, 2, 3, 4 ] ); + actual = gconjoin( x.length, '', '', 'and', true, x, -1, 3 ); + t.strictEqual( actual, '4, 3, 2, and 1', 'returns expected value' ); + + // Null and undefined values... + x = toAccessorArray( [ 1, null, 3, undefined, 5 ] ); + actual = gconjoin( x.length, '', '', 'and', true, x, 1, 0 ); + t.strictEqual( actual, '1, , 3, , and 5', 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns an empty string if provided an `N` parameter less than or equal to zero', function test( t ) { + var actual; + + actual = gconjoin( 0, '', '', 'and', true, [ 1, 2, 3 ], 1, 0 ); + t.strictEqual( actual, '', 'returns expected value' ); + + actual = gconjoin( -1, '', '', 'and', true, [ 1, 2, 3 ], 1, 0 ); + t.strictEqual( actual, '', 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns an empty string if provided an `N` parameter less than or equal to zero (accessors)', function test( t ) { + var actual; + + actual = gconjoin( 0, '', '', 'and', true, toAccessorArray( [ 1, 2, 3 ] ), 1, 0 ); + t.strictEqual( actual, '', 'returns expected value' ); + + actual = gconjoin( -1, '', '', 'and', true, toAccessorArray( [ 1, 2, 3 ] ), 1, 0 ); + t.strictEqual( actual, '', 'returns expected value' ); + + t.end(); +}); From 0df1b271974d83befa25fe434245886d0e48bff1 Mon Sep 17 00:00:00 2001 From: headlessNode Date: Thu, 26 Mar 2026 10:23:37 +0500 Subject: [PATCH 2/4] fix: apply suggestions from code review --- .../@stdlib/blas/ext/base/gconjoin/README.md | 9 ++-- .../blas/ext/base/gconjoin/docs/repl.txt | 10 ++-- .../ext/base/gconjoin/docs/types/index.d.ts | 6 +-- .../blas/ext/base/gconjoin/lib/accessors.js | 46 ++++++++++-------- .../blas/ext/base/gconjoin/lib/index.js | 2 +- .../blas/ext/base/gconjoin/lib/main.js | 2 +- .../blas/ext/base/gconjoin/lib/ndarray.js | 48 ++++++++++--------- .../blas/ext/base/gconjoin/package.json | 2 +- .../blas/ext/base/gconjoin/test/test.main.js | 35 ++++++++++++-- .../ext/base/gconjoin/test/test.ndarray.js | 35 ++++++++++++-- 10 files changed, 129 insertions(+), 66 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/ext/base/gconjoin/README.md b/lib/node_modules/@stdlib/blas/ext/base/gconjoin/README.md index db26e09506ed..2a25b1f92b92 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gconjoin/README.md +++ b/lib/node_modules/@stdlib/blas/ext/base/gconjoin/README.md @@ -20,7 +20,7 @@ limitations under the License. # gconjoin -> Return a string created by joining strided array elements using a conjunction. +> Return a string created by joining strided array elements into a human-readable list using a conjunction. @@ -42,7 +42,7 @@ var gconjoin = require( '@stdlib/blas/ext/base/gconjoin' ); #### gconjoin( N, prefix, suffix, conjunction, oxfordComma, x, strideX ) -Returns a string created by joining strided array elements using a conjunction. +Returns a string created by joining strided array elements into a human-readable list using a conjunction. ```javascript var x = [ 1, 2, 3, 4 ]; @@ -92,7 +92,7 @@ var str = gconjoin( 3, '', '', 'and', true, x1, 2 ); -Returns a string created by joining strided array elements using a conjunction and alternative indexing semantics. +Returns a string created by joining strided array elements into a human-readable list using a conjunction and alternative indexing semantics. ```javascript var x = [ 1, 2, 3, 4 ]; @@ -124,7 +124,8 @@ var str = gconjoin.ndarray( 3, '', '', 'and', true, x, 1, x.length-3 ); ## Notes -- If `N <= 0`, both functions return an empty string. +- If `N <= 0`, both functions return the prefix followed by the suffix. +- If `N < 2`, the `conjunction` parameter is ignored. - If `N < 3`, the `oxfordComma` parameter has no effect. - If an array element is either `null` or `undefined`, both functions will serialize the element as an empty string. - Both functions support array-like objects having getter and setter accessors for array element access (e.g., [`@stdlib/array/base/accessor`][@stdlib/array/base/accessor]). diff --git a/lib/node_modules/@stdlib/blas/ext/base/gconjoin/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/base/gconjoin/docs/repl.txt index b6b020a0a40d..53fd4a488078 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gconjoin/docs/repl.txt +++ b/lib/node_modules/@stdlib/blas/ext/base/gconjoin/docs/repl.txt @@ -1,7 +1,7 @@ {{alias}}( N, prefix, suffix, conjunction, oxfordComma, x, strideX ) - Returns a string created by joining strided array elements using a - conjunction. + Returns a string created by joining strided array elements into a + human-readable list using a conjunction. The `N` and stride parameters determine which elements in the strided array are accessed at runtime. @@ -9,7 +9,7 @@ Indexing is relative to the first index. To introduce an offset, use a typed array view. - If `N <= 0`, the function returns an empty string. + If `N <= 0`, the function returns the prefix followed by the suffix. Parameters ---------- @@ -47,8 +47,8 @@ {{alias}}.ndarray( N, prefix, suffix, conjunction, oxfordComma, x, sx, ox ) - Returns a string created by joining strided array elements using a - conjunction and alternative indexing semantics. + Returns a string created by joining strided array elements into a + human-readable list using a conjunction and alternative indexing semantics. While typed array views mandate a view offset based on the underlying buffer, the offset parameter supports indexing semantics based on a starting diff --git a/lib/node_modules/@stdlib/blas/ext/base/gconjoin/docs/types/index.d.ts b/lib/node_modules/@stdlib/blas/ext/base/gconjoin/docs/types/index.d.ts index 411ee03d4a23..7d190e27b2d5 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gconjoin/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/blas/ext/base/gconjoin/docs/types/index.d.ts @@ -32,7 +32,7 @@ type InputArray = Collection | AccessorArrayLike; */ interface Routine { /** - * Returns a string created by joining strided array elements using a conjunction. + * Returns a string created by joining strided array elements into a human-readable list using a conjunction. * * @param N - number of indexed elements * @param prefix - string to prepend @@ -52,7 +52,7 @@ interface Routine { ( N: number, prefix: string, suffix: string, conjunction: string, oxfordComma: boolean, x: InputArray, strideX: number ): string; /** - * Returns a string created by joining strided array elements using a conjunction and alternative indexing semantics. + * Returns a string created by joining strided array elements into a human-readable list using a conjunction and alternative indexing semantics. * * @param N - number of indexed elements * @param prefix - string to prepend @@ -74,7 +74,7 @@ interface Routine { } /** -* Returns a string created by joining strided array elements using a conjunction. +* Returns a string created by joining strided array elements into a human-readable list using a conjunction. * * @param N - number of indexed elements * @param prefix - string to prepend diff --git a/lib/node_modules/@stdlib/blas/ext/base/gconjoin/lib/accessors.js b/lib/node_modules/@stdlib/blas/ext/base/gconjoin/lib/accessors.js index b379604a296b..3dd8af5b4a87 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gconjoin/lib/accessors.js +++ b/lib/node_modules/@stdlib/blas/ext/base/gconjoin/lib/accessors.js @@ -21,6 +21,13 @@ // MODULES // var isUndefinedOrNull = require( '@stdlib/assert/is-undefined-or-null' ); +var gjoin = require( '@stdlib/blas/ext/base/gjoin' ).ndarray; + + +// VARIABLES // + +var SEP = ', '; +var SPACE = ' '; // FUNCTIONS // @@ -46,7 +53,7 @@ function str( get, xbuf, idx ) { // MAIN // /** -* Returns a string created by joining strided array elements using a conjunction. +* Returns a string created by joining strided array elements into a human-readable list using a conjunction. * * @private * @param {PositiveInteger} N - number of indexed elements @@ -72,6 +79,7 @@ function str( get, xbuf, idx ) { */ function gconjoin( N, prefix, suffix, conjunction, oxfordComma, x, strideX, offsetX ) { // eslint-disable-line max-len var xbuf; + var last; var out; var get; var ix; @@ -82,29 +90,25 @@ function gconjoin( N, prefix, suffix, conjunction, oxfordComma, x, strideX, offs // Cache a reference to the element accessor: get = x.accessors[ 0 ]; - - // First element... - ix = offsetX; - out = prefix + str( get, xbuf, ix ); - ix += strideX; - - // Middle elements... - for ( i = 1; i < N - 1; i++ ) { - out += ', ' + str( get, xbuf, ix ); - ix += strideX; + if ( conjunction === '' || N === 1 ) { + return prefix + gjoin( N, SEP, xbuf, strideX, offsetX ) + suffix; } - - // Last element (when N >= 2)... - if ( N >= 2 ) { - if ( conjunction === '' ) { - out += ', ' + str( get, xbuf, ix ); - } else if ( N >= 3 && oxfordComma ) { - out += ', ' + conjunction + ' ' + str( get, xbuf, ix ); - } else { - out += ' ' + conjunction + ' ' + str( get, xbuf, ix ); + if ( strideX === 1 ) { + out = prefix + gjoin( N-1, SEP, xbuf, strideX, offsetX ); + } else { + ix = offsetX; + out = prefix + str( get, xbuf, ix ); + ix += strideX; + for ( i = 1; i < N - 1; i++ ) { + out += SEP + str( get, xbuf, ix ); + ix += strideX; } } - return out + suffix; + last = str( get, xbuf, offsetX + ( (N-1) * strideX ) ); + if ( N >= 3 && oxfordComma ) { + return out + SEP + conjunction + SPACE + last + suffix; + } + return out + SPACE + conjunction + SPACE + last + suffix; } diff --git a/lib/node_modules/@stdlib/blas/ext/base/gconjoin/lib/index.js b/lib/node_modules/@stdlib/blas/ext/base/gconjoin/lib/index.js index 71353cfd006b..ed3d198c9d5f 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gconjoin/lib/index.js +++ b/lib/node_modules/@stdlib/blas/ext/base/gconjoin/lib/index.js @@ -19,7 +19,7 @@ 'use strict'; /** -* Return a string created by joining strided array elements using a conjunction. +* Return a string created by joining strided array elements into a human-readable list using a conjunction. * * @module @stdlib/blas/ext/base/gconjoin * diff --git a/lib/node_modules/@stdlib/blas/ext/base/gconjoin/lib/main.js b/lib/node_modules/@stdlib/blas/ext/base/gconjoin/lib/main.js index e10f4fe78e05..2b0a2e1f13f2 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gconjoin/lib/main.js +++ b/lib/node_modules/@stdlib/blas/ext/base/gconjoin/lib/main.js @@ -27,7 +27,7 @@ var ndarray = require( './ndarray.js' ); // MAIN // /** -* Returns a string created by joining strided array elements using a conjunction. +* Returns a string created by joining strided array elements into a human-readable list using a conjunction. * * @param {PositiveInteger} N - number of indexed elements * @param {string} prefix - string to prepend diff --git a/lib/node_modules/@stdlib/blas/ext/base/gconjoin/lib/ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/gconjoin/lib/ndarray.js index 59633f19374b..b803b202726d 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gconjoin/lib/ndarray.js +++ b/lib/node_modules/@stdlib/blas/ext/base/gconjoin/lib/ndarray.js @@ -22,9 +22,16 @@ var isUndefinedOrNull = require( '@stdlib/assert/is-undefined-or-null' ); var arraylike2object = require( '@stdlib/array/base/arraylike2object' ); +var gjoin = require( '@stdlib/blas/ext/base/gjoin' ).ndarray; var accessors = require( './accessors.js' ); +// VARIABLES // + +var SEP = ', '; +var SPACE = ' '; + + // FUNCTIONS // /** @@ -47,7 +54,7 @@ function str( x, idx ) { // MAIN // /** -* Returns a string created by joining strided array elements using a conjunction and alternative indexing semantics. +* Returns a string created by joining strided array elements into a human-readable list using a conjunction and alternative indexing semantics. * * @param {PositiveInteger} N - number of indexed elements * @param {string} prefix - string to prepend @@ -66,41 +73,38 @@ function str( x, idx ) { * // returns '1, 2, 3, and 4' */ function gconjoin( N, prefix, suffix, conjunction, oxfordComma, x, strideX, offsetX ) { // eslint-disable-line max-len + var last; var out; var ix; var o; var i; if ( N <= 0 ) { - return ''; + return prefix + suffix; } o = arraylike2object( x ); if ( o.accessorProtocol ) { return accessors( N, prefix, suffix, conjunction, oxfordComma, o, strideX, offsetX ); // eslint-disable-line max-len } - - // First element... - ix = offsetX; - out = prefix + str( x, ix ); - ix += strideX; - - // Middle elements... - for ( i = 1; i < N - 1; i++ ) { - out += ', ' + str( x, ix ); - ix += strideX; + if ( conjunction === '' || N === 1 ) { + return prefix + gjoin( N, SEP, x, strideX, offsetX ) + suffix; } - - // Last element (when N >= 2)... - if ( N >= 2 ) { - if ( conjunction === '' ) { - out += ', ' + str( x, ix ); - } else if ( N >= 3 && oxfordComma ) { - out += ', ' + conjunction + ' ' + str( x, ix ); - } else { - out += ' ' + conjunction + ' ' + str( x, ix ); + if ( strideX === 1 ) { + out = prefix + gjoin( N-1, SEP, x, strideX, offsetX ); + } else { + ix = offsetX; + out = prefix + str( x, ix ); + ix += strideX; + for ( i = 1; i < N - 1; i++ ) { + out += SEP + str( x, ix ); + ix += strideX; } } - return out + suffix; + last = str( x, offsetX + ( (N-1) * strideX ) ); + if ( N >= 3 && oxfordComma ) { + return out + SEP + conjunction + SPACE + last + suffix; + } + return out + SPACE + conjunction + SPACE + last + suffix; } diff --git a/lib/node_modules/@stdlib/blas/ext/base/gconjoin/package.json b/lib/node_modules/@stdlib/blas/ext/base/gconjoin/package.json index e07f4e0abd24..8f3d29ba829a 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gconjoin/package.json +++ b/lib/node_modules/@stdlib/blas/ext/base/gconjoin/package.json @@ -1,7 +1,7 @@ { "name": "@stdlib/blas/ext/base/gconjoin", "version": "0.0.0", - "description": "Return a string created by joining strided array elements using a conjunction.", + "description": "Return a string created by joining strided array elements into a human-readable list using a conjunction.", "license": "Apache-2.0", "author": { "name": "The Stdlib Authors", diff --git a/lib/node_modules/@stdlib/blas/ext/base/gconjoin/test/test.main.js b/lib/node_modules/@stdlib/blas/ext/base/gconjoin/test/test.main.js index 87c8fde00a84..0ca26ebed025 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gconjoin/test/test.main.js +++ b/lib/node_modules/@stdlib/blas/ext/base/gconjoin/test/test.main.js @@ -21,6 +21,7 @@ // MODULES // var tape = require( 'tape' ); +var Complex128Array = require( '@stdlib/array/complex128' ); var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); var gconjoin = require( './../lib' ); @@ -38,7 +39,7 @@ tape( 'the function has an arity of 7', function test( t ) { t.end(); }); -tape( 'the function returns a string created by joining strided array elements using a conjunction', function test( t ) { +tape( 'the function returns a string created by joining strided array elements into a human-readable list using a conjunction', function test( t ) { var actual; var x; @@ -84,7 +85,7 @@ tape( 'the function returns a string created by joining strided array elements u t.end(); }); -tape( 'the function returns a string created by joining strided array elements using a conjunction (accessors)', function test( t ) { +tape( 'the function returns a string created by joining strided array elements into a human-readable list using a conjunction (accessors)', function test( t ) { var actual; var x; @@ -128,7 +129,24 @@ tape( 'the function returns a string created by joining strided array elements u t.end(); }); -tape( 'the function returns an empty string if provided an `N` parameter less than or equal to zero', function test( t ) { +tape( 'the function returns a string created by joining strided array elements into a human-readable list using a conjunction (complex128)', function test( t ) { + var actual; + var x; + + x = new Complex128Array( [ 1, 2, 3, 4, 5, 6 ] ); + + // Unit stride... + actual = gconjoin( x.length, '', '', 'and', true, x, 1 ); + t.strictEqual( actual, '1 + 2i, 3 + 4i, and 5 + 6i', 'returns expected value' ); + + // Non-unit stride... + actual = gconjoin( 2, '', '', 'and', true, x, 2 ); + t.strictEqual( actual, '1 + 2i and 5 + 6i', 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns the prefix followed by the suffix if provided an `N` parameter less than or equal to zero', function test( t ) { var actual; actual = gconjoin( 0, '', '', 'and', true, [ 1, 2, 3 ], 1 ); @@ -137,10 +155,16 @@ tape( 'the function returns an empty string if provided an `N` parameter less th actual = gconjoin( -1, '', '', 'and', true, [ 1, 2, 3 ], 1 ); t.strictEqual( actual, '', 'returns expected value' ); + actual = gconjoin( 0, '[', ']', 'and', true, [ 1, 2, 3 ], 1 ); + t.strictEqual( actual, '[]', 'returns expected value' ); + + actual = gconjoin( -1, '[ ', ' ]', 'and', true, [ 1, 2, 3 ], 1 ); + t.strictEqual( actual, '[ ]', 'returns expected value' ); + t.end(); }); -tape( 'the function returns an empty string if provided an `N` parameter less than or equal to zero (accessors)', function test( t ) { +tape( 'the function returns the prefix followed by the suffix if provided an `N` parameter less than or equal to zero (accessors)', function test( t ) { var actual; actual = gconjoin( 0, '', '', 'and', true, toAccessorArray( [ 1, 2, 3 ] ), 1 ); @@ -149,5 +173,8 @@ tape( 'the function returns an empty string if provided an `N` parameter less th actual = gconjoin( -1, '', '', 'and', true, toAccessorArray( [ 1, 2, 3 ] ), 1 ); t.strictEqual( actual, '', 'returns expected value' ); + actual = gconjoin( 0, '[', ']', 'and', true, toAccessorArray( [ 1, 2, 3 ] ), 1 ); + t.strictEqual( actual, '[]', 'returns expected value' ); + t.end(); }); diff --git a/lib/node_modules/@stdlib/blas/ext/base/gconjoin/test/test.ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/gconjoin/test/test.ndarray.js index 03076c1235d0..f89b035a6647 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gconjoin/test/test.ndarray.js +++ b/lib/node_modules/@stdlib/blas/ext/base/gconjoin/test/test.ndarray.js @@ -21,6 +21,7 @@ // MODULES // var tape = require( 'tape' ); +var Complex128Array = require( '@stdlib/array/complex128' ); var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); var gconjoin = require( './../lib/ndarray.js' ); @@ -38,7 +39,7 @@ tape( 'the function has an arity of 8', function test( t ) { t.end(); }); -tape( 'the function returns a string created by joining strided array elements using a conjunction', function test( t ) { +tape( 'the function returns a string created by joining strided array elements into a human-readable list using a conjunction', function test( t ) { var actual; var x; @@ -90,7 +91,7 @@ tape( 'the function returns a string created by joining strided array elements u t.end(); }); -tape( 'the function returns a string created by joining strided array elements using a conjunction (accessors)', function test( t ) { +tape( 'the function returns a string created by joining strided array elements into a human-readable list using a conjunction (accessors)', function test( t ) { var actual; var x; @@ -134,7 +135,24 @@ tape( 'the function returns a string created by joining strided array elements u t.end(); }); -tape( 'the function returns an empty string if provided an `N` parameter less than or equal to zero', function test( t ) { +tape( 'the function returns a string created by joining strided array elements into a human-readable list using a conjunction (complex128)', function test( t ) { + var actual; + var x; + + x = new Complex128Array( [ 1, 2, 3, 4, 5, 6 ] ); + + // Unit stride... + actual = gconjoin( x.length, '', '', 'and', true, x, 1, 0 ); + t.strictEqual( actual, '1 + 2i, 3 + 4i, and 5 + 6i', 'returns expected value' ); + + // Non-unit stride... + actual = gconjoin( 2, '', '', 'and', true, x, 2, 0 ); + t.strictEqual( actual, '1 + 2i and 5 + 6i', 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns the prefix followed by the suffix if provided an `N` parameter less than or equal to zero', function test( t ) { var actual; actual = gconjoin( 0, '', '', 'and', true, [ 1, 2, 3 ], 1, 0 ); @@ -143,10 +161,16 @@ tape( 'the function returns an empty string if provided an `N` parameter less th actual = gconjoin( -1, '', '', 'and', true, [ 1, 2, 3 ], 1, 0 ); t.strictEqual( actual, '', 'returns expected value' ); + actual = gconjoin( 0, '[', ']', 'and', true, [ 1, 2, 3 ], 1, 0 ); + t.strictEqual( actual, '[]', 'returns expected value' ); + + actual = gconjoin( -1, '[ ', ' ]', 'and', true, [ 1, 2, 3 ], 1, 0 ); + t.strictEqual( actual, '[ ]', 'returns expected value' ); + t.end(); }); -tape( 'the function returns an empty string if provided an `N` parameter less than or equal to zero (accessors)', function test( t ) { +tape( 'the function returns the prefix followed by the suffix if provided an `N` parameter less than or equal to zero (accessors)', function test( t ) { var actual; actual = gconjoin( 0, '', '', 'and', true, toAccessorArray( [ 1, 2, 3 ] ), 1, 0 ); @@ -155,5 +179,8 @@ tape( 'the function returns an empty string if provided an `N` parameter less th actual = gconjoin( -1, '', '', 'and', true, toAccessorArray( [ 1, 2, 3 ] ), 1, 0 ); t.strictEqual( actual, '', 'returns expected value' ); + actual = gconjoin( 0, '[', ']', 'and', true, toAccessorArray( [ 1, 2, 3 ] ), 1, 0 ); + t.strictEqual( actual, '[]', 'returns expected value' ); + t.end(); }); From 160acb5cebb41721c89d3df062c624a3d6ca118e Mon Sep 17 00:00:00 2001 From: Athan Date: Wed, 25 Mar 2026 23:12:09 -0700 Subject: [PATCH 3/4] Apply suggestions from code review Co-authored-by: Athan Signed-off-by: Athan --- .../@stdlib/blas/ext/base/gconjoin/docs/repl.txt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/node_modules/@stdlib/blas/ext/base/gconjoin/docs/repl.txt b/lib/node_modules/@stdlib/blas/ext/base/gconjoin/docs/repl.txt index 53fd4a488078..d33ecd255aab 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gconjoin/docs/repl.txt +++ b/lib/node_modules/@stdlib/blas/ext/base/gconjoin/docs/repl.txt @@ -1,7 +1,7 @@ {{alias}}( N, prefix, suffix, conjunction, oxfordComma, x, strideX ) - Returns a string created by joining strided array elements into a - human-readable list using a conjunction. + Returns a string created by joining strided array elements into a human- + readable list using a conjunction. The `N` and stride parameters determine which elements in the strided array are accessed at runtime. @@ -47,8 +47,8 @@ {{alias}}.ndarray( N, prefix, suffix, conjunction, oxfordComma, x, sx, ox ) - Returns a string created by joining strided array elements into a - human-readable list using a conjunction and alternative indexing semantics. + Returns a string created by joining strided array elements into a human- + readable list using a conjunction and alternative indexing semantics. While typed array views mandate a view offset based on the underlying buffer, the offset parameter supports indexing semantics based on a starting From b5c72fe22132859fc424ce9f5cfa8b0e5ed98d43 Mon Sep 17 00:00:00 2001 From: headlessNode Date: Thu, 26 Mar 2026 22:40:52 +0500 Subject: [PATCH 4/4] refactor: apply suggestions from code review --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../blas/ext/base/gconjoin/lib/accessors.js | 117 ------------------ .../blas/ext/base/gconjoin/lib/ndarray.js | 31 ++--- 2 files changed, 8 insertions(+), 140 deletions(-) delete mode 100644 lib/node_modules/@stdlib/blas/ext/base/gconjoin/lib/accessors.js diff --git a/lib/node_modules/@stdlib/blas/ext/base/gconjoin/lib/accessors.js b/lib/node_modules/@stdlib/blas/ext/base/gconjoin/lib/accessors.js deleted file mode 100644 index 3dd8af5b4a87..000000000000 --- a/lib/node_modules/@stdlib/blas/ext/base/gconjoin/lib/accessors.js +++ /dev/null @@ -1,117 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2026 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. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isUndefinedOrNull = require( '@stdlib/assert/is-undefined-or-null' ); -var gjoin = require( '@stdlib/blas/ext/base/gjoin' ).ndarray; - - -// VARIABLES // - -var SEP = ', '; -var SPACE = ' '; - - -// FUNCTIONS // - -/** -* Returns the string representation of an array element. -* -* @private -* @param {Function} get - accessor function -* @param {Collection} xbuf - data buffer -* @param {integer} idx - element index -* @returns {string} string representation -*/ -function str( get, xbuf, idx ) { - var v = get( xbuf, idx ); - if ( isUndefinedOrNull( v ) ) { - return ''; - } - return String( v ); -} - - -// MAIN // - -/** -* Returns a string created by joining strided array elements into a human-readable list using a conjunction. -* -* @private -* @param {PositiveInteger} N - number of indexed elements -* @param {string} prefix - string to prepend -* @param {string} suffix - string to append -* @param {string} conjunction - conjunction before the last element -* @param {boolean} oxfordComma - boolean specifying whether to include an Oxford comma -* @param {Object} x - input array object -* @param {Collection} x.data - input array data -* @param {Array} x.accessors - array element accessors -* @param {integer} strideX - stride length -* @param {NonNegativeInteger} offsetX - starting index -* @returns {string} joined string -* -* @example -* var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); -* var arraylike2object = require( '@stdlib/array/base/arraylike2object' ); -* -* var x = [ 1, 2, 3, 4 ]; -* -* var out = gconjoin( x.length, '', '', 'and', true, arraylike2object( toAccessorArray( x ) ), 1, 0 ); -* // returns '1, 2, 3, and 4' -*/ -function gconjoin( N, prefix, suffix, conjunction, oxfordComma, x, strideX, offsetX ) { // eslint-disable-line max-len - var xbuf; - var last; - var out; - var get; - var ix; - var i; - - // Cache reference to array data: - xbuf = x.data; - - // Cache a reference to the element accessor: - get = x.accessors[ 0 ]; - if ( conjunction === '' || N === 1 ) { - return prefix + gjoin( N, SEP, xbuf, strideX, offsetX ) + suffix; - } - if ( strideX === 1 ) { - out = prefix + gjoin( N-1, SEP, xbuf, strideX, offsetX ); - } else { - ix = offsetX; - out = prefix + str( get, xbuf, ix ); - ix += strideX; - for ( i = 1; i < N - 1; i++ ) { - out += SEP + str( get, xbuf, ix ); - ix += strideX; - } - } - last = str( get, xbuf, offsetX + ( (N-1) * strideX ) ); - if ( N >= 3 && oxfordComma ) { - return out + SEP + conjunction + SPACE + last + suffix; - } - return out + SPACE + conjunction + SPACE + last + suffix; -} - - -// EXPORTS // - -module.exports = gconjoin; diff --git a/lib/node_modules/@stdlib/blas/ext/base/gconjoin/lib/ndarray.js b/lib/node_modules/@stdlib/blas/ext/base/gconjoin/lib/ndarray.js index b803b202726d..97b8977c4e0e 100644 --- a/lib/node_modules/@stdlib/blas/ext/base/gconjoin/lib/ndarray.js +++ b/lib/node_modules/@stdlib/blas/ext/base/gconjoin/lib/ndarray.js @@ -21,9 +21,8 @@ // MODULES // var isUndefinedOrNull = require( '@stdlib/assert/is-undefined-or-null' ); -var arraylike2object = require( '@stdlib/array/base/arraylike2object' ); +var resolveGetter = require( '@stdlib/array/base/resolve-getter' ); var gjoin = require( '@stdlib/blas/ext/base/gjoin' ).ndarray; -var accessors = require( './accessors.js' ); // VARIABLES // @@ -38,12 +37,13 @@ var SPACE = ' '; * Returns the string representation of an array element. * * @private +* @param {Function} get - accessor function * @param {Collection} x - input array * @param {integer} idx - element index * @returns {string} string representation */ -function str( x, idx ) { - var v = x[ idx ]; +function str( get, x, idx ) { + var v = get( x, idx ); if ( isUndefinedOrNull( v ) ) { return ''; } @@ -75,32 +75,17 @@ function str( x, idx ) { function gconjoin( N, prefix, suffix, conjunction, oxfordComma, x, strideX, offsetX ) { // eslint-disable-line max-len var last; var out; - var ix; - var o; - var i; + var get; if ( N <= 0 ) { return prefix + suffix; } - o = arraylike2object( x ); - if ( o.accessorProtocol ) { - return accessors( N, prefix, suffix, conjunction, oxfordComma, o, strideX, offsetX ); // eslint-disable-line max-len - } if ( conjunction === '' || N === 1 ) { return prefix + gjoin( N, SEP, x, strideX, offsetX ) + suffix; } - if ( strideX === 1 ) { - out = prefix + gjoin( N-1, SEP, x, strideX, offsetX ); - } else { - ix = offsetX; - out = prefix + str( x, ix ); - ix += strideX; - for ( i = 1; i < N - 1; i++ ) { - out += SEP + str( x, ix ); - ix += strideX; - } - } - last = str( x, offsetX + ( (N-1) * strideX ) ); + get = resolveGetter( x ); + out = prefix + gjoin( N-1, SEP, x, strideX, offsetX ); + last = str( get, x, offsetX + ( (N-1) * strideX ) ); if ( N >= 3 && oxfordComma ) { return out + SEP + conjunction + SPACE + last + suffix; }