@kodex-data/prototypes
Version:
A library of TypeScript prototypes that extend built-in types in JavaScript, providing additional functionality to make development easier and more efficient. This library includes prototypes for working with big numbers, Ethereum Virtual Machine (EVM) fu
74 lines (63 loc) • 2.02 kB
Markdown
# @kodex-data/evm-prototypes
The `@kodex-data/evm-prototypes` package provides a set of utility functions and prototypes for working with Ethereum Virtual Machine (EVM) data types such as strings, addresses, and numbers.
## Installation
You can install the package using `yarn` or `npm`:
```bash
yarn add @kodex-data/evm-prototypes
# or
npm install @kodex-data/evm-prototypes
```
## Usage
Once installed, you can import the package in your TypeScript code as follows:
```typescript
import '@kodex-data/evm-prototypes'
```
This will extend the `String` and `Number` prototypes with additional methods, as shown below.
```ts
declare global {
interface String {
strip0x(): string;
isHex(): boolean;
toHex(): string;
fromHex(): string;
toAscii(): string;
isAddress(): boolean;
isEtherAddress(): boolean;
addrIsEqual(address: string): boolean;
toChecksumAddress(): string;
isKeccakHash(): boolean;
trimAddress(): string;
findHex(): string[];
findHex(type: 'address'): string[];
findHex(type: 'keccak'): string[];
toSha3(): string;
toUtf8Bytes(): Uint8Array;
isNumber(): boolean;
toUint(add0x?: boolean): string;
isValidJSON(): boolean;
isTwitterUrl(): boolean;
getTwitterUsername(): string | undefined;
rndHex(l?: number): string;
}
interface Number {
toUint(add0x?: boolean): string;
toHex(): string;
isOdd(): boolean;
}
}
declare global {
interface String {
toBN(base?: number): BigNumber;
shiftedBy(n: number): string;
shiftedBy(n: number, asBN: undefined | false | null): string;
shiftedBy(n: number, asBN: true): BigNumber;
}
interface Number {
toBN(): BigNumber;
toUint(add0x?: boolean): string;
shiftedBy(n: number): string;
shiftedBy(n: number, asBN: boolean): BigNumber;
noExponents(): string;
}
}
```