array-little-endian-factory

Return a typed array constructor for creating typed arrays stored in little-endian byte order.

https://github.com/stdlib-js/array-little-endian-factory

Science Score: 44.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
    Found CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
  • Academic publication links
  • Academic email domains
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (16.8%) to scientific vocabulary

Keywords

array byte-order data endian factory javascript little-endian node node-js nodejs stdlib structure typed typed-array types
Last synced: 6 months ago · JSON representation ·

Repository

Return a typed array constructor for creating typed arrays stored in little-endian byte order.

Basic Info
Statistics
  • Stars: 1
  • Watchers: 2
  • Forks: 0
  • Open Issues: 0
  • Releases: 0
Topics
array byte-order data endian factory javascript little-endian node node-js nodejs stdlib structure typed typed-array types
Created over 1 year ago · Last pushed 9 months ago
Metadata Files
Readme Changelog Contributing License Code of conduct Citation Security

README.md

About stdlib...

We believe in a future in which the web is a preferred environment for numerical computation. To help realize this future, we've built stdlib. stdlib is a standard library, with an emphasis on numerical and scientific computation, written in JavaScript (and C) for execution in browsers and in Node.js.

The library is fully decomposable, being architected in such a way that you can swap out and mix and match APIs and functionality to cater to your exact preferences and use cases.

When you use stdlib, you can be absolutely certain that you are using the most thorough, rigorous, well-written, studied, documented, tested, measured, and high-quality code out there.

To join us in bringing numerical computing to the web, get started by checking us out on GitHub, and please consider financially supporting stdlib. We greatly appreciate your continued support!

littleEndianFactory

NPM version Build Status Coverage Status <!-- dependencies -->

Return a typed array constructor for creating typed arrays stored in little-endian byte order.

