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) btc(value) → {String}
Safely convert satoshis to a BTC string. This function explicitly avoids any floating point arithmetic.
Parameters:
Name | Type | Description |
---|---|---|
value |
Amount | Satoshis. |
- Source:
Returns:
BTC string.
- Type
- String
(static) decode(value, exp) → {Amount}
Safely convert a BTC string to satoshis.
Parameters:
Name | Type | Description |
---|---|---|
value |
String | Number | BTC |
exp |
Number | Exponent. |
- Source:
Throws:
on parse error
Returns:
Satoshis.
- Type
- Amount
(static) encode(value, exp, num) → {String|Number}
Safely convert satoshis to a BTC 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) fromBits(value) → {Amount}
Instantiate amount from bits.
Parameters:
Name | Type | Description |
---|---|---|
value |
Number | String |
- Source:
Returns:
- Type
- Amount
(static) fromBTC(value) → {Amount}
Instantiate amount from btc.
Parameters:
Name | Type | Description |
---|---|---|
value |
Number | String |
- Source:
Returns:
- Type
- Amount
(static) fromMBTC(value) → {Amount}
Instantiate amount from mbtc.
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
(static) fromSatoshis(value) → {Amount}
Instantiate amount from satoshis.
Parameters:
Name | Type | Description |
---|---|---|
value |
Number | String |
- 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 BTC string to satoshis.
Parameters:
Name | Type | Description |
---|---|---|
str |
String | BTC |
- Source:
Throws:
on parse error
Returns:
Satoshis.
- 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) fromBits(value) → {Amount}
Inject properties from bits.
Parameters:
Name | Type | Description |
---|---|---|
value |
Number | String |
- Source:
Returns:
- Type
- Amount
(private) fromBTC(value) → {Amount}
Inject properties from btc.
Parameters:
Name | Type | Description |
---|---|---|
value |
Number | String |
- Source:
Returns:
- Type
- Amount
(private) fromMBTC(value) → {Amount}
Inject properties from mbtc.
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) fromSatoshis(value) → {Amount}
Inject properties from satoshis.
Parameters:
Name | Type | Description |
---|---|---|
value |
Number | String |
- Source:
Returns:
- Type
- Amount
(private) fromValue(value) → {Amount}
Inject properties from value.
Parameters:
Name | Type | Description |
---|---|---|
value |
Amount |
- Source:
Returns:
- Type
- Amount
inspectSymbol() → {String}
Inspect amount.
- Source:
Returns:
- Type
- String
to(unit, numnullable) → {String|Amount}
Get unit string or value.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
unit |
String | Can be |
|
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
toBTC(numnullable) → {String|Amount}
Get btc string or value.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
num |
Boolean |
<nullable> |
- Source:
Returns:
- Type
- String | Amount
toMBTC(numnullable) → {String|Amount}
Get mbtc string or value.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
num |
Boolean |
<nullable> |
- Source:
Returns:
- Type
- String | Amount
toSatoshis(numnullable) → {String|Amount}
Get satoshi string or value.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
num |
Boolean |
<nullable> |
- Source:
Returns:
- Type
- String | Amount
toString() → {String}
Convert amount to bitcoin string.
- Source:
Returns:
- Type
- String
toValue() → {Amount}
Get satoshi value.
- Source:
Returns:
- Type
- Amount