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

sudoku-grid-maker

v2.2.0

Published

A playable sudoku grid maker (not generator). Supports pencil marks and grid history for undo/redo.

Downloads

15

Readme

Sudoku Grid Maker

A playable sudoku grid maker (not generator). Supports pencil marks and grid history for undo/redo.

Install

npm install sudoku-grid-maker

Usage

// CJS
const Sudoku = require('sudoku-grid-maker');

// ESM
import Sudoku from 'sudoku-grid-maker';

// create new empty grid
const sudoku = new Sudoku();

// create new populated grid
const initialCellValues = [
    // 2D array of rows of 1-9 or null
];
const sudoku = new Sudoku(initialCellValues, true);

sudoku.addNumber({ newNumber: 6, row: 2, column: 0 });
sudoku.removeNumber({ row: 2, column: 0 });
sudoku.undo();
sudoku.togglePencilMark({ number: 9, row: 0, column: 0 });
sudoku.togglePencilMark({ number: 5, row: 0, column: 0 });
sudoku.togglePencilMark({ number: 9, row: 0, column: 0 });
sudoku.redo();
sudoku.reset();

Methods

constructor(startingValues?, shouldLockStartNums?)

startingValues (optional)

A 9x9 2D array containing the numbers 1-9 or null, representing the starting cell values of the grid. If not provided, all cells will be initialised with null values.

shouldLockStartNums (optional)

A boolean - if true, upon grid creation, any cells that start with number values will be locked (cannot edit values/pencil marks).

addNumber({ newNumber, row, column })

Set a cell's value to a number (1-9). This will clear the target cell's pencil marks, and will remove any matching pencil marks from any cell in the same box/row/column as the target cell.

Calling this method will first clear any grid history states after the current history index, then record a new grid history state.

addNumber.newNumber

The new number value for the cell.

addNumber.row

The target cell's row index (0-8).

addNumber.column

The target cell's column index (0-8).

removeNumber({ row, column })

Sets a cell's value to null.

Calling this method will first clear any grid history states after the current history index, then record a new grid history state.

removeNumber.row

The row number (0-8) of the cell to remove the value of (set to null).

removeNumber.column

The column number (0-8) of the cell to remove the value of (set to null).

togglePencilMark({ number, row, column })

If the target cell is empty (null value) or does not already have the pencil mark, adds the pencil mark number (1-9). If the pencil mark already exists, removes it instead.

Calling this method will first clear any grid history states after the current history index, then record a new grid history state.

togglePencilMark.number

The number to add to or remove from pencil marks.

togglePencilMark.row

The target cell's row index (0-8).

togglePencilMark.column

The target cell's column index (0-8).

undo()

Changes the current grid state to the previously recorded grid state (if one exists).

redo()

Changes the current grid state to the next recorded grid state (if one exists).

reset()

Resets the current grid to the original grid state and wipes the rest of the grid history.

isSolved()

true if all cells have values in them, otherwise false.