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

@not_thefirst/jsmaze

v0.3.4

Published

Simple maze module in JavaScript.

Downloads

71

Readme

Simple maze module in JavaScript

The name said it all. It's a simple maze module, written in JavaScript.

Documentation:

base class Maze

Properties:
- maze: The array containing the maze's content;
- playerPosition: The current position of the player in the maze array;
Methods:
- move(direction): Move the player in the specified direction;
- getUnicodeMaze(): Returns a text block containing the maze's content.
- getMazeImage(cellSize, wallColor, pathColor, playerColor, endPointColor): Returns a buffer containing the image visualization of the maze's data.

constructor(width, height)

Creates a maze instance with the width of 'width' and height of 'height', data will be saved into Maze.maze. Note that due to the used algorithm (recursive backtracking), the width/height will always be even.\

Maze.maze

The array containing the maze's data.

Maze.playerPosition

Position of the player in the maze's array. Have 2 properties: x and y, representing its position of maze[x][y] in the array.

Maze.move(direction)

Moves the player in the specified direction. Returns/prints nothing on success.
Parameters:
- direction: The direction of the move. Can be up, down, right and left.

Maze.getUnicodeMaze()

Returns the maze's content in a Unicode text block that can be logged to console.
The maze's wall will be represented as '#', the blank area will be '0', player will be 'S' and the end point will be 'E'.

Maze.getMazeImage(cellSize, wallColor, pathColor, playerColor, endPointColor)

Returns a buffer containing the image visualization of the maze's data, which can be saved to the computer with the image extension of png.
Parameters:
- cellSize: The cell size, in pixels. Will default to 20. - wallColor: The color of a wall cell. Written in the format of #RRGGBB ('#' is required). Will default to #000000 if the parameter is not passed/or not matching the format.
- pathColor: The color of a wall cell. Written in the format of #RRGGBB. Will default to #FFFFFF.
- playerColor: The color of a wall cell. Written in the format of #RRGGBB. Will default to #00FF00.
- endPointColor: The color of a wall cell. Written in the format of #RRGGBB. Will default to #FF0000.

Here's the instruction on how to use it:

The module can be included using this following line in your project:

const Maze = include('@not_thefirst/jsmaze');

To create a maze, simply use:

let mazeInstance = new Maze(sizeX, sizeY);

// But to access the maze content, you would have to use:
let mazeContent = mazeInstance.maze;

You can also retrieve the maze content in Unicode characters for logging into consoles:

// ...
let unicodeMaze = mazeInstance.getUnicodeMaze();

console.log(unicodeMaze); // this should print the Unicode maze, with S being the player, E being the end point.

There's a built-in function to move the player. When creating a maze, the player's position is always at (1, 1) of the generated maze array. There're 4 directions: up, down, left and right. Example usage:

// ...
let mazeInstance = new Maze(5, 5); // 5x5 maze for demonstration

console.log(mazeInstance.getUnicodeMaze());
/* 
Let's , after generation, the maze will look like this:
#####
#S#E#
#0#0#
#000#
#####
*/

// attempt to put garbage for direction
mazeInstance.move('saddwdsd');
// prints 'Invalid direction'

// attempt to move up
mazeInstance.move('up');
// prints 'Invalid move! Hit a wall.'

// attempt to move down
mazeInstance.move('down');
// nothing prints, stating a successful move

console.log(mazeInstance.getUnicodeMaze());
/*
#####
#0#E#
#S#0#
#000#
#####
*/

You can also save the image into a file:

const fs = require('fs');
const { Maze } = require('@not_thefirst/jsmaze');

// generates a 20x20 maze
let mazeInstance = new Maze(20, 20);

// gets the maze image with cellSize = 20, colors are auto defaulted
let imgBuffer = mazeInstance.getMazeImage(20);

// outputs a file named maze.png in the working directory
fs.writeFileSync('./maze.png', imgBuffer);