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

@april-cs-npm/arcade-core

v1.1.0

Published

npm package for the 2048 logic: move, spawn, hasMoves, score

Readme

@april-cs-npm/arcade-core

Pure JavaScript game logic for 2048. No UI, no DOM, no framework — just functions that take a board and return a new board, so the same logic can run in Node, in tests, or inside any app.

Built for the CS5610 arcade project.

Install

npm install @april-cs-npm/arcade-core

The board

A board is a 4×4 array of rows. Each cell is a number, where 0 means empty.

const board = [
  [2, 2, 0, 0],
  [0, 0, 0, 0],
  [4, 0, 0, 0],
  [4, 0, 0, 0],
];

A direction is one of: "left", "right", "up", "down".

Usage

import { move, spawn, hasMoves, canMove, score } from '@april-cs-npm/arcade-core';

// Slide and merge tiles. Returns a NEW board; the input is never changed.
const afterMove = move(board, 'left');

// Check whether a direction is a valid move (would change the board).
const isValid = canMove(board, 'left');

// How many points that move earned (the sum of tiles created by merges).
const points = score(board, 'left');

// Drop a new 2 or 4 into a random empty cell. Returns a NEW board.
const afterSpawn = spawn(afterMove);

// Is the game still playable? false means game over.
const canKeepPlaying = hasMoves(afterSpawn);

API

move(board, direction)

Slides every tile as far as it can go in direction, merging equal neighbours once per move, and returns the new board. Does not mutate the input.

canMove(board, direction)

Returns true if a move in that direction would change the board, false otherwise.

score(board, direction)

Returns the points a move in direction would earn: the total value of every tile created by a merge.

spawn(board, rng?)

Returns a new board with one new tile (a 2 90% of the time, a 4 10%) placed in a random empty cell. If the board is full, it is returned unchanged.

rng is optional and defaults to Math.random. Pass your own function returning a number in [0, 1) to make spawning deterministic (useful for tests and for seeded games):

const afterSpawn = spawn(board, () => 0); // always picks the first empty cell

hasMoves(board)

Returns true if any direction would change the board, and false when no move is possible (game over).

Notes

  • Every function is pure: it returns a new board and never changes the one you pass in.
  • The package contains no Svelte and no DOM access, so it runs anywhere plain JavaScript runs.

License

MIT