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

@tablefolk/script

v0.1.0

Published

Scripted stories for games and chat apps: world flags and facts, one condition language, actions, a step runner for workflows (menus as steps the player answers), triggers, and a validator. No DOM; runs in the browser and Node.

Readme

@tablefolk/script

Scripted stories for games and chat apps: world flags and the facts characters know while they hold, one condition language, actions, a step runner for workflows, triggers, and a validator. It has no DOM and no game in it: your app supplies a small host (who carries what, run a character's command, what was said to it, optionally a language model). It runs in the browser and in Node.

Tablefolk uses it for menus, workflows and model-free worlds, through app/story.js in the repository.

Conditions and templates

world.cat_found                     a flag holds (not false, 0, "", "no", "none", "off")
world.favours >= 2                  == != >= <= > <  contains
player has lost cat                 someone carries it (player lacks ...)
player has "bread and butter"       quote names that contain and/or
player.gold >= 10, me.gold, bert.items contains key
answer contains kettle              a workflow run's own variables
not world.paid, (a or b) and c      not / and / or, brackets ("and" binds first)
  • Item names match whole words: "cat" finds "lost cat", but "key" doesn't find "keyring".
  • Templates: {{player}}, {{me}}, {{world.flag}}, {{player.gold}}, and run variables.
  • Errors: parse() throws ExprError with a position.

Actions

A menu choice, a workflow's do step and a trigger's do are one list of effects, run in this order:

| effect | example | |---|---| | take | "take": "lost cat" | | set | "set": {"cat_found": true, "favours": "+1"} | | say | the player's line | | reply | the character's line | | act | command lines: "act": ["give(silver locket)"] | | give | "give": "pie" | | start | a workflow: "start": "riddle" (also workflow) | | stop | "stop": true |

world.x is always a flag. A bare name is a flag in a menu or a trigger, and a run variable inside a workflow.

Workflows (the runner)

Step types:

| step | what it does | |---|---| | await | waits for "speech", or for "turns" | | set | sets run variables or flags | | take | the player hands an item over, with "else" when they don't carry it | | if / then / else | branches on a condition | | choose | "by": ["decider", "model", "default"], the order of who answers | | prompt | a question for the model | | command | a command line; takes the character's turn | | menu | the player picks; "options" maps a choice id to a step, words that fit no choice go to "other" (or the menu asks again), closing goes to "closed" | | do | actions (above) |

Any step can also have goto, end, and max + exit.

A saved run keeps the step's id and a version, so it survives edits to the scenario. Runs pause and resume (a menu opened mid-workflow). advance(id, { until: 'turn' }) stops after a command that took the character's turn; until: 'wait' runs on until the flow waits.

Triggers

"triggers": [ { "on": "flag", "flag": "cat_found", "to": true, "as": "bert", "once": true, "do": { "reply": "Whiskers is home!" } },
              { "on": "given", "who": "pell", "item": "lost cat", "do": { "set": { "cat_found": true } } },
              { "on": "start", "as": "hobb", "do": { "start": "open_shop" } } ]
  • Optional fields: if and once.
  • No chains: a trigger set off while another runs is skipped, so they can't loop.

Validate

validate(scenario) returns [{ level, where, message }]. It finds:

  • conditions that don't parse;
  • goto/then/other targets that don't exist, and steps nothing reaches;
  • menus and workflows that are named but missing;
  • flags that are read but never set;
  • in a world with no model: a choose without a default, and a menu step without other.

Tablefolk's world generator sends the errors back to its model to fix.

Use

import { createState, createRunner, createTriggers, perform, visibleMenu, pickMenu, check, validate, memoryHost } from '@tablefolk/script';

const host = memoryHost({ player: { gold: 10, items: [] }, chars: { bert: { inventory: { items: ['lost cat'] } } } });
const flags = {}, state = createState({ flags: () => flags, facts: () => scenario.facts }); host._state = state;
const runs = {}, store = { get: id => runs[id] || null, set: (id, r) => { if (r) runs[id] = r; else delete runs[id]; } };
const runner = createRunner({ flows: () => scenario.workflows, state, host, store });
const triggers = createTriggers({ list: () => scenario.triggers, state, host, runner });

await perform(menuItem, { host, state, me: 'pell', runner, triggers });   // a menu choice
runner.start('hobb', 'riddle'); await runner.advance('hobb', { until: 'wait' });
host.heard.hobb = ['a kettle']; await runner.advance('hobb', { until: 'wait' });

A host for your own app implements:

| method | what it does | |---|---| | scope(me, vars) | gives conditions access to inventory(who), playerName() and flag(name) | | transfer(from, to, item) | moves an item from one holder to another | | run(actorId, line) | runs a command line as a character; returns { tookTurn } | | hear(actorId) | what was said to the character since it last listened | | ask(actorId, question, parse, options) | asks the model; null when there is none |

Optional: decide, menu(actorId, ref), playerSays, log, ended.

Tests: node test.mjs (35 checks, including a full playthrough of Tablefolk's Willow Lane with no model).

Part of Tablefolk (libs/). MIT.