npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@1inch/byte-utils

v2.6.0

Published

Contains helpers to work with bytes

Downloads

3,594

Readme

@1inch/byte-utils

Contains helpers to work with bytes

Installation

npm install @1inch/byte-utils

Docs

:toolbox: Functions

:gear: isHexString

Check that string starts with 0x and has only valid hex symbols

| Function | Type | | ---------- | ---------- | | isHexString | (val: string) => boolean |

:gear: isHexBytes

Check that string is valid hex with 0x prefix and length is even

| Function | Type | | ---------- | ---------- | | isHexBytes | (val: string) => boolean |

:wrench: Constants

:gear: UINT_8_MAX

| Constant | Type | | ---------- | ---------- | | UINT_8_MAX | bigint |

:gear: UINT_24_MAX

| Constant | Type | | ---------- | ---------- | | UINT_24_MAX | bigint |

:gear: UINT_32_MAX

| Constant | Type | | ---------- | ---------- | | UINT_32_MAX | bigint |

:gear: UINT_40_MAX

| Constant | Type | | ---------- | ---------- | | UINT_40_MAX | bigint |

:gear: UINT_48_MAX

| Constant | Type | | ---------- | ---------- | | UINT_48_MAX | bigint |

:gear: UINT_80_MAX

| Constant | Type | | ---------- | ---------- | | UINT_80_MAX | bigint |

:gear: UINT_160_MAX

| Constant | Type | | ---------- | ---------- | | UINT_160_MAX | bigint |

:gear: UINT_128_MAX

| Constant | Type | | ---------- | ---------- | | UINT_128_MAX | bigint |

:gear: UINT_256_MAX

| Constant | Type | | ---------- | ---------- | | UINT_256_MAX | bigint |

:factory: BitMask

Class to define bit mask: new BitMask(16, 32) is for bits from [16, 32) => 0xffff0000

Methods

:gear: toString

| Method | Type | | ---------- | ---------- | | toString | () => string |

:gear: toBigInt

| Method | Type | | ---------- | ---------- | | toBigInt | () => bigint |

:factory: BN

Class to work with bits in bignumber Immutable, all methods return new value

Methods

:gear: fromNumber

| Method | Type | | ---------- | ---------- | | fromNumber | (n: number) => BN |

:gear: fromHex

| Method | Type | | ---------- | ---------- | | fromHex | (hex: string) => BN |

:gear: add

Add value

| Method | Type | | ---------- | ---------- | | add | (other: BN) => BN |

:gear: sub

Subtract value

| Method | Type | | ---------- | ---------- | | sub | (other: BN) => BN |

:gear: setBit

| Method | Type | | ---------- | ---------- | | setBit | (n: bigint, value: 0 or 1) => BN |

:gear: getBit

| Method | Type | | ---------- | ---------- | | getBit | (n: bigint) => 0 or 1 |

:gear: shiftLeft

| Method | Type | | ---------- | ---------- | | shiftLeft | (n: bigint) => BN |

:gear: shiftRight

| Method | Type | | ---------- | ---------- | | shiftRight | (n: bigint) => BN |

:gear: and

| Method | Type | | ---------- | ---------- | | and | (other: bigint or BN) => BN |

:gear: or

| Method | Type | | ---------- | ---------- | | or | (other: bigint or BN) => BN |

:gear: xor

| Method | Type | | ---------- | ---------- | | xor | (other: bigint or BN) => BN |

:gear: isZero

| Method | Type | | ---------- | ---------- | | isZero | () => boolean |

:gear: isOne

| Method | Type | | ---------- | ---------- | | isOne | () => boolean |

:gear: getMask

Return bits defined in mask as BN

| Method | Type | | ---------- | ---------- | | getMask | (mask: BitMask) => BN |

:gear: setMask

Set bits defined in mask to value if value is bigger than mask then error will be thrown

| Method | Type | | ---------- | ---------- | | setMask | (mask: BitMask, value: bigint or BN) => BN |

:gear: clearMask

Set bits defined in mask to 0s

