#
@latticexyz/utils
#
Classes
#
Interfaces
#
Type Aliases
#
Area
Ƭ Area: Object
#
Type declaration
#
Defined in
packages/utils/src/types.ts:30
#
AsyncFunc
Ƭ AsyncFunc<A
, R
>: R
extends Promise
<unknown
> ? (...args
: A
) => R
: (...args
: A
) => Promise
<R
>
#
Type parameters
#
Defined in
#
Cached
Ƭ Cached<C
>: { proxied
: false
} & { [key in keyof C]: CachedValue<C[key], false> } | { proxied
: true
} & { [key in keyof C]: CachedValue<C[key], true> }
#
Type parameters
#
Defined in
packages/utils/src/types.ts:19
#
CachedValue
Ƭ CachedValue<V
, Proxied
>: Proxied
extends true
? V
extends Func
AsyncFunc
A
, B
> : V
extends Record
<string
, any
> ? Cached
V
> & { proxied
: true
} : { proxied
: true
} : V
extends Func
Func
A
, B
> : V
extends Record
<string
, any
> ? V
: V
& { proxied
: false
}
#
Type parameters
#
Defined in
#
Coord
Ƭ Coord: Object
#
Type declaration
#
Defined in
packages/utils/src/types.ts:37
#
Func
Ƭ Func<A
, R
>: (...args
: A
) => R
#
Type parameters
#
Type declaration
▸ (...args
): R
#
Parameters
#
Returns
R
#
Defined in
#
Logger
Ƭ Logger: ReturnType
<typeof enableLogger
#
Defined in
packages/utils/src/types.ts:48
#
PromiseValue
Ƭ PromiseValue<T
>: Awaited
<T
>
Deprecated
Use Awaited
#
Type parameters
#
Defined in
packages/utils/src/types.ts:26
#
ValueOf
Ƭ ValueOf<T
>: T
[keyof T
]
#
Type parameters
#
Defined in
packages/utils/src/types.ts:28
#
VoxelCoord
Ƭ VoxelCoord: Object
#
Type declaration
#
Defined in
packages/utils/src/types.ts:42
#
Functions
#
Int32ArrayToUint8Array
▸ Int32ArrayToUint8Array(input
): Uint8Array
#
Parameters
#
Returns
Uint8Array
#
Defined in
packages/utils/src/bytes.ts:41
#
Uint8ArrayToHexString
▸ Uint8ArrayToHexString(data
): string
#
Parameters
#
Returns
string
#
Defined in
packages/utils/src/bytes.ts:14
#
Uint8ArrayToInt32Array
▸ Uint8ArrayToInt32Array(input
): number
[]
#
Parameters
#
Returns
number
[]
#
Defined in
packages/utils/src/bytes.ts:50
#
areaContains
▸ areaContains(area
, coord
): boolean
#
Parameters
#
Returns
boolean
#
Defined in
#
arrayToHex
▸ arrayToHex(array
): `0x$`
#
Parameters
#
Returns
`0x$`
#
Defined in
packages/utils/src/v2/arrayToHex.ts:2
#
arrayToIterator
▸ arrayToIterator<T
>(array
): IterableIterator
<T
>
Turns an array into an iterator. NOTE: an iterator can only be iterated once.
#
Type parameters
#
Parameters
#
Returns
IterableIterator
<T
>
Iterator to iterate through the array
#
Defined in
packages/utils/src/iterable.ts:49
#
awaitPromise
▸ awaitPromise<T
>(): OperatorFunction
<T
, Awaited
<T
>>
#
Type parameters
#
Returns
OperatorFunction
<T
, Awaited
<T
>>
#
Defined in
#
awaitStreamValue
▸ awaitStreamValue<T
>(stream$
, predicate?
): Promise
<T
>
#
Type parameters
#
Parameters
#
Returns
Promise
<T
>
A promise that resolves with the requested value once the predicate is true
#
Defined in
#
awaitValue
▸ awaitValue<T
>(comp
): Promise
<T
>
#
Type parameters
#
Parameters
#
Returns
Promise
<T
>
promise that resolves with the first truthy computed value
#
Defined in
#
bytesToString
▸ bytesToString(bytes
): string
#
Parameters
#
Returns
string
#
Defined in
packages/utils/src/v2/bytesToString.ts:1
#
cacheUntilReady
▸ cacheUntilReady<T
>(target
): Cached
T
>
Caches any function calls to the target until the target is ready.
#
Type parameters
#
Parameters
#
Returns
Cached
T
>
Cached
#
Defined in
packages/utils/src/proxy.ts:22
#
callWithRetry
▸ callWithRetry<T
>(fn
, args?
, maxRetries?
, retryInterval?
): Promise
<T
>
#
Type parameters
#
Parameters
#
Returns
Promise
<T
>
#
Defined in
packages/utils/src/promise.ts:19
#
computedToStream
▸ computedToStream<T
>(comp
): Observable
<T
>
#
Type parameters
#
Parameters
#
Returns
Observable
<T
>
#
Defined in
#
concatIterators
▸ concatIterators<T
>(first
, second?
): IterableIterator
<T
>
#
Type parameters
#
Parameters
#
Returns
IterableIterator
<T
>
#
Defined in
packages/utils/src/iterable.ts:12
#
concatUint8Arrays
▸ concatUint8Arrays(...arrays
): Uint8Array
#
Parameters
#
Returns
Uint8Array
#
Defined in
packages/utils/src/bytes.ts:19
#
coordToKey
▸ coordToKey(coord
): number
#
Parameters
#
Returns
number
#
Defined in
packages/utils/src/CoordMap.ts:18
#
coordsOf
▸ coordsOf(area
): Coord
#
Parameters
#
Returns
Coord
#
Defined in
#
createToInt
▸ createToInt(size
): (value
: number
) => number
#
Parameters
#
Returns
fn
▸ (value
): number
#
Parameters
#
Returns
number
#
Defined in
packages/utils/src/bytes.ts:59
#
cubicNoiseConfig
▸ cubicNoiseConfig(seed
, octave
, scale
, periodX?
, periodY?
): Object
Config a cubic noise.
#
Parameters
#
Returns
Object
A configuration object used by noise functions.
#
Defined in
packages/utils/src/cubic.ts:28
#
cubicNoiseSample1
▸ cubicNoiseSample1(config
, x
): number
Sample 1D cubic noise.
#
Parameters
#
Returns
number
A noise value in the range [0, 1].
#
Defined in
packages/utils/src/cubic.ts:50
#
cubicNoiseSample2
▸ cubicNoiseSample2(config
, x
, y
): number
Sample 2D cubic noise.
#
Parameters
#
Returns
number
A noise value in the range [0, 1].
#
Defined in
packages/utils/src/cubic.ts:76
#
deferred
▸ deferred<T
>(): [(t
: T
) => void
, (t
: Error
) => void
, Promise
<T
>]
A convenient way to create a promise with resolve and reject functions.
#
Type parameters
#
Returns
[(t
: T
) => void
, (t
: Error
) => void
, Promise
<T
>]
Tuple with resolve function, reject function and promise.
#
Defined in
packages/utils/src/deferred.ts:5
#
enableLogger
▸ enableLogger(): Object
#
Returns
Object
#
Defined in
packages/utils/src/console.ts:3
#
ethAddressToUint8Array
▸ ethAddressToUint8Array(address
): Uint8Array
#
Parameters
#
Returns
Uint8Array
#
Defined in
packages/utils/src/bytes.ts:54
#
euclidean
▸ euclidean(a
, b
): number
Compute the Euclidean distance between two points https://en.wikipedia.org/wiki/Euclidean_distance
#
Parameters
#
Returns
number
Euclidian distance between a and b
#
Defined in
packages/utils/src/distance.ts:8
#
extractEncodedArguments
▸ extractEncodedArguments(input
): string
#
Parameters
#
Returns
string
#
Defined in
#
filterNullish
▸ filterNullish<T
>(): OperatorFunction
<T
, NonNullable
<T
>>
#
Type parameters
#
Returns
OperatorFunction
<T
, NonNullable
<T
>>
#
Defined in
#
filterNullishValues
▸ filterNullishValues<T
>(array
): T
[]
Filters undefined values from an array and lets TypeScript know the resulting array does not have undefined values
#
Type parameters
#
Parameters
#
Returns
T
[]
Array without undefined values
#
Defined in
packages/utils/src/arrays.ts:17
#
formatHex
▸ formatHex(hex
): string
#
Parameters
#
Returns
string
#
Defined in
#
fromWorker
▸ fromWorker<I
, O
>(worker
, input$
): Observable
<O
>
#
Type parameters
#
Parameters
#
Returns
Observable
<O
>
#
Defined in
packages/utils/src/worker.ts:7
#
hexStringToUint8Array
▸ hexStringToUint8Array(hexString
): Uint8Array
#
Parameters
#
Returns
Uint8Array
#
Defined in
packages/utils/src/bytes.ts:10
#
hexToArray
▸ hexToArray(hex
): Uint8Array
#
Parameters
#
Returns
Uint8Array
#
Defined in
packages/utils/src/v2/hexToArray.ts:4
#
interpolate
▸ interpolate(a
, b
, c
, d
, x
, s
, scale
): number
#
Parameters
#
Returns
number
#
Defined in
packages/utils/src/cubic.ts:14
#
isDefined
▸ isDefined<T
>(argument
): argument is T
#
Type parameters
#
Parameters
#
Returns
argument is T
#
Defined in
packages/utils/src/v2/isDefined.ts:1
#
isFunction
▸ isFunction(c
): c is Func<any, any>
#
Parameters
#
Returns
c is Func<any, any>
#
Defined in
packages/utils/src/guards.ts:8
#
isHex
▸ isHex(hex
): boolean
#
Parameters
#
Returns
boolean
#
Defined in
packages/utils/src/v2/isHex.ts:4
#
isNotEmpty
▸ isNotEmpty<T
>(array
): array is [T, ...T[]]
TypeScript type guard to assert the type of a non-empty array
#
Type parameters
#
Parameters
#
Returns
array is [T, ...T[]]
True if the empty is non-empty, else false. TypeScript accepts the array as non-empty after the assertion.
#
Defined in
packages/utils/src/arrays.ts:6
#
isObject
▸ isObject(c
): c is Record<string, any>
#
Parameters
#
Returns
c is Record<string, any>
#
Defined in
packages/utils/src/guards.ts:4
#
keccak256
▸ keccak256(data
): string
Compute keccak256 hash from given string and remove padding from the resulting hex string
#
Parameters
#
Returns
string
Hash of the given string as hex string without padding
#
Defined in
#
keccak256Coord
▸ keccak256Coord(coord
): string
#
Parameters
#
Returns
string
#
Defined in
#
keyToCoord
▸ keyToCoord(key
): Coord
#
Parameters
#
Returns
Coord
#
Defined in
packages/utils/src/CoordMap.ts:26
#
makeIterable
▸ makeIterable<T
>(iterator
): IterableIterator
<T
>
#
Type parameters
#
Parameters
#
Returns
IterableIterator
<T
>
#
Defined in
packages/utils/src/iterable.ts:1
#
mapObject
▸ mapObject<S
, T
>(source
, valueMap
): T
Utility function to map a source object to an object with the same keys but mapped values
#
Type parameters
#
Parameters
#
Returns
T
An object with the same keys as the source object but mapped values
#
Defined in
packages/utils/src/objects.ts:7
#
mergeIterators
▸ mergeIterators<A
, B
>(iteratorA
, iteratorB
): IterableIterator
<[A
, B
]>
#
Type parameters
#
Parameters
#
Returns
IterableIterator
<[A
, B
]>
#
Defined in
packages/utils/src/iterable.ts:23
#
numValues
▸ numValues(enm
): number
[]
#
Parameters
#
Returns
number
[]
Number array containing the enum values
#
Defined in
#
observableToComputed
▸ observableToComputed<T
>(obs
): IComputedValue
<T
>
#
Type parameters
#
Parameters
#
Returns
IComputedValue
<T
>
#
Defined in
#
observableToStream
▸ observableToStream<T
>(obs
): Observable
<T
>
#
Type parameters
#
Parameters
#
Returns
Observable
<T
>
#
Defined in
#
pack
▸ pack(numbers
, bitsPerNumber
): number
Packs two unsigned integers in one 32 bit unsigned integer
#
Parameters
#
Returns
number
Packed 32 bit unsigned integer
#
Defined in
#
packTuple
▸ packTuple(numbers
): number
#
Parameters
#
Returns
number
#
Defined in
#
padToBitLength
▸ padToBitLength(input
, bits
): string
Pads start of a hex string with 0 to create a bit string of the given length
#
Parameters
#
Returns
string
Hex string of specified length
#
Defined in
#
pickRandom
▸ pickRandom<T
>(array
): T
#
Type parameters
#
Parameters
#
Returns
T
Random element from the given array.
#
Defined in
packages/utils/src/random.ts:15
#
random
▸ random(to
, from?
): number
#
Parameters
#
Returns
number
A random integer between from and to.
#
Defined in
packages/utils/src/random.ts:7
#
randomize
▸ randomize(seed
, x
, y
): number
#
Parameters
#
Returns
number
#
Defined in
#
range
▸ range(total?
, step?
, from?
): Generator
<number
, void
, unknown
>
#
Parameters
#
Returns
Generator
<number
, void
, unknown
>
#
Defined in
packages/utils/src/promise.ts:5
#
rejectAfter
▸ rejectAfter<T
>(ms
, msg
): Promise
<T
>
#
Type parameters
#
Parameters
#
Returns
Promise
<T
>
#
Defined in
packages/utils/src/promise.ts:10
#
roundTowardsZero
▸ roundTowardsZero(x
): number
For positive inputs: returns the greatest integer less than or equal to its numeric argument. For negative inputs: returns the smallest integer greater than or equal to its numeric argument.
#
Parameters
#
Returns
number
Input rounded towards zero.
#
Defined in
#
runWorker
▸ runWorker<I
, O
>(worker
): void
#
Type parameters
#
Parameters
#
Returns
void
#
Defined in
packages/utils/src/worker.ts:12
#
sleep
▸ sleep<T
>(timeout
, returns?
): Promise
<T
>
#
Type parameters
#
Parameters
#
Returns
Promise
<T
>
#
Defined in
#
splitUint8Arrays
▸ splitUint8Arrays(data
, byteLengths
): Uint8Array
[]
#
Parameters
#
Returns
Uint8Array
[]
#
Defined in
packages/utils/src/bytes.ts:27
#
streamToComputed
▸ streamToComputed<T
>(stream$
): IComputedValue
<T
| undefined
>
#
Type parameters
#
Parameters
#
Returns
IComputedValue
<T
| undefined
>
#
Defined in
#
streamToDefinedComputed
▸ streamToDefinedComputed<T
>(stream$
): Promise
<IComputedValue
<T
>>
#
Type parameters
#
Parameters
#
Returns
Promise
<IComputedValue
<T
>>
#
Defined in
#
streamToWrappedValue
▸ streamToWrappedValue<T
>(stream$
): Promise
<{ current
: T
}>
Turns a stream into an updating object for easy access outside of rxjs
#
Type parameters
#
Parameters
#
Returns
Promise
<{ current
: T
}>
Object with current
key corresponding to last stream value
#
Defined in
#
stretch
▸ stretch<T
>(spacingDelayMs
): UnaryFunction
<Observable
<T
>, Observable
<T
>>
RxJS operator to stretch out an event stream by a given delay per event
#
Type parameters
#
Parameters
#
Returns
UnaryFunction
<Observable
<T
>, Observable
<T
>>
stream of events with at least spacingDelayMs spaceing between event
#
Defined in
#
stringToBytes16
▸ stringToBytes16(str
): Uint8Array
#
Parameters
#
Returns
Uint8Array
#
Defined in
packages/utils/src/v2/stringToBytes16.ts:1
#
subtract
▸ subtract(from
, subtract
): CoordMap
<boolean
>
#
Parameters
#
Returns
CoordMap
<boolean
>
#
Defined in
packages/utils/src/CoordMap.ts:7
#
tile
▸ tile(coordinate
, period
): number
#
Parameters
#
Returns
number
#
Defined in
#
timeoutAfter
▸ timeoutAfter<T
>(promise
, ms
, timeoutMsg
): Promise
<T
>
#
Type parameters
#
Parameters
#
Returns
Promise
<T
>
#
Defined in
packages/utils/src/promise.ts:15
#
to256BitString
▸ to256BitString(input
): string
Pads start of a hex string with 0 to create a 256bit hex string which can be used as an Ethereum address
#
Parameters
#
Returns
string
256 bit hex string
#
Defined in
#
toEthAddress
▸ toEthAddress(input
): string
Pads start of a hex string with 0 to create a 160 bit hex string which can be used as an Ethereum address
#
Parameters
#
Returns
string
160 bit hex string
#
Defined in
#
toInt32
▸ toInt32(value
): number
#
Parameters
#
Returns
number
#
Defined in
packages/utils/src/bytes.ts:70
#
transformIterator
▸ transformIterator<A
, B
>(iterator
, transform
): IterableIterator
<B
>
#
Type parameters
#
Parameters
#
Returns
IterableIterator
<B
>
#
Defined in
packages/utils/src/iterable.ts:35
#
unpack
▸ unpack(packed
, bitsPerNumber
): number
[]
Unpacks a packed 32 bit unsigned integer into the original unsigned integers
#
Parameters
#
Returns
number
[]
Array of unpacked unsignd integers
#
Defined in
#
unpackTuple
▸ unpackTuple(packed
): [number
, number
]
#
Parameters
#
Returns
[number
, number
]
#
Defined in
#
uuid
▸ uuid(): string
Generates a version 4 UUID as a hexadecimal string.
#
Returns
string
Hexadecimal UUID string.