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

miaoda-game-deck-core

v0.3.0

Published

Engine-agnostic deck/pile engine for card games: named zones, deterministic shuffle with optional authoritative RNG injection, automatic reshuffle, hand limits, atomic selected-card moves, saves, and pure snapshot operations for reducer/command state. Car

Downloads

1,122

Readme

miaoda-game-deck-core

Use this package for draw piles, hands, discard piles, exhaust zones, tables, and other card-game zones. It owns card movement, deterministic shuffles, mid-draw reshuffles, hand overflow policies, change events, and snapshots. Card effects and game rules remain yours.

Install and create a deck

pnpm add miaoda-game-deck-core
import { Deck } from 'miaoda-game-deck-core';

const deck = new Deck({
  seed: 1234,
  zones: [
    { id: 'draw', cards: cardList },
    { id: 'hand', limit: 10 },
    { id: 'discard' },
    { id: 'exhaust' },
  ],
});

deck.shuffle();
const opening = deck.draw(5);
deck.move('strike-1', 'discard');
deck.moveAll('hand', 'discard');
deck.draw(5); // reshuffles discard automatically when draw empties

Cards need a stable string id; other card fields are preserved as your data. cardsIn(zone) returns cards bottom-to-top, with the last card as the pile top.

Draw and move rules

  • Drawing across an empty draw pile reshuffles discard into draw and continues the same request.
  • Drawing from completely empty zones returns fewer cards, never holes or an infinite loop.
  • moveMany is atomic: if any selected card is missing from the declared source, nothing moves.
  • Hand limit is enforced by draw, with overflow: 'stop' (default), 'allow', or 'spill' to another zone. Direct move and moveAll do not enforce the limit.
deck.draw(3, { to: 'hand', overflow: 'spill', spillTo: 'discard' });
deck.moveMany(['a', 'b'], 'table', { from: 'hand' });

Events for animation

deck.onChange((event) => queueCardAnimation(event));

Each mutation emits one event. A draw that needs a reshuffle emits reshuffle then draw synchronously; queue those events so the pile collapse finishes before cards fan out. exhaust is represented as a normal move with to: 'exhaust'. Empty moveAll is a silent no-op.

Determinism, snapshots, and hidden information

The seeded RNG state is included in toJSON, so restoring a snapshot reproduces future shuffles. Deck.fromJSON creates a new instance; loadJSON replaces an existing instance and keeps its listeners.

Snapshots contain every hidden card and private RNG state. Never send them directly to an untrusted player; project zones, card IDs, and deck events at the game/server boundary. applyDeckOperation(snapshot, operation) is the data-first option for command reducers and AI simulations.

Composition boundaries

Use turn-core for who acts and when, command-core for atomic deterministic commands and replay, and card-specific rules packages for legal plays and scoring. This package only manages zones and piles.