This package has been deprecated

Author message:

Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.

grid-data

2.1.1 • Public • Published

GRID

Simple grid data structure.


Install

npm install grid-data

Usage

// create a empty 2x2 grid
const g = new Grid(2, 2)
 
// set values
g.set(0, 0, "first cell") // zero-based index
g.set(1, 1, "last cell")
 
// get values
console.log(g.get(0, 0)) // => "first cell"
console.log(g.get(1, 1)) // => "last cell"
 
// check a position
console.log(g.has(0, 1)) // => false
 
// create a 2x2 grid from a Array
const ga = Grid.fromArray(2, 2, [1, 2, 3, 4])
 
console.log(ga.get(0, 0)) // => 1
console.log(ga.get(0, 1)) // => 2
console.log(ga.get(1, 0)) // => 3
console.log(ga.get(1, 1)) // => 4
 
// export the grid as Array
console.log(ga.toArray()); // => [1,2,3,4]
 
// export the grid as String
console.log(ga.toString()); // => 1,2,3,4
 
// use forEach to interact
ga.forEach(function (value, x, y) {
    // do something...
})
 
// sanitizes a X position with .clipX (or use .clipY for Y positions)
console.log(ga.clipX(5)) // => 1
console.log(ga.clipY(-1)) // => 0
 
// clone a grid
const cloned = ga.clone()
 
// clear all stored values
ga.clear()
 
// public properties
g.width
g.height
g.length // === g.width * g.height

License

MIT

Readme

Keywords

Package Sidebar

Install

npm i grid-data

Weekly Downloads

0

Version

2.1.1

License

MIT

Unpacked Size

18 kB

Total Files

8

Last publish

Collaborators

  • luizbills