npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@seabuffalo/grid-generator

v1.0.4

Published

Module to create nested arrays mapped to DOM Elements

Downloads

1

Readme

Grid Generator

Simple JavaScript class to generate nested arrays and map them to the DOM.

Install

npm install @seabuffalo/grid-generator

API

Grid-Generator uses the static import declaration and so must be used inside a JavaScript module

import { Grid, Cell } from "./node_modules/@seabuffalo/grid-generator/index.js"
new Cell(r, g, b, a)
new Grid(rows, columns, cell, parent)

Example

Sample JavaScript functionality test.js

//import Grid and Cell classes in module format
import { Grid, Cell } from './node_modules/@seabuffalo/grid-generator/index.js'

//identify DOM element to append grid to
const gridContainer = document.querySelector(".grid-container");

//create new Grid instance
//Each grid is comprised of cells, created with the Cell class
const newCell = new Cell(0, 200, 100, 1);

//Grids take four initial arguments: rows, columns, Cell, and parent element
const newGrid = new Grid(3, 3, newCell, gridContainer);

//bind Grid methods to custom inputs
const rowsInput = document.querySelector("#rows");
rowsInput.addEventListener("change", (e) => {
  newGrid.setRows(parseInt(e.target.value));
});

const columnsInput = document.querySelector("#columns");
columnsInput.addEventListener("change", (e) => {
  newGrid.setColumns(parseInt(e.target.value));
});

const redInput = document.querySelector("#red");
redInput.addEventListener("change", (e) => {
  newGrid.setRed(parseFloat(e.target.value));
});

const greenInput = document.querySelector("#green");
greenInput.addEventListener("change", (e) => {
  newGrid.setGreen(parseFloat(e.target.value));
});

const blueInput = document.querySelector("#blue");
blueInput.addEventListener("change", (e) => {
  newGrid.setBlue(parseFloat(e.target.value));
});

const alphaInput = document.querySelector("#alpha");
alphaInput.addEventListener("change", (e) => {
  newGrid.setAlpha(parseFloat(e.target.value));
});

Binded to sample HTML document

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <script src="test.js" type="module" defer></script>
  <title>Grid Generator Test</title>
</head>
<body>
  <style>
    body {
      display: flex;
      flex-direction: column;
      align-items: center;
    }
    .grid-container {
      height: 600px;
      width: 600px;
    }
    .rgb-container, .rows-columns {
      width: 600px;
    }
    .labels, .inputs {
      display: flex;
    }
    .labels > label, .inputs > input {
      width: 25%;
    }
  </style>
  <div class="rows-columns">
    <label for="rows">Rows</label>
    <input id="rows" type="number" min="0" max="100" value="3">
  
    <label for="columns">Columns</label>
    <input id="columns" type="number" min="0" max="100" value="3">
  </div>
  
  <div class="rgb-container">
    <div class="labels">
      <label for="red">Red</label>
      <label for="green">Green</label>
      <label for="blue">Blue</label>
      <label for="alpha">Alpha</label>
    </div>

    <div class="inputs">
      <input id="red" type="range" min="0" max="255" value="0">
      <input id="green" type="range" min="0" max="255" value="200">
      <input id="blue" type="range" min="0" max="255" value="100">
      <input id="alpha" type="range" min="0" max="1" step="0.01" value="1">
    </div>
  </div>
  
  <div class="grid-container"></div>
</body>
</html>

Properties & Methods

//Grid

//Constructor
new Grid(rows, column, Cell, parent) //creates grid with n rows/columns  
                                //using supplied Cell and parent element

//Properties
newGrid.element              //returns grid mapped to a DOM element
newGrid.grid                 //returns current grid
newGrid.rows                 //returns total rows
newGrid.columns              //returns total columns
newGrid.totalCells           //returns total cells
newGrid.cell                 //returns current cell properties
newGrid.parent               //returns parent element

//Methods
newGrid.addRows(rows)        //add n rows
newGrid.addColumns(columns)  //add n columns
newGrid.setRows(rows)        //modify grid to n rows
newGrid.setColumns(columns)  //modify grid to n columns
newGrid.setRed(r)            //change red value of cell rgba
newGrid.setGreen(g)          //change green value of cell rgba
newGrid.setBlue(b)           //change blue value of cell rgba
newGrid.setAlpha(a)          //change alpha value of cell rgba
newGrid.setCellColors(r, g, b, a)  //change cell rgba values

/////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////

//Cell

//Constructor
new Cell(r, g, b, a)         //creates cell to be used in grid
                             //takes rgba values for cell color

//Properties
cell.r                       //cell's red value
cell.g                       //cell's green value
cell.b                       //cell's blue value
cell.a                       //cells alpha value

//Methods
cell.setColors(r, g, b, a)   //change cell's rgba values

License

MIT