New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

gridsjs

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gridsjs

GridsJS is an easy and intuitive JavaScript library for creating, manipulating, and rendering 2D grids. Perfect for games, simulations, and any grid-based applications, it handles all the math for you. made with <3 by me!

latest
npmnpm
Version
1.0.1
Version published
Maintainers
1
Created
Source

GridsJS 🚀

Create grid-based systems with ease!
GridsJS saves you time by giving you a simple, intuitive way to work with 2D grids. It’s versatile enough to build games, simulations, or any grid-based system you can imagine.

Features ✨

  • Create grid-based systems quickly
  • Save time—no need to code your own grid engine
  • Versatile for games, systems, simulations, and more
  • Easy-to-use API for setting, getting, filling, and rendering grids

Installation 💾

Install via npm:

npm install gridsjs

And then in your JS file:

const grids = require('gridsjs');

Getting Started 🚀

Initializing a Grid

// Initialize a 10x10 grid
grids.initGrid(10, 10);
  • x = width
  • y = height

Setting and Getting Values

// Set a value at x=3, y=5
grids.SetGridValue(3, 5, 1);

// Get a value at x=3, y=5
const value = grids.GetGridValue(3, 5);
console.log(value); // 1

Fill the Grid

// Fill the entire grid with 0s
grids.FillAllGrids(0);

Render the Grid

grids.RenderGrid();

Output will display the grid in the console with each cell’s value.

Example: Conway's Game of Life 🌱

const grids = require('../index');

const WIDTH = 10;
const HEIGHT = 10;

// Initialize grid
grids.initGrid(WIDTH, HEIGHT);

// Randomly populate grid (30% chance alive)
for (let y = 0; y < HEIGHT; y++) {
    for (let x = 0; x < WIDTH; x++) {
        grids.SetGridValue(x, y, Math.random() < 0.3 ? 1 : 0);
    }
}

// Render function
function RenderGridCustom() {
    let output = '';
    for (let y = 0; y < HEIGHT; y++) {
        for (let x = 0; x < WIDTH; x++) {
            output += grids.GetGridValue(x, y) === 1 ? 'O ' : '. ';
        }
        output += '\n';
    }
    console.clear();
    console.log(output);
}

// Count alive neighbors
function countAliveNeighbors(x, y) {
    let count = 0;
    for (let dy = -1; dy <= 1; dy++) {
        for (let dx = -1; dx <= 1; dx++) {
            if (dx === 0 && dy === 0) continue;
            const nx = x + dx;
            const ny = y + dy;
            if (nx >= 0 && nx < WIDTH && ny >= 0 && ny < HEIGHT) {
                count += grids.GetGridValue(nx, ny);
            }
        }
    }
    return count;
}

// Next generation
function nextGeneration() {
    const newGrid = [];
    for (let y = 0; y < HEIGHT; y++) {
        for (let x = 0; x < WIDTH; x++) {
            const alive = grids.GetGridValue(x, y);
            const neighbors = countAliveNeighbors(x, y);
            let newState = alive;
            if (alive === 1 && (neighbors < 2 || neighbors > 3)) newState = 0;
            if (alive === 0 && neighbors === 3) newState = 1;
            newGrid.push(newState);
        }
    }
    for (let i = 0; i < newGrid.length; i++) grids.SetRawGridValue(i, newGrid[i]);
}

// Animation loop: 1 second per generation
setInterval(() => {
    RenderGridCustom();
    nextGeneration();
}, 1000);

You can then build animations, simulations, or any grid-based logic using the simple API provided.

API Reference 📚

  • initGrid(width, height) – initialize a grid
  • SetGridValue(x, y, value) – set a cell value
  • GetGridValue(x, y) – get a cell value
  • SetRawGridValue(index, value) – set cell by raw index
  • GetRawGridValue(index) – get cell by raw index
  • FillAllGrids(value) – fill entire grid
  • RenderGrid() – print the grid to console

Contributing 🤝

Feel free to open issues or submit pull requests. Everyone is welcome!

License 📝

MIT

thank you for downloading! <3

Keywords

grid

FAQs

Package last updated on 19 Nov 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts