diff --git a/lib/node_modules/@stdlib/array/uint64/README.md b/lib/node_modules/@stdlib/array/uint64/README.md index f0d84ef9697c..18e1670af23e 100644 --- a/lib/node_modules/@stdlib/array/uint64/README.md +++ b/lib/node_modules/@stdlib/array/uint64/README.md @@ -258,11 +258,11 @@ arr.set( 2, 1 ); arr.set( 9, 9 ); // Get the first element: -var z = arr.at( 0 ); +var u = arr.at( 0 ); // returns [ 1n ] // Get the last element: -z = arr.at( -1 ); +u = arr.at( -1 ); // returns [ 9n ] ``` @@ -271,10 +271,10 @@ If provided an out-of-bounds index, the method returns `undefined`. ```javascript var arr = new Uint64Array( 10 ); -var z = arr.at( 100 ); +var u = arr.at( 100 ); // returns undefined -z = arr.at( -100 ); +u = arr.at( -100 ); // returns undefined ``` @@ -287,12 +287,7 @@ Returns an iterator for iterating over array key-value pairs. ```javascript var Uint64 = require( '@stdlib/number/uint64/ctor' ); -var arr = [ - new Uint64( 1 ), - new Uint64( 2 ), - new Uint64( 3 ) -]; -arr = new Uint64Array( arr ); +var arr = new Uint64Array( [ 1, 2, 3 ] ); // Create an iterator: var it = arr.entries(); @@ -329,7 +324,7 @@ var arr = new Uint64Array( 10 ); arr.set( 1, 0 ); // Get the first element: -var z = arr.get( 0 ); +var u = arr.get( 0 ); // returns [ 1n ] ``` @@ -338,7 +333,7 @@ If provided an out-of-bounds index, the method returns `undefined`. ```javascript var arr = new Uint64Array( 10 ); -var z = arr.get( 100 ); +var u = arr.get( 100 ); // returns undefined ``` @@ -355,14 +350,14 @@ var arr = new Uint64Array( [ 1, 2, 3 ] ); // returns [ 1n, 2n, 3n ] // Get the first element: -var z = arr.get( 0 ); +var u = arr.get( 0 ); // returns [ 1n ] // Set the first element: arr.set( new Uint64( 5 ) ); // Get the first element: -z = arr.get( 0 ); +u = arr.get( 0 ); // returns [ 5n ] ``` @@ -375,14 +370,14 @@ var arr = new Uint64Array( [ 1, 2, 3 ] ); // returns [ 1n, 2n, 3n ] // Get the third element: -var z = arr.get( 2 ); +var u = arr.get( 2 ); // returns [ 3n ] // Set the third element: arr.set( new Uint64( 5 ), 2 ); // Get the third element: -z = arr.get( 2 ); +u = arr.get( 2 ); // returns [ 5n ] ``` @@ -397,10 +392,10 @@ var arr = new Uint64Array( [ 1, 2, 3 ] ); // Set the first two array elements: arr.set( [ 4, 5 ] ); -var z = arr.get( 0 ); +var u = arr.get( 0 ); // returns [ 4n ] -z = arr.get( 1 ); +u = arr.get( 1 ); // returns [ 5n ] ``` diff --git a/lib/node_modules/@stdlib/array/uint64/docs/repl.txt b/lib/node_modules/@stdlib/array/uint64/docs/repl.txt index 6dd3c27d5987..c737fc5bf588 100644 --- a/lib/node_modules/@stdlib/array/uint64/docs/repl.txt +++ b/lib/node_modules/@stdlib/array/uint64/docs/repl.txt @@ -248,7 +248,7 @@ -------- > var arr = new {{alias}}( [ 1, 2 ] ) [ 1n, 2n ] - > var z = arr.at( 1 ) + > var u = arr.at( 1 ) [ 2n ] @@ -295,7 +295,7 @@ -------- > var arr = new {{alias}}( [ 1, 2 ] ) [ 1n, 2n ] - > var z = arr.get( 1 ) + > var u = arr.get( 1 ) [ 2n ] @@ -320,12 +320,12 @@ -------- > var arr = new {{alias}}( [ 1, 2, 3 ] ); > arr.set( new {{alias:@stdlib/number/uint64/ctor}}( 4 ), 1 ); - > var z = arr.get( 1 ) + > var u = arr.get( 1 ) [ 4n ] > arr.set( [ 5, 6 ], 1 ); - > z = arr.get( 1 ) + > u = arr.get( 1 ) [ 5n ] - > z = arr.get( 2 ) + > u = arr.get( 2 ) [ 6n ] See Also diff --git a/lib/node_modules/@stdlib/array/uint64/docs/types/index.d.ts b/lib/node_modules/@stdlib/array/uint64/docs/types/index.d.ts index 73e7941a80c5..78b11c503625 100644 --- a/lib/node_modules/@stdlib/array/uint64/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/array/uint64/docs/types/index.d.ts @@ -434,12 +434,7 @@ declare class Uint64Array implements Uint64ArrayInterface { * @example * var Uint64 = require( '@stdlib/number/uint64/ctor' ); * - * var arr = [ - * new Uint64( 1 ), - * new Uint64( 2 ), - * new Uint64( 3 ) - * ]; - * arr = new Uint64Array( arr ); + * var arr = new Uint64Array( [ 1, 2, 3 ] ); * * // Create an iterator: * var it = arr.entries(); @@ -469,15 +464,15 @@ declare class Uint64Array implements Uint64ArrayInterface { * @example * var arr = new Uint64Array( 10 ); * - * var z = arr.get( 0 ); + * var u = arr.get( 0 ); * // returns [ 0n ] * * arr.set( 1, 0 ); * - * var z = arr.get( 0 ); + * u = arr.get( 0 ); * // returns [ 1n ] * - * z = arr.get( 100 ); + * u = arr.get( 100 ); * // returns undefined */ get( i: number ): Uint64 | void; @@ -516,12 +511,12 @@ declare class Uint64Array implements Uint64ArrayInterface { * @example * var arr = new Uint64Array( 10 ); * - * var z = arr.get( 0 ); + * var u = arr.get( 0 ); * // returns [ 0n ] * * arr.set( 1, 0 ); * - * z = arr.get( 0 ); + * u = arr.get( 0 ); * // returns [ 1n ] */ set( value: ArrayLike | Uint64Array | Uint, i?: number ): void; diff --git a/lib/node_modules/@stdlib/array/uint64/lib/from_array.js b/lib/node_modules/@stdlib/array/uint64/lib/from_array.js index 0486566e4ac7..bccdf89e6e8c 100644 --- a/lib/node_modules/@stdlib/array/uint64/lib/from_array.js +++ b/lib/node_modules/@stdlib/array/uint64/lib/from_array.js @@ -20,11 +20,10 @@ // MODULES // -var isUint64 = require( '@stdlib/assert/is-uint64' ); var toWords = require( '@stdlib/number/uint64/base/to-words' ).assign; -var Uint64 = require( '@stdlib/number/uint64/ctor' ); var format = require( '@stdlib/string/format' ); var indices = require( './indices.js' ); +var scalarToUint64 = require( './scalar_to_uint64.js' ); // MAIN // @@ -50,13 +49,9 @@ function fromArray( buf, arr ) { len = arr.length; j = 0; for ( i = 0; i < len; i++ ) { - v = arr[ i ]; - if ( !isUint64( v ) ) { - try { - v = new Uint64( v ); - } catch ( err ) { // eslint-disable-line no-unused-vars - return new TypeError( format( 'invalid argument. An array element must be either a 64-bit unsigned integer or a value which can be converted to a 64-bit unsigned integer. Value: `%s`.', v ) ); - } + v = scalarToUint64( arr[ i ] ); + if ( v instanceof Error ) { + return new TypeError( format( 'invalid argument. An array element must be either a 64-bit unsigned integer or a value which can be converted to a 64-bit unsigned integer. Value: `%s`.', arr[ i ] ) ); } toWords( v, words, 1, 0 ); buf[ j+indices.HIGH ] = words[ 0 ]; diff --git a/lib/node_modules/@stdlib/array/uint64/lib/from_iterator.js b/lib/node_modules/@stdlib/array/uint64/lib/from_iterator.js index 4e4ccb930231..1f7c3bcecc3b 100644 --- a/lib/node_modules/@stdlib/array/uint64/lib/from_iterator.js +++ b/lib/node_modules/@stdlib/array/uint64/lib/from_iterator.js @@ -20,10 +20,9 @@ // MODULES // -var isUint64 = require( '@stdlib/assert/is-uint64' ); var toWords = require( '@stdlib/number/uint64/base/to-words' ).assign; -var Uint64 = require( '@stdlib/number/uint64/ctor' ); var format = require( '@stdlib/string/format' ); +var scalarToUint64 = require( './scalar_to_uint64.js' ); // MAIN // @@ -50,13 +49,9 @@ function fromIterator( it ) { if ( v.done ) { break; } - u = v.value; - if ( !isUint64( u ) ) { - try { - u = new Uint64( u ); - } catch ( err ) { // eslint-disable-line no-unused-vars - return new TypeError( format( 'invalid argument. An iterator must return either a 64-bit unsigned integer or a value which can be converted to a 64-bit unsigned integer. Value: `%s`.', u ) ); - } + u = scalarToUint64( v.value ); + if ( u instanceof Error ) { + return new TypeError( format( 'invalid argument. An iterator must return either a 64-bit unsigned integer or a value which can be converted to a 64-bit unsigned integer. Value: `%s`.', v.value ) ); } toWords( u, words, 1, 0 ); out.push( words[ 0 ], words[ 1 ] ); diff --git a/lib/node_modules/@stdlib/array/uint64/lib/from_iterator_map.js b/lib/node_modules/@stdlib/array/uint64/lib/from_iterator_map.js index 527fe5b936ad..0997d036e3a2 100644 --- a/lib/node_modules/@stdlib/array/uint64/lib/from_iterator_map.js +++ b/lib/node_modules/@stdlib/array/uint64/lib/from_iterator_map.js @@ -20,10 +20,9 @@ // MODULES // -var isUint64 = require( '@stdlib/assert/is-uint64' ); var toWords = require( '@stdlib/number/uint64/base/to-words' ).assign; -var Uint64 = require( '@stdlib/number/uint64/ctor' ); var format = require( '@stdlib/string/format' ); +var scalarToUint64 = require( './scalar_to_uint64.js' ); // MAIN // @@ -42,6 +41,7 @@ function fromIteratorMap( it, clbk, thisArg ) { var out; var v; var u; + var r; var i; // Workspace for storing high and low words: @@ -55,13 +55,10 @@ function fromIteratorMap( it, clbk, thisArg ) { break; } i += 1; - u = clbk.call( thisArg, v.value, i ); - if ( !isUint64( u ) ) { - try { - u = new Uint64( u ); - } catch ( err ) { // eslint-disable-line no-unused-vars - return new TypeError( format( 'invalid argument. An iterator must return either a 64-bit unsigned integer or a value which can be converted to a 64-bit unsigned integer. Value: `%s`.', u ) ); - } + r = clbk.call( thisArg, v.value, i ); + u = scalarToUint64( r ); + if ( u instanceof Error ) { + return new TypeError( format( 'invalid argument. An iterator must return either a 64-bit unsigned integer or a value which can be converted to a 64-bit unsigned integer. Value: `%s`.', r ) ); } toWords( u, words, 1, 0 ); out.push( words[ 0 ], words[ 1 ] ); diff --git a/lib/node_modules/@stdlib/array/uint64/lib/main.js b/lib/node_modules/@stdlib/array/uint64/lib/main.js index dd158c90cb94..92908ee29a86 100644 --- a/lib/node_modules/@stdlib/array/uint64/lib/main.js +++ b/lib/node_modules/@stdlib/array/uint64/lib/main.js @@ -47,6 +47,7 @@ var indices = require( './indices.js' ); var fromIterator = require( './from_iterator.js' ); var fromIteratorMap = require( './from_iterator_map.js' ); var fromArray = require( './from_array.js' ); +var scalarToUint64 = require( './scalar_to_uint64.js' ); // VARIABLES // @@ -403,13 +404,10 @@ setReadOnly( Uint64Array, 'from', function from( src ) { words = [ 0, 0 ]; j = 0; for ( i = 0; i < len; i++ ) { - v = clbk.call( thisArg, get( src, i ), i ); - if ( !isUint64( v ) ) { - try { - v = new Uint64( v ); - } catch ( err ) { // eslint-disable-line no-unused-vars - throw new TypeError( format( 'invalid argument. A callback must return either a 64-bit unsigned integer or a value which can be converted to a 64-bit unsigned integer. Value: `%s`.', v ) ); - } + tmp = clbk.call( thisArg, get( src, i ), i ); + v = scalarToUint64( tmp ); + if ( v instanceof Error ) { + throw new TypeError( format( 'invalid argument. A callback must return either a 64-bit unsigned integer or a value which can be converted to a 64-bit unsigned integer. Value: `%s`.', tmp ) ); } toWords( v, words, 1, 0 ); buf[ j+indices.HIGH ] = words[ 0 ]; @@ -611,12 +609,7 @@ setReadOnly( Uint64Array.prototype, 'BYTES_PER_ELEMENT', Uint64Array.BYTES_PER_E * @example * var Uint64 = require( '@stdlib/number/uint64/ctor' ); * -* var arr = [ -* new Uint64( 1 ), -* new Uint64( 2 ), -* new Uint64( 3 ) -* ]; -* arr = new Uint64Array( arr ); +* var arr = new Uint64Array( [ 1, 2, 3 ] ); * * // Create an iterator: * var it = arr.entries(); @@ -725,15 +718,15 @@ setReadOnly( Uint64Array.prototype, 'entries', function entries() { * @example * var arr = new Uint64Array( 10 ); * -* var z = arr.get( 0 ); +* var u = arr.get( 0 ); * // returns [ 0n ] * * arr.set( [ 1 ], 0 ); * -* z = arr.get( 0 ); +* u = arr.get( 0 ); * // returns [ 1n ] * -* z = arr.get( 100 ); +* u = arr.get( 100 ); * // returns undefined */ setReadOnly( Uint64Array.prototype, 'get', function get( idx ) { @@ -806,12 +799,12 @@ setReadOnlyAccessor( Uint64Array.prototype, 'length', function get() { * @example * var arr = new Uint64Array( 10 ); * -* var z = arr.get( 0 ); +* var u = arr.get( 0 ); * // returns [ 0n ] * * arr.set( 1n, 0 ); * -* z = arr.get( 0 ); +* u = arr.get( 0 ); * // returns [ 1n ] */ setReadOnly( Uint64Array.prototype, 'set', function set( value ) { @@ -912,13 +905,9 @@ setReadOnly( Uint64Array.prototype, 'set', function set( value ) { } idx *= 2; for ( i = 0; i < N; i++ ) { - v = sbuf[ i ]; - if ( !isUint64( v ) ) { - try { - v = new Uint64( v ); - } catch ( err ) { // eslint-disable-line no-unused-vars - throw new TypeError( format( 'invalid argument. An array element must be either a 64-bit unsigned integer or a value which can be converted to a 64-bit unsigned integer. Value: `%s`.', v ) ); - } + v = scalarToUint64( sbuf[ i ] ); + if ( v instanceof Error ) { + throw new TypeError( format( 'invalid argument. An array element must be either a 64-bit unsigned integer or a value which can be converted to a 64-bit unsigned integer. Value: `%s`.', sbuf[ i ] ) ); } toWords( v, words, 1, 0 ); buf[ idx+indices.HIGH ] = words[ 0 ]; diff --git a/lib/node_modules/@stdlib/array/uint64/lib/scalar_to_uint64.js b/lib/node_modules/@stdlib/array/uint64/lib/scalar_to_uint64.js new file mode 100644 index 000000000000..289944096191 --- /dev/null +++ b/lib/node_modules/@stdlib/array/uint64/lib/scalar_to_uint64.js @@ -0,0 +1,51 @@ +/** +* @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 isUint64 = require( '@stdlib/assert/is-uint64' ); +var Uint64 = require( '@stdlib/number/uint64/ctor' ); +var format = require( '@stdlib/string/format' ); + + +// MAIN // + +/** +* Converts a value to a 64-bit unsigned integer. +* +* @private +* @param {*} value - value to convert +* @returns {(Uint64|TypeError)} 64-bit unsigned integer or an error +*/ +function scalarToUint64( value ) { + if ( isUint64( value ) ) { + return value; + } + try { + return new Uint64( value ); + } catch ( err ) { // eslint-disable-line no-unused-vars + return new TypeError( format( 'invalid argument. Value must be either a 64-bit unsigned integer or a value which can be converted to a 64-bit unsigned integer. Value: `%s`.', value ) ); + } +} + + +// EXPORTS // + +module.exports = scalarToUint64;