@erfffun/utils
Version:
Energi javascript utilities for web development
84 lines (58 loc) • 1.4 kB
Markdown
Javascript utilities for web development
**Description**: Convert number digit to wei Value
**Usage**
```js
amountToWei(<amount as string>, <decimal>)
```
**Example**
```js
amountToWei('1.01', 18);
```
**Description**: With this method, you can easily implement a copy to clip board feature
**Usage**
```js
const result = copyToClipboard(<text>)
```
**Response**: Returns either a true/false depending on the status of the operation
**Example**
```js
const result = copyToClipboard('Some text!');
if (result) {
console.log('Copied to clipboard');
} else {
throw new Error('Error: could not copy to clipboard');
}
```
**Description**: Detect if user is on a mobile device
**Example**
```js
import { isMobile } from '@energi/utils';
if (isMobile) {
console.log('You are using a mobile device');
}
```
**Description**: Module formats energi bignumber amounts (wei) into NRG amount, with decimal and thousands separator, internationalized
**Usage**
```js
formatBN(toBN(bnStringRoundUp), {
locale,
decimals: 18, // force the format to have specific number of decimals
assetDigits: 18,
});
```
**Example**
```js
import { formatBN } from '@energi/utils';
const locale = 'en-US';
formatBN(toBN(bnStringRoundUp), {
locale,
decimals: 2,
assetDigits: 18,
});
```