Class: Amount

Amount(valuenullable, unitnullable)

Amount Represents a currency amount (base unit internally).

Constructor

new Amount(valuenullable, unitnullable)

Create an amount.

Parameters:
Name Type Attributes Description
value String | Number <nullable>
unit String <nullable>
Properties:
Name Type Description
value Amount
Source:

Methods

(static) coin(value) → {String}

Safely convert base unit to a currency string. This function explicitly avoids any floating point arithmetic.

Parameters:
Name Type Description
value Amount

Base unit.

Source:
Returns:

Currency string.

Type
String

(static) decode(value, exp) → {Amount}

Safely convert a currency string to base unit.

Parameters:
Name Type Description
value String | Number
exp Number

Exponent.

Source:
Throws:

on parse error

Returns:

Base unit.

Type
Amount

(static) encode(value, exp, num) → {String|Number}

Safely convert base unit to a currency string.

Parameters:
Name Type Description
value Amount
exp Number

Exponent.

num Boolean

Return a number.

Source:
Returns:
Type
String | Number

(static) from(unit, value) → {Amount}

Instantiate amount from unit.

Parameters:
Name Type Description
unit String
value Number | String
Source:
Returns:
Type
Amount

(static) fromBase(value) → {Amount}

Instantiate amount from base unit.

Parameters:
Name Type Description
value Number | String
Source:
Returns:
Type
Amount

(static) fromBits(value) → {Amount}

Instantiate amount from bits.

Parameters:
Name Type Description
value Number | String
Source:
Returns:
Type
Amount

(static) fromCoins(value) → {Amount}

Instantiate amount from unit.

Parameters:
Name Type Description
value Number | String
Source:
Returns:
Type
Amount

(static) fromMilli(value) → {Amount}

Instantiate amount from milliunit.

Parameters:
Name Type Description
value Number | String
Source:
Returns:
Type
Amount

(static) fromOptions(valuenullable, unitnullable) → {Amount}

Instantiate amount from options.

Parameters:
Name Type Attributes Description
value String | Number <nullable>
unit String <nullable>
Source:
Returns:
Type
Amount

(private, static) fromValue(value) → {Amount}

Instantiate amount from value.

Parameters:
Name Type Description
value Amount
Source:
Returns:
Type
Amount

(static) value(str) → {Amount}

Safely convert a currency string to base unit.

Parameters:
Name Type Description
str String
Source:
Throws:

on parse error

Returns:

Base unit.

Type
Amount

(private) from(unit, value) → {Amount}

Inject properties from unit.

Parameters:
Name Type Description
unit String
value Number | String
Source:
Returns:
Type
Amount

(private) fromBase(value) → {Amount}

Inject properties from base unit.

Parameters:
Name Type Description
value Number | String
Source:
Returns:
Type
Amount

(private) fromBits(value) → {Amount}

Inject properties from bits.

Parameters:
Name Type Description
value Number | String
Source:
Returns:
Type
Amount

(private) fromCoins(value) → {Amount}

Inject properties from value.

Parameters:
Name Type Description
value Number | String
Source:
Returns:
Type
Amount

(private) fromMilli(value) → {Amount}

Inject properties from mhns.

Parameters:
Name Type Description
value Number | String
Source:
Returns:
Type
Amount

(private) fromOptions(valuenullable, unitnullable) → {Amount}

Inject properties from options.

Parameters:
Name Type Attributes Description
value String | Number <nullable>
unit String <nullable>
Source:
Returns:
Type
Amount

(private) fromValue(value) → {Amount}

Inject properties from value.

Parameters:
Name Type Description
value Amount
Source:
Returns:
Type
Amount

inspect() → {String}

Inspect amount.

Source:
Returns:
Type
String

to(unit, numnullable) → {String|Amount}

Get unit string or value.

Parameters:
Name Type Attributes Description
unit String
num Boolean <nullable>
Source:
Returns:
Type
String | Amount

toBase(numnullable) → {String|Amount}

Get base unit string or value.

Parameters:
Name Type Attributes Description
num Boolean <nullable>
Source:
Returns:
Type
String | Amount

toBits(numnullable) → {String|Amount}

Get bits string or value.

Parameters:
Name Type Attributes Description
num Boolean <nullable>
Source:
Returns:
Type
String | Amount

toCoins(numnullable) → {String|Amount}

Get currency string or value.

Parameters:
Name Type Attributes Description
num Boolean <nullable>
Source:
Returns:
Type
String | Amount

toMilli(numnullable) → {String|Amount}

Get mhns string or value.

Parameters:
Name Type Attributes Description
num Boolean <nullable>
Source:
Returns:
Type
String | Amount

toString() → {String}

Convert amount to currency string.

Source:
Returns:
Type
String

toValue() → {Amount}

Get base unit value.

Source:
Returns:
Type
Amount