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

@zixial3/arcade-core

v1.1.0

Published

Pure, framework-free game logic for 2048.

Readme

@zixial3/arcade-core

Pure game logic for 2048: no framework, no DOM, no globals. Works in Node and in the browser.

Install

npm install @zixial3/arcade-core

Usage

A board is a square array of numbers where 0 means empty.

import {
  move,
  spawn,
  hasMoves,
  canMove,
  startBoard,
} from "@zixial3/arcade-core";

let board = startBoard(); // empty 4×4 board with two starting tiles

if (canMove(board, "left")) {
  board = move(board, "left"); // slide and merge
  board = spawn(board); // add a 2 or 4 in a random empty cell
}

if (!hasMoves(board)) console.log("game over");

Every function returns a new board and never mutates its input.

API

| Function | Returns | | ------------------------------------- | ----------------------------------------------------------------------------------------------- | | move(board, direction) | New board after sliding every tile towards direction and merging equal neighbours once. | | spawn(board, rng?) | New board with a 2 (90%) or 4 (10%) in a random empty cell. rng defaults to Math.random. | | hasMoves(board) | true if any direction would change the board; false means game over. | | canMove(board, direction) | true if moving in direction would change the board. | | moveWithDetails(board, direction) | { board, moves, merges, points, changed }: where every tile went, for animations and scoring. | | startBoard(rng?, size?) | Empty board (default 4×4) with two starting tiles. | | createBoard(size?) | Empty board. | | createRng(seed) | Seeded random number generator to pass as rng. Its state resumes the same sequence. | | emptyCells(board), maxTile(board) | Helpers. |

direction is 'up' | 'down' | 'left' | 'right'.

Merging rules

Each tile merges at most once per move:

move([[2, 2, 2, 2], ...], 'left'); // → [[4, 4, 0, 0], ...]
move([[4, 4, 8, 0], ...], 'left'); // → [[8, 8, 0, 0], ...]

Scoring

moveWithDetails reports points, the sum of every tile created by a merge:

const { board, points } = moveWithDetails([[2, 2, 4, 4], ...], 'left');
// board[0] → [4, 8, 0, 0], points → 12

Seeded games

import { createRng, startBoard, spawn } from "@zixial3/arcade-core";

const rng = createRng(1234);
let board = startBoard(rng); // same starting tiles for seed 1234, every time
board = spawn(move(board, "up"), rng); // same spawn for the same move

const saved = rng.state; // save this…
const resumed = createRng(saved); // …and pick up exactly where you left off

Development

npm install
npm test        # vitest
npm run build   # TypeScript → dist/

License

MIT