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

@jsondeck/core

v0.1.1

Published

Headless TypeScript runtime for JSON-defined card games.

Readme

@jsondeck/core

CI Status npm version npm downloads TypeScript License: MIT

Headless TypeScript runtime for JSON-defined card games.

@jsondeck/core is a pure, deterministic game engine for building and executing card games defined in JSON DSL. It provides validation, compilation, state management, event dispatching, rule execution, and render-neutral view models.

This is a headless library — it contains no UI, DOM, Canvas, or browser dependencies. Perfect for:

  • Server-side game validation
  • Node.js game servers
  • Web browsers (via bundlers)
  • Web Workers
  • Testing and automation

Installation

npm install @jsondeck/core

Or with yarn/pnpm:

yarn add @jsondeck/core
pnpm add @jsondeck/core

Requirements

  • Node.js ≥ 18 (or any modern browser / Web Worker via a bundler).
  • ESM-only. This package ships as an ES module ("type": "module") with TypeScript declarations. Import it with import from ESM code or a bundler. CommonJS consumers can load it via dynamic await import('@jsondeck/core').
  • The only runtime dependency is zod.

Quick Start

import {
  compileGame,
  createInitialState,
  dispatchEvent,
  tick,
  buildViewModel,
} from '@jsondeck/core';

// Load your game definition
const gameJson = {
  jsondeck: '0.1',
  id: 'my-game',
  title: 'My Game',
  table: { width: 800, height: 600, camera: { mode: 'fixed' } },
  zones: { main: { type: 'free_space', layout: 'free' } },
  cardTypes: { card: { title: 'Card' } },
  initialState: { cards: [{ id: 'c1', type: 'card', zone: 'main' }] },
  rules: [],
};

// Compile and initialize
const game = compileGame(gameJson);
let state = createInitialState(game);

// Dispatch an event
const result = dispatchEvent(game, state, {
  type: 'card.clicked',
  source: 'c1',
  position: { x: 100, y: 100 },
});

state = result.state;

// Advance time and process timers
const tickResult = tick(game, state, 1000);
state = tickResult.state;

// Build a view model for rendering
const viewModel = buildViewModel(game, state);
console.log(viewModel);

Key Features

  • JSON DSL v0.1 — Define games in declarative JSON
  • Validation — Structural and semantic validation with detailed error reporting
  • Rule Engine — Event-driven rules with conditions and commands
  • State Management — Immutable state transitions via transactions
  • Expressions — Variable and context-aware expression resolution
  • Timers — Built-in timer management with tick-based processing
  • View Models — Render-neutral ViewModel for any UI framework
  • Deterministic — Same inputs always produce same outputs
  • Type-Safe — Full TypeScript support with strict types

Documentation

  • English — Full API reference and concepts
  • Русский — Полное описание на русском

Core Concepts

For integrators

Example Games

See examples/ for sample game definitions (also shipped inside the package under node_modules/@jsondeck/core/examples):

API Overview

Compilation

// Throws on error
const game = compileGame(raw);

// Returns result object
const result = safeCompileGame(raw);
if (result.ok) {
  const game = result.game;
}

Runtime

// Create initial state
const state = createInitialState(game);

// Dispatch events
const dispatchResult = dispatchEvent(game, state, event);
const newState = dispatchResult.state;

// Process time
const tickResult = tick(game, state, deltaMs);
const newState = tickResult.state;

// Build view model
const viewModel = buildViewModel(game, state);

Wrapper

// Convenience runtime wrapper
const runtime = createRuntime(gameJson);
runtime.dispatch(event);
runtime.tick(100);
const vm = runtime.getViewModel();

Error handling

Validation and runtime errors are structured ({ code, message, path? }). Use the exported JsonDeckErrorCodes catalog instead of magic strings:

import { safeCompileGame, JsonDeckErrorCodes } from '@jsondeck/core';

const result = safeCompileGame(raw);
if (!result.ok) {
  for (const err of result.errors) {
    if (err.code === JsonDeckErrorCodes.SEMANTIC_VALIDATION_ERROR) {
      console.warn(`Invalid DSL at ${err.path}: ${err.message}`);
    }
  }
}

compileGame throws a JsonDeckCompileError (with .errors / .warnings) whose message summarizes the first failure for logs and stack traces.

Architecture Principles

  • Clean Architecture — No global state, no side effects, no I/O
  • Immutability — All functions return new objects
  • Determinism — Identical inputs produce identical outputs
  • Headless — No rendering, UI, or browser dependencies
  • Testability — Pure functions, easy to unit test

Contributing

Please see CONTRIBUTING.md for guidelines on submitting PRs and working with the codebase.

Status

Current version: 0.1.1 — Beta. Suitable for controlled production integrations and early adopters, not yet a stabilized GA SDK. The DSL v0.1 and the runtime API may receive backward-incompatible refinements before 1.0.0.

Recommendations for adopters:

  • Pin an exact version ("@jsondeck/core": "0.1.1") and upgrade deliberately; review the CHANGELOG and release criteria.
  • Treat the GameState returned by getState() / dispatch() / tick() as an owned snapshot; mutate state only through dispatch / tick / reset.

See CHANGELOG.md for release history.

License

MIT — see LICENSE for details.


Monorepo note: This package is part of the JsonDeck platform but stands alone as an independent npm module.