Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion lib/node_modules/@stdlib/array/fixed-endian-factory/lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
var isPrototypeOf = require( '@stdlib/assert/is-prototype-of' ); // eslint-disable-line stdlib/no-redeclare
var setReadOnlyAccessor = require( '@stdlib/utils/define-nonenumerable-read-only-accessor' );
var ArrayBuffer = require( '@stdlib/array/buffer' );
var Uint8Array = require( '@stdlib/array/uint8' );
var DataView = require( '@stdlib/array/dataview' );
var getter = require( '@stdlib/array/base/getter' );
var accessorGetter = require( '@stdlib/array/base/accessor-getter' );
Expand Down Expand Up @@ -225,7 +226,7 @@
* Typed array constructor which returns a typed array representing an array of values in a specified byte order.
*
* @private
* @constructor

Check failure on line 229 in lib/node_modules/@stdlib/array/fixed-endian-factory/lib/main.js

View workflow job for this annotation

GitHub Actions / Lint Changed Files

Invalid JSDoc tag (preference). Replace "constructor" JSDoc tag with "class"
* @param {string} endianness - byte order
* @param {(NonNegativeInteger|Collection|ArrayBuffer|Iterable)} [arg] - length, typed array, array-like object, buffer, or an iterable
* @param {NonNegativeInteger} [byteOffset=0] - byte offset
Expand Down Expand Up @@ -1141,6 +1142,9 @@
*/
setReadOnly( TypedArray.prototype, 'with', function copyWith( index, value ) {
var outbuf;
var nbytes;
var dest;
var src;
var buf;
var out;
var len;
Expand All @@ -1159,7 +1163,11 @@
if ( index < 0 || index >= len ) {
throw new RangeError( format( 'invalid argument. Index argument is out-of-bounds. Value: `%s`.', index ) );
}
out = new this.constructor( flag2byteOrder( this._isLE ), buf.buffer );
nbytes = len * BYTES_PER_ELEMENT;
src = new Uint8Array( buf.buffer, buf.byteOffset, nbytes );
dest = new Uint8Array( new ArrayBuffer( nbytes ) );
dest.set( src );
out = new this.constructor( flag2byteOrder( this._isLE ), dest.buffer );
outbuf = out._buffer; // eslint-disable-line no-underscore-dangle
outbuf[ SETTER ]( index * BYTES_PER_ELEMENT, value, this._isLE );
return out;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ var tape = require( 'tape' );
var hasSameValues = require( '@stdlib/array/base/assert/has-same-values' );
var hasOwnProp = require( '@stdlib/assert/has-own-property' );
var isFunction = require( '@stdlib/assert/is-function' );
var ArrayBuffer = require( '@stdlib/array/buffer' );
var factory = require( './../lib' );


Expand Down Expand Up @@ -187,3 +188,57 @@ tape( 'the method supports negative indices', function test( t ) {
t.notEqual( actual, arr, 'returns new instance' );
t.end();
});

tape( 'the method does not mutate the original array', function test( t ) {
var expected;
var actual;
var ctor;
var arr;

ctor = factory( 'float64' );
arr = new ctor( 'little-endian', [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );
expected = new ctor( 'little-endian', [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );
actual = arr.with( 0, 0.0 );

t.notEqual( actual.buffer, arr.buffer, 'returns expected value' );
t.strictEqual( hasSameValues( arr, expected ), true, 'returns expected value' );
t.end();
});

tape( 'the method supports typed arrays which are views on an underlying buffer', function test( t ) {
var expected;
var actual;
var ctor;
var arr;
var buf;

ctor = factory( 'float64' );
buf = new ArrayBuffer( 40 );
arr = new ctor( 'little-endian', buf, 8, 3 );
arr.set( [ 1.0, 2.0, 3.0 ] );

expected = new ctor( 'little-endian', [ 1.0, 0.0, 3.0 ] );
actual = arr.with( 1, 0.0 );

t.strictEqual( actual.length, 3, 'returns expected value' );
t.strictEqual( hasSameValues( actual, expected ), true, 'returns expected value' );

expected = new ctor( 'little-endian', [ 1.0, 2.0, 3.0 ] );
t.strictEqual( hasSameValues( arr, expected ), true, 'returns expected value' );
t.end();
});

tape( 'the method returns a typed array having the same byte order as the original array', function test( t ) {
var expected;
var actual;
var ctor;
var arr;

ctor = factory( 'float64' );
arr = new ctor( 'big-endian', [ 1.0, 2.0, 3.0 ] );
expected = new ctor( 'big-endian', [ 1.0, 2.0, 0.0 ] );
actual = arr.with( 2, 0.0 );

t.strictEqual( hasSameValues( actual, expected ), true, 'returns expected value' );
t.end();
});
Loading