utils

utils

Methods

(static) DecimalImply(value, precision) → {string}

Ensures proper trailing zeros then removes decimal place.

Example
import {DecimalImply} from "u3.js/src";
const u3 = createU3(config)
u3.DecimalImply(10.2, 3) === '10200'
Parameters:
Name Type Description
value number | string | object.toString

eg.10.2

precision number

eg.3

Returns:
Type
string

(static) DecimalPad(num, precisionopt) → {string}

See:
  • ./format.test.js

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

Example
import {DecimalPad} from "u3.js/src";
const u3 = createU3(config)
u3.DecimalPad(10.2, 3) === '10.200'
Parameters:
Name Type Attributes Default Description
num number | string | object.toString
precision number <optional>
null

number of decimal places. Null skips padding suffix but still applies number format normalization.

Returns:

decimal part is added and zero padded to match precision

Type
string

(static) 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.

Example
import {DecimalString} from "u3.js/src";
Returns:

value

Type
string

(static) 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).

Example
import {DecimalUnimply} from "u3.js/src";
const u3 = createU3(config)
u3.DecimalUnimply(10000, 4) === '1.0000'
Parameters:
Name Type Description
value string | number | value.toString

10000

precision number

4

Returns:

1.0000

Type
number

(static) decodeName(value, littleEndian) → {string|string}

Example
import {decodeName} from "u3.js/src";
const u3 = createU3(config)
u3.decodeName(encodeName('ultrain'))
Parameters:
Name Type Default Description
value string
littleEndian true
Returns:
Type
string | string

(static) decodeNameEx(valueH, valueL, littleEndian) → {string|string}

Example
import {decodeNameEx} from "u3.js/src";
Parameters:
Name Type Default Description
valueH
valueL
littleEndian true
Returns:
Type
string | string

(static) decodeSymbolName(symbolName, littleEndianopt)

decode an integer style value to Asset's Symbol Name.

Parameters:
Name Type Attributes Default Description
symbolName *

uint 64 value to be parsed to Asset's Symbol Name, it can be a string like "1396787029", or a integer like 1396787029.

littleEndian boolean <optional>
true

to determine if 'symbolName' is little endian or big endian.

Returns:

a String stands for Asset's Symbol Name.

(static) encodeName(name, littleEndian) → {string}

Example
import {encodeName} from "u3.js/src";
const u3 = createU3(config)
u3.encodeName('ultrain')
Parameters:
Name Type Default Description
name

A name can be up to 12 characters long

littleEndian true
Returns:
Type
string

(static) encodeNameEx(name, littleEndian)

Example
import {encodeNameEx} from "u3.js/src";
const u3 = createU3(config)
u3.encodeNameEx('ultrain')
Parameters:
Name Type Default Description
name

A name_ex can be up to 21 characters long

littleEndian true

(static) isName(str, err) → {boolean}

Example
import {isName} from "u3.js/src";
const u3 = createU3(config)
u3.isName('ultrain')
Parameters:
Name Type Description
str string

code name

err boolean

Whether to display an error message

Returns:
Type
boolean

(static) 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.

Example
import {parseAsset} from "u3.js/src";
Throws:

AssertionError

Returns:

{amount, precision, symbol, contract}

Type
object

(static) parseExtendedAsset(str) → {Object}

Example
import {parseExtendedAsset} from "u3.js/src";
const u3 = createU3(config)
u3.parseExtendedAsset('1.0 4,[email protected]')
Parameters:
Name Type Description
str String

String to be parsed

Returns:
Type
Object

(static) UDecimalImply(value, precision) → {*}

Ensures proper trailing zeros then removes decimal place

Parameters:
Name Type Description
value
precision
Returns:
Type
*

(static) UDecimalPad(num, precision) → {*}

Example
import {UDecimalPad} from "u3.js/src";
const u3 = createU3(config)
u3.UDecimalPad('10.1', 1)
Parameters:
Name Type Description
num String

decimal

precision Number

Precision should be 18 characters or less

Returns:
Type
*

(static) UDecimalString(value) → {string}

Example
import {UDecimalString} from "u3.js/src";
const u3 = createU3(config)
u3.UDecimalString(10.1)
Parameters:
Name Type Description
value Number

Decimal

Returns:
Type
string

(static) UDecimalUnimply(value, precision) → {*}

Example
import {UDecimalUnimply} from "u3.js/src";
const u3 = createU3(config)
u3.UDecimalUnimply('10', 1)
Parameters:
Name Type Description
value String

Integer

precision Number

Precision should be 18 characters or less

Returns:
Type
*

(static) ULong(value, unsigned, radix) → {*}

Example
import {ULong} from "u3.js/src";
Parameters:
Name Type Default Description
value
unsigned true
radix 10
Returns:
Type
*