| Method | Type | | ---------- | ---------- | | clearMask | (mask: BitMask) => BN |

:gear: toHex

Return 0x prefixed string with hex representation of BN, padded with '0s' if padNum specified

| Method | Type | | ---------- | ---------- | | toHex | (padNum?: number) => string |

:gear: toNumber

Convert BN to Number

Caution: value will be rounded for numbers > Number.MAX_SAFE_INTEGER

| Method | Type | | ---------- | ---------- | | toNumber | () => number |

:factory: BytesIter

Class to iterate through bytes string by parsing individual bytes

Methods

:gear: BigInt

| Method | Type | | ---------- | ---------- | | BigInt | (bytes: string) => BytesIter<bigint> |

:gear: String

| Method | Type | | ---------- | ---------- | | String | (bytes: string) => BytesIter<string> |

:gear: rest

Returns all not consumed bytes

| Method | Type | | ---------- | ---------- | | rest | () => T |

:gear: isEmpty

| Method | Type | | ---------- | ---------- | | isEmpty | () => boolean |

:gear: nextByte

| Method | Type | | ---------- | ---------- | | nextByte | (side?: Side) => T |

:gear: nextBytes

| Method | Type | | ---------- | ---------- | | nextBytes | (n: number, side?: Side) => T |

:gear: nextAddress

| Method | Type | | ---------- | ---------- | | nextAddress | (side?: Side) => T |

:gear: nextUint8

| Method | Type | | ---------- | ---------- | | nextUint8 | (side?: Side) => T |

:gear: nextUint16

| Method | Type | | ---------- | ---------- | | nextUint16 | (side?: Side) => T |

:gear: nextUint24

| Method | Type | | ---------- | ---------- | | nextUint24 | (side?: Side) => T |

:gear: nextUint32

| Method | Type | | ---------- | ---------- | | nextUint32 | (side?: Side) => T |

:gear: nextUint128

| Method | Type | | ---------- | ---------- | | nextUint128 | (side?: Side) => T |

:gear: nextUint160

| Method | Type | | ---------- | ---------- | | nextUint160 | (side?: Side) => T |

:gear: nextUint256

| Method | Type | | ---------- | ---------- | | nextUint256 | (side?: Side) => T |

:factory: BytesBuilder

Helper class to build an arbitrary bytes sequence

Methods

:gear: addAddress

| Method | Type | | ---------- | ---------- | | addAddress | (address: string or bigint or BN) => this |

:gear: addBytes

| Method | Type | | ---------- | ---------- | | addBytes | (bytes: string) => this |

:gear: addByte

| Method | Type | | ---------- | ---------- | | addByte | (byte: string or bigint or BN) => this |

:gear: addUint8

| Method | Type | | ---------- | ---------- | | addUint8 | (val: string or bigint or BN) => this |

:gear: addUint16

| Method | Type | | ---------- | ---------- | | addUint16 | (val: string or bigint or BN) => this |

:gear: addUint24

| Method | Type | | ---------- | ---------- | | addUint24 | (val: string or bigint or BN) => this |

:gear: addUint32

| Method | Type | | ---------- | ---------- | | addUint32 | (val: string or bigint or BN) => this |

:gear: addUint64

| Method | Type | | ---------- | ---------- | | addUint64 | (val: string or bigint or BN) => this |

:gear: addUint128

| Method | Type | | ---------- | ---------- | | addUint128 | (val: string or bigint or BN) => this |

:gear: addUint160

| Method | Type | | ---------- | ---------- | | addUint160 | (val: string or bigint or BN) => this |

:gear: addUint256

| Method | Type | | ---------- | ---------- | | addUint256 | (val: string or bigint or BN) => this |

:gear: asBigInt

Returns bytes as single bigint value

| Method | Type | | ---------- | ---------- | | asBigInt | () => bigint |

:gear: asHex

Returns hex string

| Method | Type | | ---------- | ---------- | | asHex | (prefixed?: boolean) => string |

Parameters:

  • prefixed: should be string prefixed with 0x or not, true by default