@iota/converter
Methods for converting ascii, values & trytes to trits and back.Installation
Install using npm:npm install @iota/converter
or using yarn:
yarn add @iota/converter
API Reference
* [.asciiToTrytes(input)](#module_converter.asciiToTrytes)
* [.trytesToAscii(trytes)](#module_converter.trytesToAscii)
* [.trytesToTrits(input)](#module_converter.trytesToTrits)
* [.tritsToTrytes(input)](#module_converter.tritsToTrytes)
* [.tritsToValue(input)](#module_converter.tritsToValue)
* [.valueToTrits(input)](#module_converter.valueToTrits)
converter.asciiToTrytes(input)
Summary: Converts ASCII characters to trytes.Throws:
errors.INVALID\_ASCII\_CHARS
: Make sure that theinput
argument contains only valid ASCII characters.
| Param | Type | Description | | --- | --- | --- | | input |
string
| ASCII input |This method converts ASCII characters to trytes.
Related methods
To convert trytes to ASCII characters, use thetrytesToAscii()
method.Returns:
string
- TrytesExample
let trytes = Converter.asciiToTrytes('Hello, where is my coffee?');
converter.trytesToAscii(trytes)
Summary: Converts trytes to ASCII characters.Throws:
errors.INVALID\_TRYTES
: Make sure that thetrytes
argument contains only valid trytes (A-Z or 9).errors.INVALID\_ODD\_LENGTH
: Make sure that thetrytes
argument contains an even number of trytes.
| Param | Type | Description | | --- | --- | --- | | trytes |
string
| An even number of trytes |This method converts trytes to ASCII characters.
Because each ASCII character is represented as 2 trytes, the given trytes must be of an even length.
Related methods
To convert ASCII characters to trytes, use theasciiToTrytes()
method.Returns:
string
- ASCII charactersExample
let message = Converter.trytesToAscii('IOTA');
converter.trytesToTrits(input)
Summary: Converts trytes to trits.Throws:
errors.INVALID\_TRYTES
: Make sure that theinput
argument contains only valid trytes (A-Z or 9).
| Param | Type | Description | | --- | --- | --- | | input |
String
\| number
| Trytes |This method converts trytes to trits.
Related methods
To convert ASCII characters to trytes, use theasciiToTrytes()
method.Returns:
Int8Array
- tritsExample
let trits = Converter.trytesToTrits('IOTA');
converter.tritsToTrytes(input)
Summary: Converts trits to trytes.Throws:
errors.INVALID\_TRITS
: Make sure that theinput
argument contains an array of trits.
| Param | Type | Description | | --- | --- | --- | | input |
String
\| number
| Trits |This method converts trits to trytes.
Related methods
To convert trytes to ASCII characters, use thetrytesToAscii()
method.Returns:
Int8Array
- trytesExample
let trytes = Converter.tritsToTrytes(trits);
converter.tritsToValue(input)
Summary: Converts trits to a number.| Param | Type | Description | | --- | --- | --- | | input |
String
\| number
| Trits |This method converts trits to a number.
Related methods
To convert trytes to trits, use thetrytesToTrits()
method.
To convert trits to trytes, use the tritsToTrytes()
method.Returns:
Int8Array
- numberExample
let number = Converter.tritsToValue(trits);
converter.valueToTrits(input)
Summary: Converts trits to a number.| Param | Type | Description | | --- | --- | --- | | input |
String
\| number
| Number |This method converts a number to trits.
Related methods
To convert trits to trytes, use thetritsToTrytes()
method.Returns:
Int8Array
- tritsExample
let trits = Converter.valueToTrits(9);