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

@zgdhdnd/arcade-core

v1.0.1

Published

Pure, framework-free game logic for 2048: move, spawn, hasMoves and canMove.

Readme

@zgdhdnd/arcade-core

Pure game logic for 2048, with no framework and no DOM. Every function takes a board and returns a new one, so it runs the same in Node, in the browser, or inside any UI framework.

It powers the 2048 page of The Arcade, my course site.

Install

npm install @zgdhdnd/arcade-core

Use it

import { createBoard, spawn, move, canMove, hasMoves } from '@zgdhdnd/arcade-core';

let board = spawn(spawn(createBoard()));   // a 4×4 board with two starting tiles

if (canMove(board, 'left')) {
  board = move(board, 'left');             // slide and merge
  board = spawn(board);                    // a new 2 or 4 appears
}

if (!hasMoves(board)) console.log('Game over');

A board is an array of rows, and 0 means an empty cell:

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

API

| Function | Returns | | --- | --- | | move(board, direction) | A new board with every tile slid as far as it goes and equal neighbours merged once each. | | spawn(board, rng?) | A 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 still change the board, false when the game is over. | | canMove(board, direction) | true if moving in that direction would change the board. | | slide(board, direction) | { board, score, moves, changed }: the new board, points earned from merges, and where each tile went ({ from, to, merged }). Useful for scoring and animation. | | seededRng(seed) | A repeatable random function to pass to spawn, so the same seed gives the same spawns. | | createBoard(size = 4) | An empty size × size board. |

direction is one of 'up', 'down', 'left' or 'right'. Types (Board, Direction, Cell, SlideResult, TileMove) ship with the package.

Rules it follows

  • Merging is once per tile per move: 2 2 2 2 becomes 4 4, and 4 4 8 becomes 8 8.
  • Tiles closest to the wall merge first: 2 2 2 moved left is 4 2, moved right is 2 4.
  • Inputs are never changed, and nothing is read from or written to anything outside the arguments.

Repeatable games

import { seededRng, spawn, createBoard } from '@zgdhdnd/arcade-core';

const rng = seededRng(2048);
const board = spawn(spawn(createBoard(), rng), rng);   // same two tiles every time

spawn calls rng exactly twice when there is room (once for the cell, once for the value) and not at all on a full board.

Develop

npm install
npm test        # compiles src/ to dist/ with tsc, then runs node:test against dist/

The source is TypeScript in src/. Tests import the compiled dist/ files so they check exactly what gets published.

Credits

seededRng uses mulberry32, a public-domain generator by Tommy Ettinger.

License

MIT