@pelevesque/make-grid
v0.0.9
Published
Creates a two dimensional array arranged as a grid with `x`, `y`, `w`, `h` values on each item.
Downloads
5
Readme
make-grid
Creates a two dimensional array arranged as a grid with x
, y
, w
, h
values on each item.
Node Repository
https://www.npmjs.com/package/@pelevesque/make-grid
Installation
npm install @pelevesque/make-grid
Tests
Command | Description
---------------------------- | ------------
npm test
or npm run test
| All Tests Below
npm run cover
| Standard Style
npm run standard
| Coverage
npm run unit
| Unit Tests
Usage
const makeGrid = require('@pelevesque/make-grid')
const numRows = 3
const numCols = 5
const cellWidth = 2
const cellHeight = 3
const grid = makeGrid(numRows, numCols, cellWidth, cellHeight)
// result
grid = [
[ { x: 0, y: 0, w: 2, h: 3 },
{ x: 2, y: 0, w: 2, h: 3 },
{ x: 4, y: 0, w: 2, h: 3 },
{ x: 6, y: 0, w: 2, h: 3 },
{ x: 8, y: 0, w: 2, h: 3 }
], [
{ x: 0, y: 3, w: 2, h: 3 },
{ x: 2, y: 3, w: 2, h: 3 },
{ x: 4, y: 3, w: 2, h: 3 },
{ x: 6, y: 3, w: 2, h: 3 },
{ x: 8, y: 3, w: 2, h: 3 }
], [
{ x: 0, y: 6, w: 2, h: 3 },
{ x: 2, y: 6, w: 2, h: 3 },
{ x: 4, y: 6, w: 2, h: 3 },
{ x: 6, y: 6, w: 2, h: 3 },
{ x: 8, y: 6, w: 2, h: 3 }
]
]