Skip to content

Commit

Permalink
feat(common): add data constructor module
Browse files Browse the repository at this point in the history
  • Loading branch information
stuf committed Oct 16, 2019
1 parent 900e8a9 commit 26a8617
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/common/data.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/**
* @module data
* @namespace common
*
* Common curried data structure constructors
*/
import * as R from 'ramda';

export const mkClampedArray = R.constructN(1, Uint8ClampedArray);

export const mkImageData = R.constructN(3, ImageData);
17 changes: 17 additions & 0 deletions src/common/data.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import * as Mod from './data';

it('mkClampedArray', () => {
const xs = Mod.mkClampedArray([1, 2, 3, 4, 5, 6, 7, 8]);

expect(xs).toBeInstanceOf(Uint8ClampedArray);
});

it('mkImageData', () => {
const w = 5;
const h = 5;
const m = 4;
const xs = Mod.mkClampedArray(Array(w * h * m).fill(0));

const ctor = () => Mod.mkImageData(xs, w, h);
expect(ctor).not.toThrow();
});

0 comments on commit 26a8617

Please sign in to comment.