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

emath.js

v9.6.0

Published

A library for incremental games based on break_eternity.js

Readme

Header

Abstract

This project started when I was trying to create my first incremental game. I found it difficult to implement certain systems like upgrades and saving. When I eventually made those systems, I wanted to make a package so I could streamline those tools. After a few months of development, I have finally developed it into a presentable state (I should have started it with v0.1.0 instead of v1.0.0 . . .).

Note: This package uses break_eternity.js by exporting the class Decimal directly. You should import the Decimal class from emath.js instead of break_eternity.js. For example,

import { Decimal } from "emath.js";

const num1 = new Decimal(10);
const num2 = num1.add(5);

const num3 = new Decimal(20);
const num4 = Decimal.pow(num1, num3);

This was done in order to implement the saving/loading system using class-transformer and reflect-metadata (which are the only dependencies of this package).

You cannot import directly from break_eternity.js as the package targets a version of javascript (es5) that is not supported by class-transformer and reflect-metadata.

Example Usage

This is a simple example of how to use the package. It creates a game with a currency called "coins" and an upgrade for that currency. It also includes hotkeys for gaining coins and buying upgrades, as well as saving and loading the game.

Note: This example uses javascript. It is recommended to use typescript for better type checking.

import { Decimal } from "emath.js";
import { Game } from "emath.js/game";

// For CDN usage:
// const { Decimal, Game } = eMath; 

// Initialize game
const coinGame = new Game();

// Create a new currency with upgrades
const coins = coinGame.addCurrency("coins", [
    {
        id: "upg1Coins", // Unique ID
        cost: level => level.mul(10), // Cost of 10 times the level
        maxLevel: new Decimal(1000),
        effect: (level, upgradeContext, currencyContext) => {
            // `level` is the level of the upgrade
            // `upgradeContext` is the context of the upgrade (this upgrade)
            // `currencyContext` is the context of the currency (coins in this case)

            // Access the `boost` object to add a boost
            currencyContext.boost.setBoost({
                id: "boostUpg1Coins", // Unique ID of the boost
                // Effect of the boost, which is additive, 11 times the level of the upgrade
                value: n => n.plus(level.mul(11)).sub(1),
            });
        },
    },
    // Add more upgrades here ...
]);

// Initialize / Load game
coinGame.init();
coinGame.dataManager.loadData();

// Gain coins
coins.gain();

// Buy (max) upgrades
coins.buyUpgrade("upg1Coins");

// Hotkeys
coinGame.keyManager.addKey([
    {
        id: "gainCoins",
        name: "Gain Coins",
        key: "g",
        onDownContinuous: () => coins.gain(),
    },
    {
        id: "buyUpgrades",
        name: "Buy Upgrades",
        key: "b",
        onDownContinuous: () => coins.buyUpgrade("upg1Coins"),
    },
]);

// Saving and Loading
window.addEventListener("beforeunload", () => {
    coinGame.dataManager.saveData();
});
coinGame.eventManager.setEvent("autoSave", "interval", 30000, () => {
    coinGame.dataManager.saveData();
    console.log("Auto Saved!");
});

Installation

Install via npm (recommended)

npm install emath.js

Include using CDN

Include the following script in your HTML file. It will set the global variable eMath to the window object.

Note: There is no development build for CDN, as it is used for nodejs. Replace @latest with the version you want to use. (e.g. @8.3.0), or use @latest for the latest version.

emath.js

<script src="https://cdn.jsdelivr.net/npm/emath.js@latest/dist/main/eMath.min.js"></script>

emath.js/game

Also includes "emath.js" so you only need to include this script.

<script src="https://cdn.jsdelivr.net/npm/emath.js@latest/dist/game/eMath.game.min.js"></script>

emath.js/presets

Sets the global variable eMathPresets to the window object.

Note: This does not include either "emath.js" or "emath.js/game".

<script src="https://cdn.jsdelivr.net/npm/emath.js@latest/dist/presets/eMath.presets.min.js"></script>

Check out the documentation!