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

scribe-rpg-coin-purse

v1.2.4

Published

Fantasy RPG Currency Exchange

Downloads

11

Readme

Scribe Coin Purse Build Status

NPM

A Fantasy RPG Currency Exchange.

Getting started

npm install --save scribe-rpg-coin-purse

Features

This project makes it easy to:

  • Add and subtract multiple denominations
  • Parse strings for value denomination pairs
  • Keep your coins organized

Documentation

config

Most functions accept a config object.

Supported config values:

denominations

An array of denomination objects

Schema:

{
  name: String,
  abrv: String, (must be two uppercase letters)
  copperValue: Number,
}

Default:

[
  {
    name: 'copper',
    abrv: 'CP',
    copperValue: 1,
  },
  {
    name: 'silver',
    abrv: 'SP',
    copperValue: 10,
  },
  {
    name: 'electrum',
    abrv: 'EP',
    copperValue: 50,
  },
  {
    name: 'gold',
    abrv: 'GP',
    copperValue: 100,
  },
  {
    name: 'platinum',
    abrv: 'PP',
    copperValue: 1000,
  },
]

copperValue(string, config)

Description

Returns the total copper value of string.

Usage

copperValue(string, config)

  • string {string} required

    • A string with value denomination pairs in it to be parsed
  • config {object} optional

    • an object containing configuration options
    • default value: { denominations }
  • @return {number} sum of all value denomination pairs in string

Example

const val = copperValue('This sword is worth 20gp');

val === 200;

parser(exp, config)

Description

Returns an array of objects describing each denomination value pair found within exp.

Usage

parser(exp, config)

  • exp {string} required

    • A string containing value denomination pairs
  • config {object} optional

    • an object containing configuration options
    • default value: { denominations }
  • @return {array}

[
  {
    match: String, // the match found
    value: String, // the value in the found match
    denomination: String, // the denomination in the found match
  },
  ...
]

Example

const val = parser('This sword is worth 20gp');

val === { match: '20gp', value: '20', denomination: 'GP' };

subUnits(coppers, config)

Description

Takes a copper value and returns and object containing each denomination and their value.

Usage

subUnits(coppers, config)

  • exp {number} required

    • A number representing the total copper value to be parsed
  • config {object} optional

    • an object containing configuration options
    • default value: { denominations }
  • @return {object} [contains a key for each denomination in denominations]

{
  CP: 0,
  SP: 0,
  EP: 0,
  GP: 0,
  PP: 0,
}

Example

const val = subUnits(1161);

val === {
  CP: 1,
  SP: 1,
  EP: 1,
  GP: 1,
  PP: 1,
};

total(array, config)

Description

Returns the total copper value of all expressions in array

Usage

total(array, config)

  • array {array} required

    • An array of strings containing value denomination pairs
  • config {object} optional

    • an object containing configuration options
    • default value: { denominations }
  • @return {number}

Example

const val = total(['1CP', '1CP']);

val === 2;

values(copperValue, config)

Description

Returns each total denomination value within given copperValue

Usage

total(array, config)

  • array {array} required

    • An array of strings containing value denomination pairs
  • config {object} optional

    • an object containing configuration options
    • default value: { denominations }
  • @return {number}

Example:

const vals = values(1161);

vals === {
  CP: 1161,
  SP: 116,
  EP: 23,
  GP: 11,
  PP: 1,
}

Contributing

Feature requests, issues, and contributions are all welcome.

issues