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..2a25b1f92b92 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gconjoin/README.md @@ -0,0 +1,188 @@ + + +# gconjoin + +> Return a string created by joining strided array elements into a human-readable list 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 into a human-readable list 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 into a human-readable list 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 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]). + +
+ + + + + +
+ +## 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..d33ecd255aab --- /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 into a human- + readable list 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 the prefix followed by the suffix. + + 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 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 + 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..7d190e27b2d5 --- /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 into a human-readable list 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 into a human-readable list 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 into a human-readable list 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/index.js b/lib/node_modules/@stdlib/blas/ext/base/gconjoin/lib/index.js new file mode 100644 index 000000000000..ed3d198c9d5f --- /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 into a human-readable list 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..2b0a2e1f13f2 --- /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 into a human-readable list 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..97b8977c4e0e --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gconjoin/lib/ndarray.js @@ -0,0 +1,98 @@ +/** +* @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 resolveGetter = require( '@stdlib/array/base/resolve-getter' ); +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} x - input array +* @param {integer} idx - element index +* @returns {string} string representation +*/ +function str( get, x, idx ) { + var v = get( x, 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 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 last; + var out; + var get; + + if ( N <= 0 ) { + return prefix + suffix; + } + if ( conjunction === '' || N === 1 ) { + return prefix + gjoin( N, SEP, x, strideX, offsetX ) + suffix; + } + 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; + } + return out + SPACE + conjunction + SPACE + last + 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..8f3d29ba829a --- /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 into a human-readable list 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..0ca26ebed025 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gconjoin/test/test.main.js @@ -0,0 +1,180 @@ +/** +* @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 Complex128Array = require( '@stdlib/array/complex128' ); +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 into a human-readable list 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 into a human-readable list 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 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 ); + t.strictEqual( actual, '', 'returns expected value' ); + + 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 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 ); + t.strictEqual( actual, '', 'returns expected value' ); + + 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 new file mode 100644 index 000000000000..f89b035a6647 --- /dev/null +++ b/lib/node_modules/@stdlib/blas/ext/base/gconjoin/test/test.ndarray.js @@ -0,0 +1,186 @@ +/** +* @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 Complex128Array = require( '@stdlib/array/complex128' ); +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 into a human-readable list 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 into a human-readable list 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 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 ); + t.strictEqual( actual, '', 'returns expected value' ); + + 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 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 ); + t.strictEqual( actual, '', 'returns expected value' ); + + 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(); +});