scribe-rpg-coin-purse

1.2.4 • Public • Published

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

Readme

Keywords

none

Package Sidebar

Install

npm i scribe-rpg-coin-purse

Weekly Downloads

0

Version

1.2.4

License

MIT

Last publish

Collaborators

  • luetkemj