In contrast to the built-in typed array constructors which store values according to the host platform byte order, the typed array constructors returned by the factory function always access elements in little-endian byte order. Such enforcement can be particularly advantageous when working with memory buffers which do not necessarily follow host platform byte order, such as [WebAssembly memory][@stdlib/wasm/memory].
## Installation ```bash npm install @stdlib/array-little-endian-factory ``` Alternatively, - To load the package in a website via a `script` tag without installation and bundlers, use the [ES Module][es-module] available on the [`esm`][esm-url] branch (see [README][esm-readme]). - If you are using Deno, visit the [`deno`][deno-url] branch (see [README][deno-readme] for usage intructions). - For use in Observable, or in browser/node environments, use the [Universal Module Definition (UMD)][umd] build available on the [`umd`][umd-url] branch (see [README][umd-readme]). The [branches.md][branches-url] file summarizes the available branches and displays a diagram illustrating their relationships. To view installation and usage instructions specific to each branch build, be sure to explicitly navigate to the respective README files on each branch, as linked to above.
## Usage ```javascript var littleEndianFactory = require( '@stdlib/array-little-endian-factory' ); ``` #### littleEndianFactory( dtype ) Returns a typed array constructor for creating typed arrays having a specified [data type][@stdlib/array/typed-dtypes] and stored in little-endian byte order. ```javascript var Float64ArrayLE = littleEndianFactory( 'float64' ); // returns var Float32ArrayLE = littleEndianFactory( 'float32' ); // returns ``` * * * ### Typed Array Constructor #### TypedArrayLE() A typed array constructor which returns a typed array representing an array of values in little-endian byte order. ```javascript var Float64ArrayLE = littleEndianFactory( 'float64' ); var arr = new Float64ArrayLE(); // returns ``` #### TypedArrayLE( length ) Returns a typed array having a specified length. ```javascript var Float64ArrayLE = littleEndianFactory( 'float64' ); var arr = new Float64ArrayLE( 5 ); // returns ``` #### TypedArrayLE( typedarray ) Creates a typed array from another typed array. ```javascript var Float32Array = require( '@stdlib/array-float32' ); var Float64ArrayLE = littleEndianFactory( 'float64' ); var arr1 = new Float32Array( [ 0.5, 0.5, 0.5 ] ); var arr2 = new Float64ArrayLE( arr1 ); // returns var v = arr2.get( 0 ); // returns 0.5 ``` #### TypedArrayLE( obj ) Creates a typed array from an array-like object or iterable. ```javascript var Float64ArrayLE = littleEndianFactory( 'float64' ); var arr = new Float64ArrayLE( [ 0.5, 0.5, 0.5 ] ); // returns var v = arr.get( 0 ); // returns 0.5 ``` #### TypedArrayLE( buffer\[, byteOffset\[, length]] ) Returns a typed array view of an [`ArrayBuffer`][@stdlib/array/buffer]. ```javascript var ArrayBuffer = require( '@stdlib/array-buffer' ); var Float64ArrayLE = littleEndianFactory( 'float64' ); var buf = new ArrayBuffer( 32 ); var arr = new Float64ArrayLE( buf, 0, 4 ); // returns ``` * * * ### Typed Array Properties #### TypedArrayLE.BYTES_PER_ELEMENT Number of bytes per view element. ```javascript var Float64ArrayLE = littleEndianFactory( 'float64' ); var nbytes = Float64ArrayLE.BYTES_PER_ELEMENT; // returns 8 ``` #### TypedArrayLE.name Typed array constructor name. ```javascript var Float64ArrayLE = littleEndianFactory( 'float64' ); var str = Float64ArrayLE.name; // returns 'Float64ArrayLE' ``` #### TypedArrayLE.prototype.buffer **Read-only** property which returns the [`ArrayBuffer`][@stdlib/array/buffer] referenced by the typed array. ```javascript var Float64ArrayLE = littleEndianFactory( 'float64' ); var arr = new Float64ArrayLE( 5 ); var buf = arr.buffer; // returns ``` #### TypedArrayLE.prototype.byteLength **Read-only** property which returns the length (in bytes) of the typed array. ```javascript var Float64ArrayLE = littleEndianFactory( 'float64' ); var arr = new Float64ArrayLE( 5 ); var byteLength = arr.byteLength; // returns 40 ``` #### TypedArrayLE.prototype.byteOffset **Read-only** property which returns the offset (in bytes) of the typed array from the start of its [`ArrayBuffer`][@stdlib/array/buffer]. ```javascript var Float64ArrayLE = littleEndianFactory( 'float64' ); var arr = new Float64ArrayLE( 5 ); var byteOffset = arr.byteOffset; // returns 0 ``` #### TypedArrayLE.prototype.BYTES_PER_ELEMENT Number of bytes per view element. ```javascript var Float64ArrayLE = littleEndianFactory( 'float64' ); var arr = new Float64ArrayLE( 5 ); var nbytes = arr.BYTES_PER_ELEMENT; // returns 8 ``` #### TypedArrayLE.prototype.length **Read-only** property which returns the number of view elements. ```javascript var Float64ArrayLE = littleEndianFactory( 'float64' ); var arr = new Float64ArrayLE( 5 ); var len = arr.length; // returns 5 ``` * * * ### Typed Array Methods #### TypedArrayLE.from( src\[, map\[, thisArg]] ) Creates a new typed array from an array-like object or an iterable. ```javascript var Float64ArrayLE = littleEndianFactory( 'float64' ); var arr = Float64ArrayLE.from( [ 1.0, -1.0 ] ); // returns var v = arr.get( 0 ); // returns 1.0 ``` To invoke a function for each `src` value, provide a callback function. ```javascript function mapFcn( v ) { return v * 2.0; } var Float64ArrayLE = littleEndianFactory( 'float64' ); var arr = Float64ArrayLE.from( [ 1.0, -1.0 ], mapFcn ); // returns var v = arr.get( 0 ); // returns 2.0 ``` A callback function is provided two arguments: - **value**: source value. - **index**: source index. To set the callback execution context, provide a `thisArg`. ```javascript function mapFcn( v ) { this.count += 1; return v * 2.0; } var Float64ArrayLE = littleEndianFactory( 'float64' ); var ctx = { 'count': 0 }; var arr = Float64ArrayLE.from( [ 1.0, -1.0 ], mapFcn, ctx ); // returns var v = arr.get( 0 ); // returns 2.0 var n = ctx.count; // returns 2 ``` #### TypedArrayLE.of( element0\[, element1\[, ...elementN]] ) Creates a new typed array from a variable number of arguments. ```javascript var Float64ArrayLE = littleEndianFactory( 'float64' ); var arr = Float64ArrayLE.of( 1.0, -1.0 ); // returns var v = arr.get( 0 ); // returns 1.0 ``` #### TypedArrayLE.prototype.get( i ) Returns an array element located at a nonnegative integer position (index) `i`. ```javascript var Float64ArrayLE = littleEndianFactory( 'float64' ); var arr = new Float64ArrayLE( 10 ); // Set the first element: arr.set( 1.0, 0 ); // Get the first element: var v = arr.get( 0 ); // returns 1.0 ``` If provided an out-of-bounds index, the method returns `undefined`. ```javascript var Float64ArrayLE = littleEndianFactory( 'float64' ); var arr = new Float64ArrayLE( 10 ); var v = arr.get( 100 ); // returns undefined ``` #### TypedArrayLE.prototype.set( arr\[, offset] ) Sets array elements. ```javascript var Float64ArrayLE = littleEndianFactory( 'float64' ); var arr = new Float64ArrayLE( [ 1.0, 2.0, 3.0 ] ); // returns var v = arr.get( 0 ); // returns 1.0 v = arr.get( 1 ); // returns 2.0 // Set the first two array elements: arr.set( [ 4.0, 5.0 ] ); v = arr.get( 0 ); // returns 4.0 v = arr.get( 1 ); // returns 5.0 ``` By default, the method starts writing values at the first array index. To specify an alternative index, provide an index `offset`. ```javascript var Float64ArrayLE = littleEndianFactory( 'float64' ); var arr = new Float64ArrayLE( [ 1.0, 2.0, 3.0 ] ); // returns // Set the last two array elements: arr.set( [ 4.0, 5.0 ], 1 ); var v = arr.get( 1 ); // returns 4.0 v = arr.get( 2 ); // returns 5.0 ``` A few notes: - If `i` is out-of-bounds, the method throws an error. - If a target array cannot accommodate all values (i.e., the length of source array plus `i` exceeds the target array length), the method throws an error. - If provided a typed array which shares an [`ArrayBuffer`][@stdlib/array/buffer] with the target array, the method will intelligently copy the source range to the destination range. #### TypedArrayLE.prototype.toString() Serializes an array as a string. ```javascript var Float64ArrayLE = littleEndianFactory( 'float64' ); var arr = new Float64ArrayLE( [ 1.0, 2.0, 3.0 ] ); var str = arr.toString(); // returns '1,2,3' ```
* * * ## Notes - While returned constructors _strive_ to maintain (but do not **guarantee**) consistency with [typed arrays][@stdlib/array/typed], significant deviations from ECMAScript-defined [typed array][@stdlib/array/typed] behavior are as follows: - Constructors **not** require the `new` operator. - Accessing array elements using bracket syntax (e.g., `X[i]`) is **not** supported. Instead, one **must** use the `.get()` method.
* * * ## Examples ```javascript var Float64Array = require( '@stdlib/array-float64' ); var logEach = require( '@stdlib/console-log-each' ); var littleEndianFactory = require( '@stdlib/array-little-endian-factory' ); var Float64ArrayLE = littleEndianFactory( 'float64' ); // Create a typed array by specifying a length: var out = new Float64ArrayLE( 3 ); logEach( '%s', out ); // Create a typed array from an array: var arr = [ 1.0, -1.0, -3.14, 3.14, 0.5, 0.5 ]; out = new Float64ArrayLE( arr ); logEach( '%s', out ); // Create a typed array from an array buffer: arr = new Float64Array( [ 1.0, -1.0, -3.14, 3.14, 0.5, 0.5 ] ); // host byte order out = new Float64ArrayLE( arr.buffer ); logEach( '%s', out ); // Create a typed array from an array buffer view: arr = new Float64Array( [ 1.0, -1.0, -3.14, 3.14, 0.5, 0.5 ] ); // host byte order out = new Float64ArrayLE( arr.buffer, 8, 2 ); logEach( '%s', out ); ```
* * * ## Notice This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. #### Community [![Chat][chat-image]][chat-url] --- ## License See [LICENSE][stdlib-license]. ## Copyright Copyright © 2016-2025. The Stdlib [Authors][stdlib-authors].

