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-stats-core

v0.2.0

Published

Engine-agnostic character-stat + modifier/buff-stack engine — HP, attack, move-speed and the like, computed from a base value plus stacked modifiers with a correct, fixed resolution order (flat add → additive-percent → multiplicative-percent), source grou

Readme

miaoda-game-stats-core

Use this package for derived character attributes such as attack, armor, move speed, or maximum HP. A stat combines a base value with flat, additive-percent, and multiplicative-percent modifiers, optional bounds, source tags, and timed buffs. It does not own current HP, damage rules, rendering, or a clock.

Install

pnpm add miaoda-game-stats-core

Define stats and modifiers

import { Stat, StatSet } from 'miaoda-game-stats-core';

const attack = new Stat(10);
attack.addModifier('flat', 5, { source: 'sword' });
const rage = attack.addModifier('percentAdd', 0.5);
attack.value; // 22.5
attack.removeModifier(rage);

const hero = new StatSet({
  maxHp: 100,
  attack: { base: 10, bounds: { min: 0 } },
  moveSpeed: 5,
});
hero.applyBuff({
  id: 'slow',
  duration: 3,
  modifiers: [{ stat: 'moveSpeed', op: 'percentAdd', value: -0.5 }],
});
hero.tick(3); // timed values use seconds

Modifier resolution is order-independent:

(base + sum(flat)) * (1 + sum(percentAdd)) * product(1 + percentMult)

percentAdd values are fractions (0.5 means +50%) and are summed before applying. percentMult values compound individually. Bounds clamp the final result.

Buffs and time

applyBuff replaces an existing buff with the same ID, refreshing its duration instead of duplicating it. A buff can target several stats; unknown target stats are skipped. tick(dtSeconds) returns the number of expired modifiers and must be called by your game loop or an engine adapter.

hero.listBuffs();
hero.hasBuff('slow');
hero.removeBySource('sword');
hero.clearBuffs();

Use source tags for equipment, auras, or a whole effect family that should be removed together. get, setBase, modifier operations, and onChange throw for an undefined stat; call has or stat first when names are optional.

Observe and save

const stop = hero.onChange('attack', (value) => renderAttack(value));
const save = hero.toJSON();
hero.loadJSON(save);

toJSON includes bases, bounds, live modifiers, and remaining durations. Buff registry links are intentionally flattened when saved, so loaded modifiers still expire and can be removed by source but are no longer removable by their original buff ID. Loading is atomic and validates finite values and duplicate IDs.

Public API

| API | Use it for | | --- | --- | | computeModifiers / clamp | Pure stat math | | Stat | One derived value and its modifiers | | StatSet | A named sheet with buffs, listeners, ticking, and JSON save data | | addModifier / removeModifier | Equipment and one-off effects | | applyBuff / removeBuff | Timed or grouped multi-stat effects | | onChange | Update HUDs and derived gameplay values |

Pair this package with a resource or health system for current pools, status-core for ongoing effects, and combat2d-core for accepted hits. The stat engine supplies values; it does not apply damage or regenerate resources.