Join us to discuss the challenges, solutions and best practices for in-house JavaScript code sharing. Tuesday, 12/17 at 10am PT/1pm ET.Sign up here »

babel-plugin-multidimensional-array

1.0.0 • Public • Published

babel-plugin-multidimensional-array

Fast multidimensional typed arrays with a nice syntax.

Typed arrays are awesome, but sometimes you want a multidimensional array. You can do it with arrays of (arrays of...) typed arrays, but accessing or writing data to nested array objects is slow.

One way to fix this is by using a single flattened typed array, and hand calculating the offset where the data is for every access. But that is tedious. This babel plugin takes care of it for you. Just define your local variables or function arguments with dimensions, and accesses will be transformed to compute the correct offset.

Example

Compiles this:

let x[2][3] = new Uint8Array([1,2,3,4,5,6]);
x[1][2] = 42;

into:

let x = new Uint8Array([1,2,3,4,5,6]);
x[5] = 42;

Function arguments are also supported, as are non-constant dimensions:

function test(x[a][b], y) {
  x[1][y] = 4;
}

compiles to:

function test(x, y) {
  x[+ b * 1] = 4;
}

Licence

MIT

Install

npm i babel-plugin-multidimensional-array

DownloadsWeekly Downloads

1

Version

1.0.0

License

MIT

Last publish

Collaborators

  • avatar