@yorozu/utils 0.1.4 → 0.3.1
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/LICENSE +21 -0
- package/arrays/index.d.ts +4 -0
- package/arrays/typed/compare.d.ts +3 -0
- package/arrays/typed/find.d.ts +10 -0
- package/arrays/typed/index.d.ts +4 -0
- package/arrays/typed/misc.d.ts +10 -0
- package/arrays/typed/types.d.ts +2 -0
- package/arrays/u8/concat.d.ts +3 -0
- package/arrays/u8/index.d.ts +6 -0
- package/arrays/u8/misc.d.ts +3 -0
- package/arrays/u8/pool.d.ts +15 -0
- package/arrays/u8/reverse.d.ts +2 -0
- package/arrays/u8/swap.d.ts +4 -0
- package/arrays/u8/xor.d.ts +2 -0
- package/async/async-interval.d.ts +16 -0
- package/async/async-lock.d.ts +10 -0
- package/async/async-queue.d.ts +22 -0
- package/async/async-resource.d.ts +41 -0
- package/async/condition-variable.d.ts +6 -0
- package/async/deferred.d.ts +25 -0
- package/async/emitter.d.ts +15 -0
- package/async/index.d.ts +11 -0
- package/async/pool.d.ts +19 -0
- package/async/sleep.d.ts +1 -0
- package/async/timers.d.ts +8 -0
- package/bigint/bytes.d.ts +2 -0
- package/bigint/index.d.ts +2 -0
- package/bigint/math.d.ts +10 -0
- package/compress/bits.d.ts +5 -0
- package/compress/checksum.d.ts +15 -0
- package/compress/compress.d.ts +3 -0
- package/compress/decompress.d.ts +4 -0
- package/compress/deflate.d.ts +22 -0
- package/compress/detect.d.ts +2 -0
- package/compress/errors.d.ts +24 -0
- package/compress/gzip.d.ts +31 -0
- package/compress/huffman.d.ts +6 -0
- package/compress/index.d.ts +5 -0
- package/compress/inflate.d.ts +21 -0
- package/compress/types.d.ts +14 -0
- package/compress/zlib.d.ts +30 -0
- package/encoding/base64.d.ts +6 -0
- package/encoding/hex.d.ts +4 -0
- package/encoding/index.d.ts +4 -0
- package/encoding/utf8.d.ts +3 -0
- package/index.d.ts +9 -0
- package/index.js +3154 -0
- package/iterate/enumerate.d.ts +1 -0
- package/iterate/index.d.ts +1 -0
- package/misc/assert.d.ts +7 -0
- package/misc/composer.d.ts +4 -0
- package/misc/guards.d.ts +12 -0
- package/misc/index.d.ts +6 -0
- package/misc/noop.d.ts +1 -0
- package/misc/objects.d.ts +18 -0
- package/misc/string.d.ts +4 -0
- package/package.json +15 -17
- package/structures/_iterator.d.ts +2 -0
- package/structures/custom-map.d.ts +21 -0
- package/structures/custom-set.d.ts +25 -0
- package/structures/deque.d.ts +34 -0
- package/structures/index.d.ts +5 -0
- package/structures/lru-map.d.ts +15 -0
- package/structures/lru-set.d.ts +12 -0
- package/types/brand.d.ts +5 -0
- package/types/equal.d.ts +1 -0
- package/types/error.d.ts +6 -0
- package/types/index.d.ts +5 -0
- package/types/misc.d.ts +11 -0
- package/types/unions.d.ts +3 -0
- package/lib/index.cjs +0 -2044
- package/lib/index.d.cts +0 -468
- package/lib/index.d.ts +0 -468
- package/lib/index.js +0 -1958
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function enumerate<T>(iterable: Iterable<T>): IterableIterator<[number, T]>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './enumerate';
|
package/misc/assert.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Brand } from '../types/brand';
|
|
2
|
+
export declare function assert(condition: boolean, message?: unknown): asserts condition;
|
|
3
|
+
export declare function assertHashKey<Obj extends object, Key extends string>(obj: Obj, key: Key): asserts obj is Obj & Record<Key, unknown>;
|
|
4
|
+
export declare function unsafeCastType<T>(value: unknown): asserts value is T;
|
|
5
|
+
export declare function assertNotNull<T>(value: T): asserts value is Exclude<T, null | undefined>;
|
|
6
|
+
export declare function asNonNull<T>(value: null extends T ? T : undefined extends T ? T : Brand<"type is not nullable", "TypeError">): Exclude<T, null | undefined>;
|
|
7
|
+
export declare function assertMatches(str: string, regex: RegExp): RegExpMatchArray;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export type Middleware<C, R = void> = (ctx: C, next: (ctx: C) => Promise<R>) => Promise<R>;
|
|
2
|
+
export type ComposedMiddleware<C, R = void> = (ctx: C) => Promise<R>;
|
|
3
|
+
export declare function composeMiddlewares<C, R = void>(middlewares: Array<Middleware<C, R>>, final: ComposedMiddleware<C, R>): ComposedMiddleware<C, R>;
|
|
4
|
+
export declare function composeMiddlewares<C, R = void>(middlewares: Array<Middleware<C, R>>): Middleware<C, R>;
|
package/misc/guards.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { AnyFunction, Truthy } from '../types';
|
|
2
|
+
export declare const isNotUndefined: <T>(val: T) => val is Exclude<T, undefined>;
|
|
3
|
+
export declare const isNotNull: <T>(val: T) => val is Exclude<T, null>;
|
|
4
|
+
export declare const isBoolean: (val: any) => val is boolean;
|
|
5
|
+
export declare const isTruthy: <T>(val: T) => val is Truthy<T>;
|
|
6
|
+
export declare const isFalsy: <T>(val: T) => val is Exclude<T, Truthy<T>>;
|
|
7
|
+
export declare const isFunction: (val: any) => val is AnyFunction;
|
|
8
|
+
export declare const isNumber: (val: any) => val is number;
|
|
9
|
+
export declare const isString: (val: unknown) => val is string;
|
|
10
|
+
export declare const isSymbol: (val: any) => val is symbol;
|
|
11
|
+
export declare const isBigInt: (val: any) => val is bigint;
|
|
12
|
+
export declare const isObject: (val: any) => val is object;
|
package/misc/index.d.ts
ADDED
package/misc/noop.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function noop(): void;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { MaybeArray } from '../types';
|
|
2
|
+
export declare function objectKeys<T extends object>(obj: T): Array<`${keyof T & (string | number | boolean | null | undefined)}`>;
|
|
3
|
+
export declare function objectEntries<T extends object>(obj: T): Array<[keyof T, T[keyof T]]>;
|
|
4
|
+
export declare function clearUndefinedInPlace<T extends object>(obj: T): void;
|
|
5
|
+
export type MergeInsertions<T> = T extends object ? {
|
|
6
|
+
[K in keyof T]: MergeInsertions<T[K]>;
|
|
7
|
+
} : T;
|
|
8
|
+
export type DeepMerge<F, S> = MergeInsertions<{
|
|
9
|
+
[K in keyof F | keyof S]: K extends keyof S & keyof F ? DeepMerge<F[K], S[K]> : K extends keyof S ? S[K] : K extends keyof F ? F[K] : never;
|
|
10
|
+
}>;
|
|
11
|
+
export interface DeepMergeOptions {
|
|
12
|
+
undefined?: "replace" | "ignore";
|
|
13
|
+
properties?: "replace" | "ignore";
|
|
14
|
+
arrays?: "replace" | "ignore" | "merge";
|
|
15
|
+
objects?: "replace" | "ignore" | "merge";
|
|
16
|
+
}
|
|
17
|
+
export declare function deepMerge<T extends object = object>(into: T, from: MaybeArray<T>, options?: DeepMergeOptions): T;
|
|
18
|
+
export declare function deepMerge<T extends object = object, S extends object = T>(into: T, from: MaybeArray<S>, options?: DeepMergeOptions): DeepMerge<T, S>;
|
package/misc/string.d.ts
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export declare function splitOnce(str: string, separator: string): [string, string];
|
|
2
|
+
export declare function assertStartsWith<P extends string>(str: string, prefix: P): asserts str is `${P}${string}`;
|
|
3
|
+
export declare function assertEndsWith<S extends string>(str: string, suffix: S): asserts str is `${string}${S}`;
|
|
4
|
+
export { assertEndsWith as assertsEndsWith };
|
package/package.json
CHANGED
|
@@ -1,23 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yorozu/utils",
|
|
3
|
-
"version": "0.1.4",
|
|
4
3
|
"type": "module",
|
|
5
|
-
"
|
|
6
|
-
"author": "inshinrei",
|
|
7
|
-
"license": "MIT",
|
|
4
|
+
"version": "0.3.1",
|
|
8
5
|
"description": "quality of life",
|
|
9
|
-
"
|
|
10
|
-
"
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
"bench": "node benchmarks/main_bench.js",
|
|
18
|
-
"build": "tsup"
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"import": {
|
|
10
|
+
"types": "./index.d.ts",
|
|
11
|
+
"default": "./index.js"
|
|
12
|
+
}
|
|
13
|
+
}
|
|
19
14
|
},
|
|
20
|
-
"
|
|
21
|
-
|
|
15
|
+
"sideEffects": false,
|
|
16
|
+
"author": "inshinrei",
|
|
17
|
+
"repository": {
|
|
18
|
+
"type": "git",
|
|
19
|
+
"url": "git+https://github.com/inshinrei/yorozu.git"
|
|
22
20
|
}
|
|
23
|
-
}
|
|
21
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export declare class CustomMap<ExternalKey, InternalKey, V> implements Map<ExternalKey, V> {
|
|
2
|
+
readonly clear: Map<ExternalKey, V>["clear"];
|
|
3
|
+
protected _map: Map<InternalKey, V>;
|
|
4
|
+
protected _mapperTo: (key: ExternalKey) => InternalKey;
|
|
5
|
+
protected _mapperFrom: (key: InternalKey) => ExternalKey;
|
|
6
|
+
constructor(externalToInternal: (key: ExternalKey) => InternalKey, internalToExternal: (key: InternalKey) => ExternalKey);
|
|
7
|
+
get size(): number;
|
|
8
|
+
get [Symbol.toStringTag](): string;
|
|
9
|
+
getInternalMap(): Map<InternalKey, V>;
|
|
10
|
+
delete(key: ExternalKey): boolean;
|
|
11
|
+
forEach(cb: (value: V, key: ExternalKey, map: Map<ExternalKey, V>) => void, thisArg?: any): void;
|
|
12
|
+
get(key: ExternalKey): V | undefined;
|
|
13
|
+
has(key: ExternalKey): boolean;
|
|
14
|
+
set(key: ExternalKey, value: V): this;
|
|
15
|
+
getOrInsert(key: ExternalKey, value: V): ReturnType<Map<ExternalKey, V>["getOrInsert"]>;
|
|
16
|
+
getOrInsertComputed(key: ExternalKey, callback: (key: ExternalKey) => V): ReturnType<Map<ExternalKey, V>["getOrInsertComputed"]>;
|
|
17
|
+
entries(): ReturnType<Map<ExternalKey, V>["entries"]>;
|
|
18
|
+
keys(): ReturnType<Map<ExternalKey, V>["keys"]>;
|
|
19
|
+
values(): ReturnType<Map<ExternalKey, V>["values"]>;
|
|
20
|
+
[Symbol.iterator](): ReturnType<Map<ExternalKey, V>["entries"]>;
|
|
21
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export declare class CustomSet<ExternalKey, InternalKey> implements Set<ExternalKey> {
|
|
2
|
+
readonly clear: Set<ExternalKey>["clear"];
|
|
3
|
+
protected _set: Set<InternalKey>;
|
|
4
|
+
protected _mapperTo: (key: ExternalKey) => InternalKey;
|
|
5
|
+
protected _mapperFrom: (key: InternalKey) => ExternalKey;
|
|
6
|
+
constructor(externalToInternal: (key: ExternalKey) => InternalKey, internalToExternal: (key: InternalKey) => ExternalKey);
|
|
7
|
+
get size(): number;
|
|
8
|
+
get [Symbol.toStringTag](): string;
|
|
9
|
+
add(value: ExternalKey): this;
|
|
10
|
+
delete(value: ExternalKey): boolean;
|
|
11
|
+
forEach(cb: (value: ExternalKey, value2: ExternalKey, set: Set<ExternalKey>) => void, thisArg?: any): void;
|
|
12
|
+
has(value: ExternalKey): boolean;
|
|
13
|
+
entries(): ReturnType<Set<ExternalKey>["entries"]>;
|
|
14
|
+
keys(): ReturnType<Set<ExternalKey>["keys"]>;
|
|
15
|
+
values(): ReturnType<Set<ExternalKey>["values"]>;
|
|
16
|
+
union<U>(other: Set<U>): Set<ExternalKey | U>;
|
|
17
|
+
intersection<U>(other: Set<U>): Set<ExternalKey & U>;
|
|
18
|
+
difference<U>(other: ReadonlySetLike<ExternalKey & U>): Set<ExternalKey>;
|
|
19
|
+
symmetricDifference<U>(other: Set<U>): Set<ExternalKey | U>;
|
|
20
|
+
isSubsetOf(other: ReadonlySetLike<ExternalKey>): boolean;
|
|
21
|
+
isSupersetOf(other: Set<ExternalKey>): boolean;
|
|
22
|
+
isDisjointFrom(other: Set<ExternalKey>): boolean;
|
|
23
|
+
[Symbol.iterator](): ReturnType<Set<ExternalKey>["keys"]>;
|
|
24
|
+
getInternalSet(): Set<InternalKey>;
|
|
25
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
export interface DequeOptions {
|
|
2
|
+
capacity?: number;
|
|
3
|
+
}
|
|
4
|
+
export declare class Deque<T> {
|
|
5
|
+
protected _list: Array<T | undefined>;
|
|
6
|
+
protected _head: number;
|
|
7
|
+
protected _tail: number;
|
|
8
|
+
protected _capacityMask: number;
|
|
9
|
+
protected _capacity?: number;
|
|
10
|
+
protected _size: number;
|
|
11
|
+
constructor(array?: ArrayLike<T>, options?: DequeOptions);
|
|
12
|
+
get length(): number;
|
|
13
|
+
isEmpty(): boolean;
|
|
14
|
+
at(index: number): T | undefined;
|
|
15
|
+
peekFront(): T | undefined;
|
|
16
|
+
peekBack(): T | undefined;
|
|
17
|
+
pushFront(item: T): number;
|
|
18
|
+
pushBack(item: T): number;
|
|
19
|
+
popFront(): T | undefined;
|
|
20
|
+
popBack(): T | undefined;
|
|
21
|
+
removeOne(idx: number): T | undefined;
|
|
22
|
+
removeBy(predicate: (item: T) => boolean): void;
|
|
23
|
+
clear(): void;
|
|
24
|
+
indexOf(item: T): number;
|
|
25
|
+
findIndex(predicate: (item: T) => boolean): number;
|
|
26
|
+
find(predicate: (item: T) => boolean): T | undefined;
|
|
27
|
+
includes(item: T): boolean;
|
|
28
|
+
toArray(): Array<T>;
|
|
29
|
+
[Symbol.iterator](): Iterator<T>;
|
|
30
|
+
protected _fromArray(array: ArrayLike<T>): void;
|
|
31
|
+
protected _growArray(): void;
|
|
32
|
+
protected _shrinkArray(): void;
|
|
33
|
+
protected _remove(idx: number): void;
|
|
34
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export declare class LruMap<K, V> {
|
|
2
|
+
protected _capacity: number;
|
|
3
|
+
protected _map: Map<K, V>;
|
|
4
|
+
constructor(capacity: number, MapImpl?: new () => Map<K, V>);
|
|
5
|
+
get size(): number;
|
|
6
|
+
get(key: K): V | undefined;
|
|
7
|
+
has(key: K): boolean;
|
|
8
|
+
set(key: K, value: V): void;
|
|
9
|
+
delete(key: K): void;
|
|
10
|
+
clear(): void;
|
|
11
|
+
[Symbol.iterator](): IterableIterator<[K, V]>;
|
|
12
|
+
entries(): IterableIterator<[K, V]>;
|
|
13
|
+
keys(): IterableIterator<K>;
|
|
14
|
+
values(): IterableIterator<V>;
|
|
15
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export declare class LruSet<T> {
|
|
2
|
+
protected _capacity: number;
|
|
3
|
+
protected _set: Set<T>;
|
|
4
|
+
constructor(capacity: number, SetImpl?: new () => Set<T>);
|
|
5
|
+
get size(): number;
|
|
6
|
+
add(value: T): void;
|
|
7
|
+
has(value: T): boolean;
|
|
8
|
+
delete(value: T): boolean;
|
|
9
|
+
clear(): void;
|
|
10
|
+
[Symbol.iterator](): IterableIterator<T>;
|
|
11
|
+
toArray(): Array<T>;
|
|
12
|
+
}
|
package/types/brand.d.ts
ADDED
package/types/equal.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type TypesAreEqual<X, Y> = (<T>() => T extends X ? 1 : 2) extends <T>() => T extends Y ? 1 : 2 ? true : false;
|
package/types/error.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export declare function unknownToError(err: unknown): Error;
|
|
2
|
+
export declare class NotImplementedError extends Error {
|
|
3
|
+
constructor(message?: string, options?: ErrorOptions);
|
|
4
|
+
}
|
|
5
|
+
export declare function throwNotImplemented(message?: string, options?: ErrorOptions): never;
|
|
6
|
+
export declare function throwUnreachable(): never;
|
package/types/index.d.ts
ADDED
package/types/misc.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export type NoneToVoidFunction = () => void;
|
|
2
|
+
export type AnyFunction = (...args: any[]) => any;
|
|
3
|
+
export type AnyToVoidFunction = (...args: any[]) => void;
|
|
4
|
+
export type AnyToNever<T> = any extends T ? never : T;
|
|
5
|
+
export type MaybePromise<T> = Promise<T> | T;
|
|
6
|
+
export type MaybeArray<T> = Array<T> | T;
|
|
7
|
+
export type Values<T> = T[keyof T];
|
|
8
|
+
export type Truthy<T> = T extends false | "" | 0 | null | undefined ? never : T;
|
|
9
|
+
export type UnsafeMutate<T> = {
|
|
10
|
+
-readonly [P in keyof T]: T[P];
|
|
11
|
+
};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I : never;
|
|
2
|
+
export type LastOfUnion<U> = UnionToIntersection<U extends any ? () => U : never> extends () => infer R ? R : never;
|
|
3
|
+
export type UnionToTuple<U, Acc extends Array<any> = [], L = LastOfUnion<U>> = [U] extends [never] ? Acc : UnionToTuple<Exclude<U, L>, [L, ...Acc]>;
|