compute-array-constructors

Returns an array constructor corresponding to an array data type.

Downloads in past

Stats

StarsIssuesVersionUpdatedCreatedSize
compute-array-constructors
311.0.18 years ago8 years agoMinified + gzip package size for compute-array-constructors in KB

Readme

Array Constructors
!NPM versionnpm-imagenpm-url !Build Statustravis-imagetravis-url !Coverage Statuscodecov-imagecodecov-url !Dependenciesdependencies-imagedependencies-url
Returns an array constructor corresponding to an array data type.

Installation

$ npm install compute-array-constructors

For use in the browser, use browserify.

Usage

var getCtor = require( 'compute-array-constructors' );

getCtor( dtype )

Returns an array constructor corresponding to an array data type.
var ctor = getCtor( 'int8' );
// returns Int8Array

The following array data types are supported:
| Data Type | Constructor | |:----------|:------------| | int8 | Int8ArrayInt8Array | | uint8 | Uint8ArrayUint8Array | | uint8clamped | Uint8ClampedArrayUint8ClampedArray | | int16 | Int16ArrayInt16Array | | uint16 | Uint16ArrayUint16Array | | int32 | Int32ArrayInt32Array | | uint32 | Uint32ArrayUint32Array | | float32 | Float32ArrayFloat32Array | | float64 | Float64ArrayFloat64Array | | generic | ArrayArray |

Examples

var getCtor = require( 'compute-array-constructors' );

console.log( getCtor( 'int8' ) );
// returns Int8Array

console.log( getCtor( 'uint8' ) );
// returns Uint8Array

console.log( getCtor( 'uint8_clamped' ) );
// returns Uint8ClampedArray

console.log( getCtor( 'int16' ) );
// returns Int16Array

console.log( getCtor( 'uint16' ) );
// returns Uint16Array

console.log( getCtor( 'int32' ) );
// returns Int32Array

console.log( getCtor( 'uint32' ) );
// returns Uint32Array

console.log( getCtor( 'float32' ) );
// returns Float32Array

console.log( getCtor( 'float64' ) );
// returns Float64Array

console.log( getCtor( 'generic' ) );
// returns Array

console.log( getCtor( null ) );
// returns null

console.log( getCtor( 'object' ) );
// returns null

console.log( getCtor( 'array' ) );
// returns null

console.log( getCtor( {} ) );
// returns null

console.log( getCtor( [] ) );
// returns null

To run the example code from the top-level application directory,
$ node ./examples/index.js

Tests

Unit

Unit tests use the Mochamocha test framework with Chaichai assertions. To run the tests, execute the following command in the top-level application directory:
$ make test

All new feature development should have corresponding unit tests to validate correct functionality.

Test Coverage

This repository uses Istanbulistanbul as its code coverage tool. To generate a test coverage report, execute the following command in the top-level application directory:
$ make test-cov

Istanbul creates a ./reports/coverage directory. To access an HTML version of the report,
$ make view-cov

License

MIT license.

Copyright

Copyright © 2015. The Compute.io Authors.