# @iota/converter

> Convert values & trytes to trits and back

Latest version **1.0.0-beta.30** (published 2020-06-18) · MIT license · 0 weekly downloads

## Install

```sh
npm install @iota/converter
pnpm add @iota/converter
yarn add @iota/converter
bun add @iota/converter
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0-beta.30 |
| Published | 2020-06-18 |
| First published | 2018-06-25 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 53.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | domschiener, laumair, lexerr, lucasfernog, martyniota, nothingismagick |
| Keywords | iota, tangle, library, browser, javascript, nodejs, API |

## Links

- npm: https://www.npmjs.com/package/@iota/converter
- Repository: https://github.com/iotaledger/iota.js.git/tree/develop/packages/crypto
- Issues: https://github.com/iotaledger/iota.js/issues
- npm.io page: https://npm.io/package/@iota/converter

## Dependencies (1)

- [core-js](https://npm.io/package/core-js.md) ^3.1.4

## Alternatives

- [@opentelemetry/exporter-zipkin](https://npm.io/package/@opentelemetry/exporter-zipkin.md) — 14.8M weekly downloads
- [pusher-js](https://npm.io/package/pusher-js.md) — 2.0M weekly downloads
- [browserify](https://npm.io/package/browserify.md) — 1.7M weekly downloads
- [sqs-consumer](https://npm.io/package/sqs-consumer.md) — 1.7M weekly downloads
- [@sanity/eventsource](https://npm.io/package/@sanity/eventsource.md) — 930.8K weekly downloads

## Recent versions

- 1.0.0-beta.30 (latest) — 2020-06-18
- 1.0.0-alpha.a09e7908 (canary) — 2019-02-20
- 1.0.0-beta.23 — 2019-11-27
- 1.0.0-beta.21 — 2019-08-05
- 1.0.0-beta.19 — 2019-07-19
- 1.0.0-beta.16 — 2019-06-20
- 1.0.0-beta.15 — 2019-06-14
- 1.0.0-beta.12 — 2019-04-09
- 1.0.0-beta.11 — 2019-02-22
- 1.0.0-beta.10 — 2019-02-21
- 1.0.0-beta.9 — 2019-02-21
- 1.0.0-alpha.66ccc99f — 2019-02-19
- 1.0.0-alpha.e5bd9497 — 2019-02-19
- 1.0.0-alpha.912642aa — 2019-02-18
- 1.0.0-alpha.899a376d — 2019-02-17
- … 25 more at https://npm.io/package/@iota/converter/versions

## README

# @iota/converter

Methods for converting ascii, values &amp; trytes to trits and back.

## Installation

Install using [npm](https://www.npmjs.org/):
```
npm install @iota/converter
```

or using [yarn](https://yarnpkg.com/):

```
yarn add @iota/converter
```

## API Reference

    
* [converter](#module_converter)

    * [.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)


<a name="module_converter.asciiToTrytes"></a>

### *converter*.asciiToTrytes(input)
**Summary**: Converts ASCII characters to trytes.  
**Throws**:

- <code>errors.INVALID\_ASCII\_CHARS</code> : Make sure that the `input` argument contains only valid ASCII characters.


| Param | Type | Description |
| --- | --- | --- |
| input | <code>string</code> | ASCII input |

This method converts ASCII characters to [trytes](https://docs.iota.org/docs/getting-started/0.1/introduction/ternary).

## Related methods

To convert trytes to ASCII characters, use the [`trytesToAscii()`](#module_converter.trytesToAscii) method.

**Returns**: <code>string</code> - Trytes  
**Example**  
```js
let trytes = Converter.asciiToTrytes('Hello, where is my coffee?');
```
<a name="module_converter.trytesToAscii"></a>

### *converter*.trytesToAscii(trytes)
**Summary**: Converts trytes to ASCII characters.  
**Throws**:

- <code>errors.INVALID\_TRYTES</code> : Make sure that the `trytes` argument contains only valid trytes (A-Z or 9).
- <code>errors.INVALID\_ODD\_LENGTH</code> : Make sure that the `trytes` argument contains an even number of trytes.


| Param | Type | Description |
| --- | --- | --- |
| trytes | <code>string</code> | 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 the [`asciiToTrytes()`](#module_converter.asciiToTrytes) method.

**Returns**: <code>string</code> - ASCII characters  
**Example**  
```js
let message = Converter.trytesToAscii('IOTA');
```
<a name="module_converter.trytesToTrits"></a>

### *converter*.trytesToTrits(input)
**Summary**: Converts trytes to trits.  
**Throws**:

- <code>errors.INVALID\_TRYTES</code> : Make sure that the `input` argument contains only valid trytes (A-Z or 9).


| Param | Type | Description |
| --- | --- | --- |
| input | <code>String</code> \| <code>number</code> | Trytes |

This method converts [trytes](https://docs.iota.org/docs/getting-started/0.1/introduction/ternary) to trits.

## Related methods

To convert ASCII characters to trytes, use the [`asciiToTrytes()`](#module_converter.asciiToTrytes) method.

**Returns**: <code>Int8Array</code> - trits  
**Example**  
```js
let trits = Converter.trytesToTrits('IOTA');
```
<a name="module_converter.tritsToTrytes"></a>

### *converter*.tritsToTrytes(input)
**Summary**: Converts trits to trytes.  
**Throws**:

- <code>errors.INVALID\_TRITS</code> : Make sure that the `input` argument contains an array of trits.


| Param | Type | Description |
| --- | --- | --- |
| input | <code>String</code> \| <code>number</code> | Trits |

This method converts [trits](https://docs.iota.org/docs/getting-started/0.1/introduction/ternary) to trytes.

## Related methods

To convert trytes to ASCII characters, use the [`trytesToAscii()`](#module_converter.trytesToAscii) method.

**Returns**: <code>Int8Array</code> - trytes  
**Example**  
```js
let trytes = Converter.tritsToTrytes(trits);
```
<a name="module_converter.tritsToValue"></a>

### *converter*.tritsToValue(input)
**Summary**: Converts trits to a number.  

| Param | Type | Description |
| --- | --- | --- |
| input | <code>String</code> \| <code>number</code> | Trits |

This method converts [trits](https://docs.iota.org/docs/getting-started/0.1/introduction/ternary) to a number.

## Related methods

To convert trytes to trits, use the [`trytesToTrits()`](#module_converter.trytesToTrits) method.
To convert trits to trytes, use the [`tritsToTrytes()`](#module_converter.tritsToTrytes) method.

**Returns**: <code>Int8Array</code> - number  
**Example**  
```js
let number = Converter.tritsToValue(trits);
```
<a name="module_converter.valueToTrits"></a>

### *converter*.valueToTrits(input)
**Summary**: Converts trits to a number.  

| Param | Type | Description |
| --- | --- | --- |
| input | <code>String</code> \| <code>number</code> | Number |

This method converts a number to [trits](https://docs.iota.org/docs/getting-started/0.1/introduction/ternary).

## Related methods

To convert trits to trytes, use the [`tritsToTrytes()`](#module_converter.tritsToTrytes) method.

**Returns**: <code>Int8Array</code> - trits  
**Example**  
```js
let trits = Converter.valueToTrits(9);
```

---
_Source: https://npm.io/package/@iota/converter · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
