Menu

Functions

encodeName(name, [littleEndian])string.<uint64>

Encode a name (a base32 string) to a number.

For performance reasons, the blockchain uses the numerical encoding of strings for very common types like account names.

decodeName(value, [littleEndian])string
DecimalString()string

Normalize and validate decimal string (potentially large values). Should avoid internationalization issues if possible but will be safe and throw an error for an invalid number.

Normalization removes extra zeros or decimal.

DecimalPad(num, [precision])string

Ensure a fixed number of decimal places. Safe for large numbers.

DecimalImply()

Ensures proper trailing zeros then removes decimal place.

DecimalUnimply(value, precision)number

Put the decimal place back in its position and return the normalized number string (with any unnecessary zeros or an unnecessary decimal removed).

parseAsset()object

Attempts to parse all forms of the asset strings (symbol, asset, or extended versions). If the provided string contains any additional or appears to have invalid information an error is thrown.

encodeName(name, [littleEndian]) ⇒ string.<uint64>

Encode a name (a base32 string) to a number.

For performance reasons, the blockchain uses the numerical encoding of strings for very common types like account names.

Kind: global function
Returns: string.<uint64> - - compressed string (from name arg). A string is always used because a number could exceed JavaScript's 52 bit limit.
See: types.hpp string_to_name

Param Type Default Description
name string A string to encode, up to 12 characters long.
[littleEndian] string true Little or Bigendian encoding

decodeName(value, [littleEndian]) ⇒ string

Kind: global function

Param Type Default Description
value Long | String | number uint64
[littleEndian] string true Little or Bigendian encoding

DecimalString() ⇒ string

Normalize and validate decimal string (potentially large values). Should avoid internationalization issues if possible but will be safe and throw an error for an invalid number.

Normalization removes extra zeros or decimal.

Kind: global function
Returns: string - value

DecimalPad(num, [precision]) ⇒ string

Ensure a fixed number of decimal places. Safe for large numbers.

Kind: global function
Returns: string - decimal part is added and zero padded to match precision
See: ./format.test.js

Param Type Default Description
num number | string | object.toString
[precision] number number of decimal places. Null skips padding suffix but still applies number format normalization.

Example

DecimalPad(10.2, 3) === '10.200'

  

DecimalImply()

Ensures proper trailing zeros then removes decimal place.

Kind: global function

DecimalUnimply(value, precision) ⇒ number

Put the decimal place back in its position and return the normalized number string (with any unnecessary zeros or an unnecessary decimal removed).

Kind: global function
Returns: number - 1.0000

Param Type Description
value string | number | value.toString 10000
precision number 4

parseAsset() ⇒ object

Attempts to parse all forms of the asset strings (symbol, asset, or extended versions). If the provided string contains any additional or appears to have invalid information an error is thrown.

Kind: global function
Returns: object - {amount, precision, symbol, contract}
Throws:

  • AssertionError