Owner

  • Name: stdlib
  • Login: stdlib-js
  • Kind: organization

Standard library for JavaScript.

Citation (CITATION.cff)

cff-version: 1.2.0
title: stdlib
message: >-
  If you use this software, please cite it using the
  metadata from this file.

type: software

authors:
  - name: The Stdlib Authors
    url: https://github.com/stdlib-js/stdlib/graphs/contributors

repository-code: https://github.com/stdlib-js/stdlib
url: https://stdlib.io

abstract: |
  Standard library for JavaScript and Node.js.

keywords:
  - JavaScript
  - Node.js
  - TypeScript
  - standard library
  - scientific computing
  - numerical computing
  - statistical computing

license: Apache-2.0 AND BSL-1.0

date-released: 2016

GitHub Events

Total
  • Push event: 14
Last Year
  • Push event: 14

Dependencies

.github/workflows/benchmark.yml actions
  • actions/checkout 8ade135a41bc03ea155e62e844d188df1ea18608 composite
  • actions/setup-node b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 composite
.github/workflows/cancel.yml actions
  • styfle/cancel-workflow-action 85880fa0301c86cca9da44039ee3bb12d3bedbfa composite
.github/workflows/close_pull_requests.yml actions
  • superbrothers/close-pull-request 9c18513d320d7b2c7185fb93396d0c664d5d8448 composite
.github/workflows/examples.yml actions
  • actions/checkout 8ade135a41bc03ea155e62e844d188df1ea18608 composite
  • actions/setup-node b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 composite
