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

2048-engine

v0.1.1

Published

Game engine for 2048 game

Readme

2048 engine

Tests

Handles logic for 2048 game.

Originally based on 2048-ts-engine by Karel Nguyen, but has now been completely rewritten to support additional features.

Example

import { createGame, Direction } from '2048-engine';

const game = createGame();
game.move(Direction.UP);
game.move(Direction.RIGHT);

console.log(game);

might print:

{
    currentState: {
        board: [
            [ null, null, { value: 2, id: 0 }, { value: 4, id: 1 } ],
            [ null, null, null, { value: 4, id: 2 } ],
            [ null, null, { value: 4, id: 3 }, null ],
            [ null, null, null, null ]
        ],
        score: 0,
        rngNumber: 455431,
        totalTileCount: 4,
        status: { hasPossibleMoves: true, isWon: false }
    },
    boardMeta: { rows: 4, cols: 4 },
    randomSeed: 455423,
    moveLog: [ { type: 0, direction: 0 }, { type: 0, direction: 3 } ],
    move: [Function: move]
}

API

createGame

The package exposes one method createGame that creates a new game.

createGame(gameData?) => Game

Can be supplied with GameData to initialize the game with.

Game

The created game object contains the following properties:

  • currentState: The current state of the game. (see GameState)
  • move: Function to make a move in the game. Takes a Direction as an argument and returns an updated GameState in addition to updating game.currentState
  • boardMeta: Metadata about the board. Contains rows and cols properties, which are the number of rows and columns in the board.
  • randomSeed: The random seed used to create the game. A new game created with the same random seed will be exactly the same given the same moves.
  • moveLog: List of all moves made in the game. Each move is a Move object.

GameData

GameData is a subset of Game containing all properties except currentState and move. A new game created with the same GameData as an existing game will be exactly the same.

GameState

The gameState contained within Game contains the following properties:

  • board: The board state. A 2D array of Tile-objects.
  • score: The current score of the game.
  • status: object containing booleans isWon and hasPossibleMoves describing current game status.

Tile

Each tile object contains an id, and its current value. The tile might also contain a mergedId specifying the id of the tile it was most recently merged with.

  • id: id to identify the tile, unique per game.
  • value: The value of the tile.
  • mergedId: The id of the tile it was most recently merged with. (useful for animations)