a functional library geared towards incremental games


3101.5.45 years ago5 years agoMinified + gzip package size for ammonite in KB


ammonite ammonite

Travis Coveralls npm license stability

Ammonite is a small library made for incremental games.


  • Small (under ~3Kb)
  • Immutable leverages Immutable.js constructs
  • Functional focuses on pure functions, helps ensure fewer side-effects


npm install ammonite --save


import { Amount, AmountStore, Metric, NewEntryOptions } from 'ammonite';



Amount is a class that Ammonite uses to control metrics. Its constructor takes a List of an item that has the same subset of properties as Metric (see Metric for more information). It uses a list as an easy way to maintain a record of all values—in a lot of incremental games, this ability is often lost, as it simply mutates a single value over time.

Property Type Optional? Default
load List<T extends Metric> No
treatAsInteger boolean Yes false
  • load is the List
  • treatAsInteger will round the value after each evaluation


Amount(load, treatAsInteger)

This is the constructor function for the Amount class. Remember that it requires an interface which extends from Metric.


interface Dogs {
  total: number;
  averageWoof: number;
  averageBark: number;
let dogs = new Amount(List<Dogs>(), true);


Returns all items in the load.


Returns an exact copy of Amount. Note: not of load, but of the class itself.


Returns the first item in the load.


Returns the last item in the load.


Return the last item item in the load (alias for last()).


Returns the size of the load.

push(n: T)

Pushes a new value to the load and returns the new load.

Note that the type of n must satisfy T, which is F-bounded to Metric.

sum(prop: string)

Returns the sum of the given property. Note that the property itself should be of type number.



includes(v: T)

Returns a true if v is included in the load. Returns false otherwise.

sort<C>(prop: string)

Returns a new sorted List

  • C generic corresponds to the type of the property
  • prop is the property accessor for the Metric property


amount.sort<number>(prop: 'total');

amount.sort<number>(prop: 'time');

amount.sort<string>(prop: 'alphabet');

increment(inc: number, opts: NewEntryOptions<T>)

Increments the last value of the load and then returns a new load with the added value pushed onto it.

See NewEntryOptions<T> for more information.


amount.load = amount.increment(43);

amount.load = amount.increment(1.057, { exponential: true });

decrement(inc: number, opts: NewEntryOptions<T>)

Same as increment, except it substracts the given value, i.e. decrement(43) would subtract 43 from the most recent value.


AmountStore<K, V> is a class for managing all instances of Amount.

Property Type Optional? Default
store Map<K, Amount<V>> No

Under most cases K will be a string, but it can also be a number.


get(key: K)

Returns the Amount which belongs to the key.


Returns the store.

set(key: K, value: Amount<V>)

Returns a new Map after settings a new value for the given key.


Returns an Iterator from the keys of store.

update(key: K, newValue: Amount<V>)

Returns a new Map with the updated value at the given key.

forEach(sideEffect: (value: Amount<V>, key: K, iter: Iterable<K, Amount<V>>) => any)

Performs a given side-effect.

Returns the number of times the side-effect was produced.


Metric is an interface that is F-bounded to Amount.

Property Type Optional? Default
total number No
time number Yes
[prop: string] any Yes

All generic types of Amount must extend from Metric. This is easy to do with extends.

interface Click extends Metric {
    total: number;
    doubleClick?: boolean;


NewEntryOptions is the interface for new additions via increment and decrement.

Property Type Optional? Default
exponential number No
extra any Yes
  • exponential determines whether the increment number is treated as an exponential
  • extra is for additional metadata that may be required


WTF is an Ammonite?

It's this.

Ammonite made by Freepik from is licensed by CC 3.0 BY. Code licensed under MIT

If you find any bugs or have a feature request, please open an issue on github!

The npm package download data comes from npm's download counts api and package details come from