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 🙏

© 2024 – Pkg Stats / Ryan Hefner

ammonite

v1.5.4

Published

a functional library geared towards incremental games

Downloads

46

Readme

ammonite ammonite

Travis Coveralls npm license stability

Ammonite is a small library made for incremental games.

Features

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

Installation

npm install ammonite --save

Usage

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

API

Amount

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

Methods

Amount(load, treatAsInteger)

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

Example

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

getAll()

Returns all items in the load.

clone()

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

first()

Returns the first item in the load.

last()

Returns the last item in the load.

current()

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

getSize()

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.

Example

amount.sum('total');

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

Example

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.

Example

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

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.

Methods

get(key: K)

Returns the Amount which belongs to the key.

getStore()

Returns the store.

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

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

getKeys()

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

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<T>

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

FAQ

WTF is an Ammonite?

It's this.