Class: Amount

Amount(valuenullable, unitopt)

Amount Represents a currency amount (base unit internally).

Constructor

new Amount(valuenullable, unitopt)

Create an amount.

Parameters:
Name Type Attributes Default Description
value String | Number <nullable>
unit AmountUnitType <optional>
doo
Properties:
Name Type Description
value Number
Source:

Methods

(static) coin(value, numopt) → {String|Number}

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

Parameters:
Name Type Attributes Default Description
value Amount

Base unit.

num Boolean <optional>
false

Return a number.

Source:
Returns:

Currency string.

Type
String | Number

(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, numopt) → {String|Number}

Safely convert base unit to a currency string.

Parameters:
Name Type Attributes Default Description
value Amount
exp Number

Exponent.

num Boolean <optional>
false

Return a number.

Source:
Returns:
Type
String | Number

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

Instantiate amount from unit.

Parameters:
Name Type Description
unit AmountUnitType
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) 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(value, unitopt) → {Amount}

Instantiate amount from options.

Parameters:
Name Type Attributes Default Description
value String | Number
unit AmountUnitType <optional>
doo
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 AmountUnitType
value Number | String
Source:
Throws:

on incorrect unit type.

Returns:
Type
Amount

(private) fromBase(value) → {Amount}

Inject properties from base unit.

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(value, unitopt) → {Amount}

Inject properties from options.

Parameters:
Name Type Attributes Default Description
value String | Number
unit AmountUnitType <optional>
doo
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, numopt) → {String|Amount}

Get unit string or value.

Parameters:
Name Type Attributes Default Description
unit AmountUnitType
num Boolean <optional>
false

Return a number.

Source:
Throws:

on incorrect unit type.

Returns:
Type
String | Amount

toBase(numopt) → {String|Amount}

Get base unit string or value.

Parameters:
Name Type Attributes Default Description
num Boolean <optional>
false

Return a number.

Source:
Returns:
Type
String | Amount

toCoins(numopt) → {String|Amount}

Get currency string or value.

Parameters:
Name Type Attributes Default Description
num Boolean <optional>
false

Return a number.

Source:
Returns:
Type
String | Amount

toMilli(numopt) → {String|Amount}

Get mhns string or value.

Parameters:
Name Type Attributes Default Description
num Boolean <optional>
false

Return a number.

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