2.2.1 • Published 2 months ago

@1inch/byte-utils v2.2.1

Weekly downloads
-
License
MIT
Repository
github
Last release
2 months ago

@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

FunctionType
isHexString(val: string) => boolean

:gear: isHexBytes

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

FunctionType
isHexBytes(val: string) => boolean

:wrench: Constants

:gear: UINT_8_MAX

ConstantType
UINT_8_MAXbigint

:gear: UINT_24_MAX

ConstantType
UINT_24_MAXbigint

:gear: UINT_32_MAX

ConstantType
UINT_32_MAXbigint

:gear: UINT_40_MAX

ConstantType
UINT_40_MAXbigint

:gear: UINT_80_MAX

ConstantType
UINT_80_MAXbigint

:gear: UINT_160_MAX

ConstantType
UINT_160_MAXbigint

:gear: UINT_256_MAX

ConstantType
UINT_256_MAXbigint

:factory: BitMask

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

Methods

:gear: toString

MethodType
toString() => string

:gear: toBigInt

MethodType
toBigInt() => bigint

:factory: BN

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

Methods

:gear: fromNumber

MethodType
fromNumber(n: number) => BN

:gear: fromHex

MethodType
fromHex(hex: string) => BN

:gear: add

Add value

MethodType
add(other: BN) => BN

:gear: sub

Subtract value

MethodType
sub(other: BN) => BN

:gear: setBit

MethodType
setBit(n: bigint, value: 0 or 1) => BN

:gear: getBit

MethodType
getBit(n: bigint) => 0 or 1

:gear: shiftLeft

MethodType
shiftLeft(n: bigint) => BN

:gear: shiftRight

MethodType
shiftRight(n: bigint) => BN

:gear: and

MethodType
and(other: bigint or BN) => BN

:gear: or

MethodType
or(other: bigint or BN) => BN

:gear: xor

MethodType
xor(other: bigint or BN) => BN

:gear: isZero

MethodType
isZero() => boolean

:gear: isOne

MethodType
isOne() => boolean

:gear: getMask

Return bits defined in mask as BN

MethodType
getMask(mask: BitMask) => BN

:gear: setMask

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

MethodType
setMask(mask: BitMask, value: bigint or BN) => BN

:gear: clearMask

Set bits defined in mask to 0s

MethodType
clearMask(mask: BitMask) => BN

:gear: toHex

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

MethodType
toHex(padNum?: number) => string

:gear: toNumber

Convert BN to Number

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

MethodType
toNumber() => number

:factory: BytesIter

Class to iterate through bytes string by parsing individual bytes

Methods

:gear: BigInt

MethodType
BigInt(bytes: string) => BytesIter<bigint>

:gear: String

MethodType
String(bytes: string) => BytesIter<string>

:gear: rest

Returns all not consumed bytes

MethodType
rest() => T

:gear: isEmpty

MethodType
isEmpty() => boolean

:gear: nextByte

MethodType
nextByte() => T

:gear: nextBytes

MethodType
nextBytes(n: number) => T

:gear: nextUint8

MethodType
nextUint8() => T

:gear: nextUint16

MethodType
nextUint16() => T

:gear: nextUint24

MethodType
nextUint24() => T

:gear: nextUint32

MethodType
nextUint32() => T

:gear: nextUint128

MethodType
nextUint128() => T

:gear: nextUint160

MethodType
nextUint160() => T

:gear: nextUint256

MethodType
nextUint256() => T

:factory: BytesBuilder

Helper class to build an arbitrary bytes sequence

Methods

:gear: addAddress

MethodType
addAddress(address: string or BN) => this

:gear: addBytes

MethodType
addBytes(bytes: string) => this

:gear: addByte

MethodType
addByte(byte: string or BN) => this

:gear: addUint8

MethodType
addUint8(val: string or BN) => this

:gear: addUint16

MethodType
addUint16(val: string or BN) => this

:gear: addUint24

MethodType
addUint24(val: string or BN) => this

:gear: addUint32

MethodType
addUint32(val: string or BN) => this

:gear: addUint64

MethodType
addUint64(val: string or BN) => this

:gear: addUint128

MethodType
addUint128(val: string or BN) => this

:gear: addUint160

MethodType
addUint160(val: string or BN) => this

:gear: addUint256

MethodType
addUint256(val: string or BN) => this

:gear: asBigInt

Returns bytes as single bigint value

MethodType
asBigInt() => bigint

:gear: asHex

Returns hex string

MethodType
asHex(prefixed?: boolean) => string

Parameters:

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

2 months ago

2.2.0

3 months ago

2.1.0

3 months ago

2.0.0

3 months ago

1.0.1

3 months ago

1.0.0

3 months ago

0.0.9

3 months ago

0.0.8

3 months ago

0.0.7

3 months ago