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

@civ-clone/base-government-change

v0.1.2

Published

How a player changes government: a revolution kept as a pending effect, the interim government while it lasts, how long it lasts, choosing the new one, which governments are available, and what a change sets off, for a ruleset to wrap in its own rules.

Readme

base-government-change

How a player changes government, for a ruleset to wrap in its own Added, Action, AnarchyDuration, Availability, Changed, RevolutionTerms, MayRechoose, GovernmentAvailable and research Complete rules with its own ids, governments and numbers:

  • Rules/AnarchyDuration: the rule asked how many turns of the interim government a revolution causes, for a RevolutionCause ('chosen' or 'civil-disorder'). The shortest answer wins.
  • Rules/RevolutionTerms: the rule that names the ruleset's revolution, its handler key and Interim government, so code outside the ruleset (a computer player) can start and finish its revolutions through lib/revolution. lib/terms has terms(key, Interim), the rule's effect, and revolutionTerms(ruleRegistry), which reads it (null with no rule). A game has one ruleset's terms: if two are registered, the first answer wins.
  • lib/revolution: a revolution kept as a PendingEffect on the PlayerGovernment under the ruleset's own handler key (a save names it). revolution(key, Interim, …) starts one, turnsUntilChoice and pendingRevolution read it, chooseGovernment finishes it (given the game's rules as its last argument, it also records the choice for MayRechoose), and registerRevolutionHandler lets one loaded from a save finish. RevolutionError is what they throw.
  • Rules/MayRechoose: whether a player may choose its government again, with no interim, in the turn it chose one. With no rule that says so, it may not. lib/rechoice keeps the turn of the choice as a PendingEffect on the PlayerGovernment under <key>:rechoice (never discharged; the next choice replaces it; registerRevolutionHandler registers a handler for it that does nothing), written only when chooseGovernment is given the game's rules and a MayRechoose rule says yes. In that turn, a revolution the player chooses ('chosen') starts no interim and makes the choice due at once, whatever AnarchyDuration says. mayRechoose, chosenThisTurn and rechoiceOpen read it.
  • Rules/GovernmentAvailable and lib/offer: offering a revolution when an advance makes a government available. offerGovernments(key, entries, …) is a research Complete rule's effect: for each government that one of entries (the ruleset's "government requires advances" entries) requires the discovered advance for, that the player may now choose (governmentsOpenedBy) and doesn't already have, unless a revolution under key is under way, it asks the GovernmentAvailable(player, government) rules, and when any says yes the engine emits player:government:available with the player and the government. With no GovernmentAvailable rules, nothing is offered.
  • lib/actions: the player Action criteria and effects: notInInterim, noRevolutionPending and offerRevolution (Revolution), then choiceDue and offerGovernmentChoice (ChooseGovernment).
  • lib/playerGovernment: addPlayerGovernment(player, Initial, …), for an Added rule.
  • lib/anarchyDuration: forCause(cause) and randomDuration(min, max, rng), for AnarchyDuration rules.
  • lib/availability: availabilityRulesFor(entry, …) and deriveAvailabilityRules(…), the Availability rule a requirement entry ("government requires advances") is played by.
  • lib/changed: emitGovernmentChanged, hasPlayerWorld and clearYieldCaches, for Changed rules.
  • lib/governedBy: governedBy(player, governments, …), whether a player has one of governments (no, when the player has none), for rules that depend on the government.

A library: it registers no rules. See civ1-government for Civilization's governments, durations and ids.