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 🙏

© 2026 – Pkg Stats / Ryan Hefner

npm-minesweep

v0.1.0

Published

Javascript based minesweep game that can be played via console.

Readme

Minesweep

A minesweeper game written as a javascript module. The data structure is simple: a Game contains a Grid that contains a 2D array of Tiles. The Tiles contain all the state information for the game play. As clicks are made, the "status" of the Tiles are changed from "UNKNOWN" to "CHECKED". Unless of course the status is "BOMB", which then is an invalid click and ends the game.

All the data is keep in the Grid/Tile objects so it can be easily export as JSON or read as an object. This detaches this data from the display. The console log display is for debugging, however it can also be used to play the game.

  • This version is the NPM module for my earlier code written at: https://github.com/kyledinh/toolkit/tree/master/mindsweep

Data Structure

Game(x, y)
  |
  .grid ------------ Grid(x, y)
  .moves               |
  .numBombs            .tiles[][] ------- Tile(status, x, y)
  |                    .x                   .x
  |                    .y                   .y
  |                    |                    .touch     # bombs are adjacent
  |                    |                    .status    { UNKNOWN | CHECKED | CLICKED | BOMB }
  |                    |                    |
  .stringify()         .stringifyTiles()    |
  |                    .parseTiles()        |
  |                    |                    |
  .show()              .show()              .show()    { "=" | " " | 1-8 }
  .cheat()             .cheat()             .cheat()   { "*" }            
  .over()              |                    |
  |                    |                    |
  .start(n)            .setup()             |                              
  |                    .layBombs(n)         |
  |                    .updateTiles()       .updateTouch(n)
  |
  .click(x, y) { INVALID | BOMB | OK }

Public Module Methods

createGame(x, y, bombs)  // creates a game with x width, y height and number of bombs
click(x,y)               // selects a grid tile to play
show()                   // returns a object of the grid
cheat()                  // returns the grid with all tiles revealed
freeSpaces()             // returns a list of free spaces [ {}, {} ]
randomFreeSpace()        // returns a random free space {x, y}

Executing via CLI

This code can be ran from the command line with node.js or V8. Or a browser's javascript console. createGame() takes the x and y for the Grid size, and the third argument is the number of desired bombs (8 is default).

 * node
 * .load ./minesweep.js
 * var ms = new APP.Minesweep;
 * ms.createGame(12,12,8);
 * ms.click(2,3);

ms.show() // console.log

show:
         0   1   2   3   4   5   6   7   8   9   10  11  
row  0 :[ ] [ ] [ ] [ ] [ ] [ ] [1] [=] [=] [=] [=] [=]
row  1 :[1] [1] [ ] [ ] [ ] [ ] [1] [=] [=] [=] [=] [=]
row  2 :[=] [1] [ ] [ ] [ ] [ ] [=] [=] [=] [=] [=] [=]
row  3 :[=] [1] [ ] [ ] [1] [1] [=] [=] [=] [=] [=] [=]
row  4 :[=] [1] [1] [ ] [=] [=] [=] [=] [=] [=] [=] [=]
row  5 :[=] [=] [=] [1] [=] [=] [=] [=] [=] [=] [=] [=]
row  6 :[=] [=] [=] [=] [=] [=] [=] [=] [=] [=] [=] [=]
row  7 :[=] [=] [=] [=] [=] [=] [=] [=] [=] [=] [=] [=]
row  8 :[=] [=] [=] [=] [=] [=] [=] [=] [=] [=] [=] [=]
row  9 :[=] [=] [=] [=] [=] [=] [=] [=] [=] [=] [=] [=]
row 10 :[=] [=] [=] [=] [=] [=] [=] [=] [=] [=] [=] [=]
row 11 :[=] [=] [=] [=] [=] [=] [=] [=] [=] [=] [=] [=]
row 12 :[=] [=] [=] [=] [=] [=] [=] [=] [=] [=] [=] [=]

object returned from show()

[{x: 0, y: 0, show: "="}, {x: 1, y: 0, show: 1}, {x: 2, y: 0, show: " "}, {x: 3, y: 0, show: " "},
{x: 4, y: 0, show: " "}, {x: 5, y: 0, show: " "}, {x: 6, y: 0, show: " "}, ... ]

ms.cheat() // console.log

cheat view:
         0   1   2   3   4   5   6   7   8   9   10  11  
row  0 :[0] [0] [0] [0] [0] [0] [1] [*] [1] [0] [1] [*]
row  1 :[1] [1] [0] [0] [0] [0] [1] [1] [1] [0] [1] [1]
row  2 :[*] [1] [0] [0] [0] [0] [0] [0] [0] [0] [0] [0]
row  3 :[1] [1] [0] [0] [1] [1] [1] [0] [0] [0] [0] [0]
row  4 :[1] [1] [1] [0] [1] [*] [1] [0] [0] [0] [0] [0]
row  5 :[1] [*] [2] [1] [1] [1] [1] [0] [1] [2] [2] [1]
row  6 :[1] [3] [*] [2] [0] [0] [0] [0] [1] [*] [*] [1]
row  7 :[0] [2] [*] [3] [1] [0] [0] [0] [1] [2] [2] [1]
row  8 :[0] [1] [2] [*] [1] [0] [0] [0] [0] [1] [1] [1]
row  9 :[0] [0] [1] [1] [1] [0] [0] [0] [0] [1] [*] [1]
row 10 :[0] [0] [0] [0] [0] [0] [0] [0] [0] [1] [1] [1]
row 11 :[0] [0] [0] [0] [0] [0] [1] [1] [1] [0] [0] [0]
row 12 :[0] [0] [0] [0] [0] [0] [1] [*] [1] [0] [0] [0]

object returned from cheat()

[{x: 0, y: 1, show: "*"}, {x: 1, y: 3, show: "*"}, {x: 0, y: 4, show: "*"}, {x: 3, y: 5, show: "*"},
{x: 7, y: 5, show: "*"}, {x: 4, y: 7, show: "*"}, {x: 6, y: 7, show: "*"}, {x: 7, y: 7, show: "*"}]

Usage

This module is written to use require() in the Nodejs context or directly included in an HTML context with a <script> tag. In the browser, the module will be loaded to the global namespace as APP.Minesweep. With the option of setting APP.LOG_LEVEL='DEBUG' to turn the console.log to a verbose state for debugging. Just use the mindsweep.js file without alteration.

Notes

Source

Written by Kyle Dinh, 2013 and 2017

https://github.com/kyledinh/toolkit/tree/master/mindsweep