Class: Amount

Amount(valueopt, nullable, unitopt)

Amount Represents a currency amount (base unit internally).

Constructor

new Amount(valueopt, nullable, unitopt)

Create an amount.

Parameters:
Name Type Attributes Default Description
value String | Number <optional>
<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 AmountValue

Base unit.

num Boolean <optional>
false

Return a number.

Source:
Returns:

Currency string.

Type
String | Number

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

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
AmountValue

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

Safely convert base unit to a currency string.

Parameters:
Name Type Attributes Default Description
value AmountValue
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

(static) fromValue(value) → {Amount}

Instantiate amount from value.

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

(static) value(str) → {AmountValue}

Safely convert a currency string to base unit.

Parameters:
Name Type Description
str String
Source:
Throws:

on parse error

Returns:

Base unit.

Type
AmountValue

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

fromBase(value) → {Amount}

Inject properties from base unit.

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

fromCoins(value) → {Amount}

Inject properties from value.

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

fromMilli(value) → {Amount}

Inject properties from mhns.

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

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

fromValue(value) → {Amount}

Inject properties from value.

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

inspect() → {String}

Inspect amount.

Source:
Returns:
Type
String

to(unit, numopt) → {String|AmountValue}

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

toBase(numopt) → {String|AmountValue}

Get base unit string or value.

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

Return a number.

Source:
Returns:
Type
String | AmountValue

toCoins(numopt) → {String|AmountValue}

Get currency string or value.

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

Return a number.

Source:
Returns:
Type
String | AmountValue

toMilli(numopt) → {String|AmountValue}

Get mhns string or value.

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

Return a number.

Source:
Returns:
Type
String | AmountValue

toString() → {String|AmountValue}

Convert amount to currency string.

Source:
Returns:
Type
String | AmountValue

toValue() → {AmountValue}

Get base unit value.

Source:
Returns:
Type
AmountValue