# @helixnetwork/converter

> Converter for ASCII and hexadecimal bytes (txs).

Latest version **1.0.0-alpha.7** (published 2019-09-24) · MIT license · 0 weekly downloads

## Install

```sh
npm install @helixnetwork/converter
pnpm add @helixnetwork/converter
yarn add @helixnetwork/converter
bun add @helixnetwork/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-alpha.7 |
| Published | 2019-09-24 |
| First published | 2019-02-26 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 179.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 5 |
| Maintainers | ahasikos, ajith_er, dad1x, dnck, dt93, dzlzv, fsbbn, mahi30795, netobjex, ofo42, sachushaji, shahanaspatel17, stefan-precup, tittu, tunghoang, vipindas28 |
| Keywords | helix, tangle, library, browser, javascript, nodejs, API |

## Links

- npm: https://www.npmjs.com/package/@helixnetwork/converter
- Repository: https://github.com/helixnetwork/helix.api.git/tree/dev/packages/crypto
- Issues: https://github.com/helixnetwork/helix.api/issues
- npm.io page: https://npm.io/package/@helixnetwork/converter

## 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-alpha.7 (latest) — 2019-09-24
- 1.0.0-alpha.6 — 2019-08-15
- 1.0.0-alpha.5 — 2019-08-06
- 1.0.0-alpha.4 — 2019-07-31
- 1.0.0-alpha.3 — 2019-07-24
- 1.0.0-alpha.2 — 2019-05-09
- 1.0.0-alpha.1 — 2019-03-02
- 1.0.0-alpha.0 — 2019-02-26

## README

# @helixnetwork/converter

Methods for converting ascii values to txs, txBits and back.

## Installation

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

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

```
yarn add @helixnetwork/converter
```

## API Reference


* [converter](#module_converter)

    * [.asciiToTxHex(input)](#module_converter.asciiToTxHex)

    * [.txsToAscii(txs)](#module_converter.txsToAscii)

    * [.txBits(input)](#module_converter.txBits)

    * [.txs(txBits)](#module_converter.txs)

    * [.value(txBits)](#module_converter.value)

    * [.fromValue(value)](#module_converter.fromValue)

    * [.toTxBytes(value, padding)](#module_converter.toBytes)


The following data types are used in this packages:
TxBits - which represents and array of bits, stored in a Int8Array object.
TxBytes - which represents and array of unsigned bytes, stored in a Uint8Array object
TxHex - which represents the hexadecima string, because of this should contain only 0-91-f and should have a even length. 


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

### *converter*.asciiToTxHex(input)

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


Converts an ascii encoded string to txs.

### How conversion works:

An ascii value of `1 Byte` can be represented in `2` hexadecimal characters:


1. We get the decimal unicode value of an individual ASCII character this code can be represented in a Byte

2. Decimal value is then converted into hexadecimal value

### Example:

Lets say we want to convert ascii character `Z`.

1. `Z` has a decimal unicode value of `90`.

2. `90` in hexadecimal is 5a

Therefore ascii character `Z` is represented as `5a` in TxHex.

**Returns**: <code>string</code> - string of txs  
<a name="module_converter.txsToAscii"></a>

### *converter*.txsToAscii(txs)

| Param | Type | Description |
| --- | --- | --- |
| txs | <code>string</code> | txs |

Converts txs of _even_ length to an ascii string


**Returns**: <code>string</code> - string in ascii  
<a name="module_converter.txBits"></a>

### *converter*.txBits(input)

| Param | Type | Description |
| --- | --- | --- |
| input | <code>TxHex</code> \ <code>Number</code> | TxHex or value to be converted. |


Converts txs or values to txBits

**Returns**: <code>Int8Array</code> - txBits  
<a name="module_converter.txs"></a>

### *converter*.txs(txBits)

| Param | Type |
| --- | --- |
| hBits | <code>Int8Array</code> |

Converts txBits to txs

**Returns**: <code>String</code> - txs  

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

### *converter*.value(txBits)

| Param | Type |
| --- | --- |
| txBits | <code>Int8Array</code> |


Converts txBits into an integer value

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

### *converter*.fromValue(value)

| Param | Type |
| --- | --- |
| value | <code>Number</code> |


Converts an integer value to txBits

**Returns**: <code>Int8Array</code> - txBits  

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

### *converter*.toTxBytes(value, padding)

| Param | Type | Description |
| --- | --- | --- |
| value | <code>number</code> | Value that should be converted |
| padding | <code>number</code> | Padding for the converted string |

Converts an integer value to byte array

**Returns**: <code>TxBytes</code> - txBytes

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