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

node-cli-character-matrix

v1.1.5

Published

A simple cli tool for drawing matrix based games.

Readme

node-cli-character-matrix

A simple cli tool for drawing matrix based games.

Notes:

  • Emoji are not supported at this stage.

Data Types

Char

export type Char = string | {
	char: string; 
	color?: string; 
	backgroundColor?: string; 
}

Functions

startMatrixApplication(options)

Options object

  • nRows - Number of rows the matrix is to have
  • nColumns - Number of columns the matrix is to have.
  • interval - Time in ms between ticks
  • onTick a function of the signature: <T,>(matrix: Matrix, tickCount: number, exit: (message:string) => void, keyPress: KeyPress, oldState:T) => {newMatrix: Matrix, newState: T}
  • initialState The value that the state is initially set as.

That is:

Each tick the onTick function will be called with matrix as it currently is, the state as it currently is, the tick count number, the most recent key press (if any) and a function to be called to stop the application running. That function can take an exit message.

The value returned from this onTick function is what will be displayed on the matrix next, as well as any new state to be passed back. This allows for a functional style of programming.

createMatrix(rows, columns)

Create a blank matrix of nRows rows and nColumns columns.

Returns: the blank matrix

setCell(matrix, rowNum, cellNum, char)

For the given matrix, set the cell at rowNum/cellNum as the given character

Returns: the new matrix

clearMatrix(matrix)

Create a blank matrix of the same size as the given one.

Returns: the blank matrix

Sample application:

The following application will draw an X starting at the top left corner, moving to the bottom right corner.

It stops after 20 ticks.

State is not used in this example.

import { startMatrixApplication, clearMatrix, setCell } from "node-cli-character-matrix";

const N_ROWS = 5;
const N_COLUMNS = 5;
const INTERVAL_MS = 100;

startMatrixApplication({
	nRows: N_ROWS,
	nColumns: N_COLUMNS,
	intervalTime: INTERVAL_MS,
	onTick: (matrix, tickCount, exit) => {
		const clearedMatrix = clearMatrix(matrix);
		const newMatrix = setCell(clearedMatrix, tickCount % N_ROWS, tickCount % N_COLUMNS, 'X');

		if (tickCount > 20) {
			exit("Thank you for playing!");
		}
		return {newMatrix, newState: null};
	},
	initialState: null,
});

Sample Application with Key Presses

This application will move the X around with the keyboard arrow keys.

State is not used in this example.


let currentX = 0;
let currentY = 0;

startMatrixApplication({
	nRows: N_ROWS,
	nColumns: N_COLUMNS,
	intervalTime: INTERVAL_MS,
	initialState: null,
	onTick: (matrix, tickCount, exit, keyPress) => {
		const clearedMatrix = clearMatrix(matrix);

		if (keyPress) {

			switch (keyPress.name) {
				case "down": {
					currentY = (currentY + 1 + N_ROWS) % N_ROWS;
					break;
				}
				case "up": {
					currentY = (currentY - 1 + N_ROWS) % N_ROWS;
					break;
				}

				case "left": {
					currentX = (currentX - 1 + N_COLUMNS) % N_COLUMNS;
					break;
				}

				case "right": {
					currentX = (currentX + 1 + N_COLUMNS) % N_COLUMNS;
					break;
				}

				default: {

				}
			}
		}

		const newMatrix = setCell(clearedMatrix, currentY, currentX, 'X');

		if (tickCount > 100) {
			exit("Thank you for playing!");
		}
		return {newMatrix, newState: null,};
	}
});

Sample application with key presses - folding function

This demonstrate is like the above one - but demonstrates the more functional 'folding' style of code:

startMatrixApplication({
	nRows: N_ROWS,
	nColumns: N_COLUMNS,
	intervalTime: INTERVAL_MS,
	initialState: {
		x: 0,
		y: 0,
	},
	onTick: (matrix, tickCount, exit, keyPress, oldState) => {
		const clearedMatrix = clearMatrix(matrix);

		function getVector(keyPress: KeyPress | null) : {
			x: number; 
			y: number;
		} {
			if (keyPress) {

				switch (keyPress.name) {
					case "down": {
						return {
							x: 0,
							y: 1,
						}
					}
					case "up": {
						return {
							x: 0,
							y: -1,
						}
					}

					case "left": {
						return {
							x: -1,
							y: 0,
						}
					}

					case "right": {
						return {
							x: 1,
							y: 0,
						}
					}

					default: {
						return {
							x: 0,
							y: 0,
						}
					}
				}
			}

			return {
				x: 0,
				y: 0,
			}
		}

		const vector = getVector(keyPress);

		const newState = {
			x: (oldState.x + N_COLUMNS + vector.x) % N_COLUMNS,
			y: (oldState.y + N_ROWS + vector.y) % N_ROWS
		}

		const newMatrix = setCell(clearedMatrix, newState.y, newState.x, 'X');

		if (tickCount > 100) {
			exit("Thank you for playing!");
		}
		return {
			newMatrix,
			newState
		}
	}
});