.github/workflows/npm_downloads.yml actions
  • actions/checkout 8ade135a41bc03ea155e62e844d188df1ea18608 composite
  • actions/setup-node b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 composite
  • actions/upload-artifact 5d5d22a31266ced268874388b861e4b58bb5c2f3 composite
  • distributhor/workflow-webhook 48a40b380ce4593b6a6676528cd005986ae56629 composite
.github/workflows/productionize.yml actions
  • 8398a7/action-slack 28ba43ae48961b90635b50953d216767a6bea486 composite
  • actions/checkout 8ade135a41bc03ea155e62e844d188df1ea18608 composite
  • actions/setup-node b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 composite
  • stdlib-js/bundle-action main composite
  • stdlib-js/transform-errors-action main composite
.github/workflows/publish.yml actions
  • 8398a7/action-slack 28ba43ae48961b90635b50953d216767a6bea486 composite
  • JS-DevTools/npm-publish 19c28f1ef146469e409470805ea4279d47c3d35c composite
  • actions/checkout 8ade135a41bc03ea155e62e844d188df1ea18608 composite
  • actions/setup-node b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 composite
  • styfle/cancel-workflow-action 85880fa0301c86cca9da44039ee3bb12d3bedbfa composite
.github/workflows/test.yml actions
  • 8398a7/action-slack 28ba43ae48961b90635b50953d216767a6bea486 composite
  • actions/checkout 8ade135a41bc03ea155e62e844d188df1ea18608 composite
  • actions/setup-node b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 composite
.github/workflows/test_bundles.yml actions
  • 8398a7/action-slack 28ba43ae48961b90635b50953d216767a6bea486 composite
  • actions/checkout 8ade135a41bc03ea155e62e844d188df1ea18608 composite
  • actions/setup-node b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 composite
  • denoland/setup-deno 041b854f97b325bd60e53e9dc2de9cb9f9ac0cba composite
.github/workflows/test_coverage.yml actions
  • 8398a7/action-slack 28ba43ae48961b90635b50953d216767a6bea486 composite
  • actions/checkout 8ade135a41bc03ea155e62e844d188df1ea18608 composite
  • actions/setup-node b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 composite
  • codecov/codecov-action 84508663e988701840491b86de86b666e8a86bed composite
  • distributhor/workflow-webhook 48a40b380ce4593b6a6676528cd005986ae56629 composite
.github/workflows/test_install.yml actions
  • 8398a7/action-slack 28ba43ae48961b90635b50953d216767a6bea486 composite
  • actions/checkout 8ade135a41bc03ea155e62e844d188df1ea18608 composite
  • actions/setup-node b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 composite
.github/workflows/test_published_package.yml actions
  • 8398a7/action-slack 28ba43ae48961b90635b50953d216767a6bea486 composite
  • actions/checkout 8ade135a41bc03ea155e62e844d188df1ea18608 composite
  • actions/setup-node b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 composite
package.json npm
  • @stdlib/array-buffer ^0.2.2 development
  • @stdlib/array-float64 ^0.2.2 development
  • @stdlib/array-zero-to ^0.2.2 development
  • @stdlib/assert-is-arraybuffer ^0.2.2 development
  • @stdlib/assert-is-nonnegative-integer ^0.2.2 development
  • @stdlib/assert-is-number ^0.2.2 development
  • @stdlib/bench-harness ^0.2.2 development
  • @stdlib/console-log-each ^0.2.2 development
  • @stdlib/math-base-special-pow ^0.3.0 development
  • @stdlib/random-array-randu ^0.2.1 development
  • istanbul ^0.4.1 development
  • tap-min git+https://github.com/Planeshifter/tap-min.git development
  • tape git+https://github.com/kgryte/tape.git#fix/globby development
  • @stdlib/array-base-accessor-getter ^0.2.2
  • @stdlib/array-base-getter ^0.2.2
  • @stdlib/array-fixed-endian-factory github:stdlib-js/array-fixed-endian-factory#main
  • @stdlib/assert-has-iterator-symbol-support ^0.2.2
  • @stdlib/assert-is-collection ^0.2.2
  • @stdlib/assert-is-function ^0.2.2
  • @stdlib/assert-is-object ^0.2.2
  • @stdlib/error-tools-fmtprodmsg ^0.2.2
  • @stdlib/ndarray-base-bytes-per-element ^0.2.2
  • @stdlib/string-base-capitalize ^0.3.0
  • @stdlib/string-format ^0.2.2
  • @stdlib/symbol-iterator ^0.2.2
  • @stdlib/utils-define-nonenumerable-read-only-property ^0.2.2
  • @stdlib/utils-inherit ^0.2.2