# @harmony-js/utils

> utils for harmony

Latest version **0.1.56** (published 2020-11-22) · MIT license · 0 weekly downloads

## Install

```sh
npm install @harmony-js/utils
pnpm add @harmony-js/utils
yarn add @harmony-js/utils
bun add @harmony-js/utils
```

## Health

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

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

Warnings: low downloads; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.56 |
| Published | 2020-11-22 |
| First published | 2019-05-17 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 2 |
| Unpacked size | 115.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | neeboo@firestack.one |
| Maintainers | gupadhyaya, jhwon0820, ghostcorn |

## Links

- npm: https://www.npmjs.com/package/@harmony-js/utils
- npm.io page: https://npm.io/package/@harmony-js/utils

## Dependencies (2)

- [bn.js](https://npm.io/package/bn.js.md) ^4.11.8
- [@types/bn.js](https://npm.io/package/@types/bn.js.md) ^4.11.3

## Recent versions

- 0.1.56 (latest) — 2020-11-22
- 0.1.58 (next) — 2022-07-06
- 0.1.41-alpha.1 (canary) — 2020-05-04
- 0.1.55 — 2020-09-29
- 0.1.54 — 2020-09-07
- 0.1.48 — 2020-07-13
- 0.1.45 — 2020-06-06
- 0.1.43 — 2020-05-04
- 0.1.35 — 2019-11-27
- 0.1.28 — 2019-10-10
- 0.1.27 — 2019-10-10
- 0.1.23 — 2019-09-24
- 0.1.14 — 2019-09-04
- 0.1.12 — 2019-09-02
- 0.1.6 — 2019-08-05
- … 47 more at https://npm.io/package/@harmony-js/utils/versions

## README

# @harmony-js/utils

This package provides a collection of utility apis for unit conversions like `fromWei`, `toWei`, `hexToNumber`, `numberToHex`, `isAddress`, etc.

## Installation

```
npm install @harmony-js/utils
```

## Usage

Available units
```
const { Units } = require('@harmony-js/utils');

[Units.wei, '1'], // 1 wei
[Units.Kwei, '1000'], // 1e3 wei
[Units.Mwei, '1000000'], // 1e6 wei
[Units.Gwei, '1000000000'], // 1e9 wei
[Units.szabo, '1000000000000'], // 1e12 wei
[Units.finney, '1000000000000000'], // 1e15 wei
[Units.ether, '1000000000000000000'], // 1e18 wei
[Units.one, '1000000000000000000'], // 1e18 wei
[Units.Kether, '1000000000000000000000'], // 1e21 wei
[Units.Mether, '1000000000000000000000000'], // 1e24 wei
[Units.Gether, '1000000000000000000000000000'], // 1e27 wei
[Units.Tether, '1000000000000000000000000000000'], // 1e30 wei
```

Converting between different units
```javascript
const { Units, Unit, numberToString, add0xToString, fromWei, toWei, numToStr} = require('@harmony-js/utils');
const { BN } = require('@harmony-js/crypto');

const one = new Unit('1').asOne();
const oneToGwei = one.toGwei();
console.log(oneToGwei);

// numberToString
const num = 123;
const str = numberToString(num)
console.log(str);

// add0xToString
const str = '12345';
const expected = add0xToString(str)
console.log(expected);

// fromWei
const Wei = new BN('1000000000000000000');
const expected = fromWei(Wei, Units.one);
console.log(expected);

// toWei
const one = new BN('1');
const expected = toWei(one, hmy.utils.Units.one);
const num = numToStr(expected);
console.log(num);
```

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