@latticexyz/utils 0.10.0 → 0.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +14 -0
- package/dist/CoordMap.d.ts +26 -0
- package/dist/area.d.ts +3 -0
- package/{src/arrays.ts → dist/arrays.d.ts} +2 -8
- package/dist/console.d.ts +52 -0
- package/dist/cubic.d.ts +32 -0
- package/dist/deferred.d.ts +5 -0
- package/{src/distance.ts → dist/distance.d.ts} +1 -3
- package/dist/enums.d.ts +5 -0
- package/dist/eth.d.ts +22 -0
- package/dist/guards.d.ts +3 -0
- package/dist/hash.d.ts +6 -0
- package/{src/index.ts → dist/index.d.ts} +1 -13
- package/dist/index.js +802 -0
- package/dist/index.js.map +1 -0
- package/dist/iterable.d.ts +10 -0
- package/{src/math.ts → dist/math.d.ts} +1 -4
- package/dist/mobx.d.ts +6 -0
- package/dist/objects.d.ts +11 -0
- package/dist/pack.d.ts +16 -0
- package/dist/promise.d.ts +4 -0
- package/dist/proxy.d.ts +8 -0
- package/{src/random.ts → dist/random.d.ts} +2 -7
- package/dist/rx.d.ts +30 -0
- package/dist/sleep.d.ts +1 -0
- package/dist/types.d.ts +40 -0
- package/dist/uuid.d.ts +19 -0
- package/dist/worker.d.ts +6 -0
- package/package.json +9 -5
- package/jest.config.js +0 -5
- package/rollup.config.js +0 -16
- package/src/CoordMap.spec.ts +0 -57
- package/src/CoordMap.ts +0 -106
- package/src/area.ts +0 -15
- package/src/console.ts +0 -62
- package/src/cubic.spec.ts +0 -14
- package/src/cubic.ts +0 -109
- package/src/deferred.ts +0 -14
- package/src/enums.ts +0 -13
- package/src/eth.ts +0 -42
- package/src/guards.ts +0 -10
- package/src/hash.ts +0 -11
- package/src/iterable.spec.ts +0 -56
- package/src/iterable.ts +0 -59
- package/src/mobx.ts +0 -26
- package/src/objects.ts +0 -16
- package/src/pack.spec.ts +0 -37
- package/src/pack.ts +0 -61
- package/src/promise.ts +0 -45
- package/src/proxy.spec.ts +0 -186
- package/src/proxy.ts +0 -101
- package/src/rx.spec.ts +0 -45
- package/src/rx.ts +0 -124
- package/src/sleep.ts +0 -3
- package/src/types.ts +0 -48
- package/src/uuid.ts +0 -70
- package/src/worker.ts +0 -16
- package/tsconfig.json +0 -102
- package/typedoc.json +0 -9
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,20 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
# [0.12.0](https://github.com/latticexyz/mud/compare/v0.11.1...v0.12.0) (2022-09-16)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @latticexyz/utils
|
|
9
|
+
|
|
10
|
+
## [0.11.1](https://github.com/latticexyz/mud/compare/v0.11.0...v0.11.1) (2022-09-15)
|
|
11
|
+
|
|
12
|
+
### Bug Fixes
|
|
13
|
+
|
|
14
|
+
- do not run prepack multiple times when publishing ([4f6f4c3](https://github.com/latticexyz/mud/commit/4f6f4c35a53c105951b32a071e47a748b2502cda))
|
|
15
|
+
|
|
16
|
+
# [0.11.0](https://github.com/latticexyz/mud/compare/v0.10.0...v0.11.0) (2022-09-15)
|
|
17
|
+
|
|
18
|
+
**Note:** Version bump only for package @latticexyz/utils
|
|
19
|
+
|
|
6
20
|
# [0.10.0](https://github.com/latticexyz/mud/compare/v0.9.0...v0.10.0) (2022-09-14)
|
|
7
21
|
|
|
8
22
|
### Features
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { Coord } from "./types";
|
|
2
|
+
export declare function subtract(from: CoordMap<boolean>, subtract: CoordMap<boolean>): CoordMap<boolean>;
|
|
3
|
+
export declare function coordToKey(coord: Coord): number;
|
|
4
|
+
export declare function keyToCoord(key: number): Coord;
|
|
5
|
+
export declare class CoordMap<T> {
|
|
6
|
+
map: Map<number, T>;
|
|
7
|
+
defaultValue?: T;
|
|
8
|
+
constructor(props?: {
|
|
9
|
+
defaultValue?: T;
|
|
10
|
+
});
|
|
11
|
+
static from<T>(coordMapLike: {
|
|
12
|
+
map: Map<number, T>;
|
|
13
|
+
defaultValue?: T;
|
|
14
|
+
}): CoordMap<T>;
|
|
15
|
+
set(coord: Coord, value: T): Map<number, T>;
|
|
16
|
+
get(coord: Coord): T | undefined;
|
|
17
|
+
keys(): IterableIterator<number>;
|
|
18
|
+
coords(): IterableIterator<Coord>;
|
|
19
|
+
entries(): IterableIterator<[number, T]>;
|
|
20
|
+
toArray(): [Coord, T][];
|
|
21
|
+
values(): IterableIterator<T>;
|
|
22
|
+
delete(coord: Coord): boolean;
|
|
23
|
+
has(coord: Coord): boolean;
|
|
24
|
+
clear(): void;
|
|
25
|
+
get size(): number;
|
|
26
|
+
}
|
package/dist/area.d.ts
ADDED
|
@@ -3,17 +3,11 @@
|
|
|
3
3
|
* @param array Any array to check for non-emptiness
|
|
4
4
|
* @returns True if the empty is non-empty, else false. TypeScript accepts the array as non-empty after the assertion.
|
|
5
5
|
*/
|
|
6
|
-
export function isNotEmpty<T>(array: T[]): array is [T, ...T[]]
|
|
7
|
-
if (array.length === 0) return false;
|
|
8
|
-
return true;
|
|
9
|
-
}
|
|
10
|
-
|
|
6
|
+
export declare function isNotEmpty<T>(array: T[]): array is [T, ...T[]];
|
|
11
7
|
/**
|
|
12
8
|
* Filters undefined values from an array and lets TypeScript know the resulting array
|
|
13
9
|
* does not have undefined values
|
|
14
10
|
* @param array Array potentially including undefined values
|
|
15
11
|
* @returns Array without undefined values
|
|
16
12
|
*/
|
|
17
|
-
export function filterNullishValues<T>(array: (T | undefined)[]): T[]
|
|
18
|
-
return array.filter((value) => value != null) as T[];
|
|
19
|
-
}
|
|
13
|
+
export declare function filterNullishValues<T>(array: (T | undefined)[]): T[];
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
/// <reference types="node" />
|
|
3
|
+
export declare function enableLogger(): {
|
|
4
|
+
log: (...logs: string[]) => void;
|
|
5
|
+
logWithTopic: (topic: string, ...logs: string[]) => void;
|
|
6
|
+
enableFilters: () => void;
|
|
7
|
+
disableFilters: () => void;
|
|
8
|
+
addTopic: (topic: string) => void;
|
|
9
|
+
removeTopic: (topic: string) => void;
|
|
10
|
+
resetTopics: () => void;
|
|
11
|
+
assert(condition?: boolean | undefined, ...data: any[]): void;
|
|
12
|
+
assert(value: any, message?: string | undefined, ...optionalParams: any[]): void;
|
|
13
|
+
clear(): void;
|
|
14
|
+
clear(): void;
|
|
15
|
+
count(label?: string | undefined): void;
|
|
16
|
+
count(label?: string | undefined): void;
|
|
17
|
+
countReset(label?: string | undefined): void;
|
|
18
|
+
countReset(label?: string | undefined): void;
|
|
19
|
+
debug(...data: any[]): void;
|
|
20
|
+
debug(message?: any, ...optionalParams: any[]): void;
|
|
21
|
+
dir(item?: any, options?: any): void;
|
|
22
|
+
dir(obj: any, options?: import("util").InspectOptions | undefined): void;
|
|
23
|
+
dirxml(...data: any[]): void;
|
|
24
|
+
dirxml(...data: any[]): void;
|
|
25
|
+
error(...data: any[]): void;
|
|
26
|
+
error(message?: any, ...optionalParams: any[]): void;
|
|
27
|
+
group(...data: any[]): void;
|
|
28
|
+
group(...label: any[]): void;
|
|
29
|
+
groupCollapsed(...data: any[]): void;
|
|
30
|
+
groupCollapsed(...label: any[]): void;
|
|
31
|
+
groupEnd(): void;
|
|
32
|
+
groupEnd(): void;
|
|
33
|
+
info(...data: any[]): void;
|
|
34
|
+
info(message?: any, ...optionalParams: any[]): void;
|
|
35
|
+
table(tabularData?: any, properties?: string[] | undefined): void;
|
|
36
|
+
table(tabularData: any, properties?: readonly string[] | undefined): void;
|
|
37
|
+
time(label?: string | undefined): void;
|
|
38
|
+
time(label?: string | undefined): void;
|
|
39
|
+
timeEnd(label?: string | undefined): void;
|
|
40
|
+
timeEnd(label?: string | undefined): void;
|
|
41
|
+
timeLog(label?: string | undefined, ...data: any[]): void;
|
|
42
|
+
timeLog(label?: string | undefined, ...data: any[]): void;
|
|
43
|
+
timeStamp(label?: string | undefined): void;
|
|
44
|
+
timeStamp(label?: string | undefined): void;
|
|
45
|
+
trace(...data: any[]): void;
|
|
46
|
+
trace(message?: any, ...optionalParams: any[]): void;
|
|
47
|
+
warn(...data: any[]): void;
|
|
48
|
+
warn(message?: any, ...optionalParams: any[]): void;
|
|
49
|
+
Console: console.ConsoleConstructor;
|
|
50
|
+
profile(label?: string | undefined): void;
|
|
51
|
+
profileEnd(label?: string | undefined): void;
|
|
52
|
+
};
|
package/dist/cubic.d.ts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
export declare function randomize(seed: number, x: number, y: number): number;
|
|
2
|
+
export declare function tile(coordinate: number, period: number): number;
|
|
3
|
+
export declare function interpolate(a: number, b: number, c: number, d: number, x: number, s: number, scale: number): number;
|
|
4
|
+
/**
|
|
5
|
+
* Config a cubic noise.
|
|
6
|
+
* @param {Number} seed A seed in the range [0, 1].
|
|
7
|
+
* @param {Number} [periodX] The number of units after which the x coordinate repeats.
|
|
8
|
+
* @param {Number} [periodY] The number of units after which the y coordinate repeats.
|
|
9
|
+
* @returns {Object} A configuration object used by noise functions.
|
|
10
|
+
*/
|
|
11
|
+
export declare function cubicNoiseConfig(seed: number, octave: number, scale: number, periodX?: number, periodY?: number): {
|
|
12
|
+
seed: number;
|
|
13
|
+
periodX: number;
|
|
14
|
+
periodY: number;
|
|
15
|
+
octave: number;
|
|
16
|
+
scale: number;
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* Sample 1D cubic noise.
|
|
20
|
+
* @param {Object} config A valid noise configuration.
|
|
21
|
+
* @param {Number} x The X position to sample at.
|
|
22
|
+
* @returns {Number} A noise value in the range [0, 1].
|
|
23
|
+
*/
|
|
24
|
+
export declare function cubicNoiseSample1(config: ReturnType<typeof cubicNoiseConfig>, x: number): number;
|
|
25
|
+
/**
|
|
26
|
+
* Sample 2D cubic noise.
|
|
27
|
+
* @param {Object} config A valid noise configuration.
|
|
28
|
+
* @param {Number} x The X position to sample at.
|
|
29
|
+
* @param {Number} y The Y position to sample at.
|
|
30
|
+
* @returns {Number} A noise value in the range [0, 1].
|
|
31
|
+
*/
|
|
32
|
+
export declare function cubicNoiseSample2({ octave, periodX, periodY, seed, scale }: ReturnType<typeof cubicNoiseConfig>, x: number, y: number): number;
|
|
@@ -5,6 +5,4 @@
|
|
|
5
5
|
* @param b
|
|
6
6
|
* @returns Euclidian distance between a and b
|
|
7
7
|
*/
|
|
8
|
-
export function euclidean(a: [number, number], b: [number, number]): number
|
|
9
|
-
return Math.sqrt(Math.pow(a[0] - b[0], 2) + Math.pow(a[1] - b[1], 2));
|
|
10
|
-
}
|
|
8
|
+
export declare function euclidean(a: [number, number], b: [number, number]): number;
|
package/dist/enums.d.ts
ADDED
package/dist/eth.d.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pads start of a hex string with 0 to create a bit string of the given length
|
|
3
|
+
* @param input Hex string
|
|
4
|
+
* @param bits Number of bits in the output hex string
|
|
5
|
+
* @returns Hex string of specified length
|
|
6
|
+
*/
|
|
7
|
+
export declare function padToBitLength(input: string, bits: number): string;
|
|
8
|
+
/**
|
|
9
|
+
* Pads start of a hex string with 0 to create a 160 bit hex string
|
|
10
|
+
* which can be used as an Ethereum address
|
|
11
|
+
* @param input Hex string
|
|
12
|
+
* @returns 160 bit hex string
|
|
13
|
+
*/
|
|
14
|
+
export declare function toEthAddress(input: string): string;
|
|
15
|
+
/**
|
|
16
|
+
* Pads start of a hex string with 0 to create a 256bit hex string
|
|
17
|
+
* which can be used as an Ethereum address
|
|
18
|
+
* @param input Hex string
|
|
19
|
+
* @returns 256 bit hex string
|
|
20
|
+
*/
|
|
21
|
+
export declare function to256BitString(input: string): string;
|
|
22
|
+
export declare function extractEncodedArguments(input: string): string;
|
package/dist/guards.d.ts
ADDED
package/dist/hash.d.ts
ADDED
|
@@ -21,16 +21,4 @@ export * from "./cubic";
|
|
|
21
21
|
export * from "./console";
|
|
22
22
|
export * from "./distance";
|
|
23
23
|
export * from "./math";
|
|
24
|
-
|
|
25
|
-
export type {
|
|
26
|
-
Cached,
|
|
27
|
-
CachedValue,
|
|
28
|
-
Func,
|
|
29
|
-
AsyncFunc,
|
|
30
|
-
PromiseValue,
|
|
31
|
-
ValueOf,
|
|
32
|
-
Area,
|
|
33
|
-
Coord,
|
|
34
|
-
VoxelCoord,
|
|
35
|
-
Logger,
|
|
36
|
-
} from "./types";
|
|
24
|
+
export type { Cached, CachedValue, Func, AsyncFunc, PromiseValue, ValueOf, Area, Coord, VoxelCoord, Logger, } from "./types";
|