@yorozu/utils 0.1.4 → 0.3.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/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 +11 -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 +8 -0
- package/async/async-lock.d.ts +6 -0
- package/async/async-queue.d.ts +18 -0
- package/async/async-resource.d.ts +33 -0
- package/async/condition-variable.d.ts +5 -0
- package/async/deferred.d.ts +24 -0
- package/async/emitter.d.ts +11 -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/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 +8 -0
- package/index.js +1819 -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 +19 -0
- package/structures/custom-set.d.ts +23 -0
- package/structures/deque.d.ts +31 -0
- package/structures/index.d.ts +5 -0
- package/structures/lru-map.d.ts +14 -0
- package/structures/lru-set.d.ts +11 -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
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Ivan
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { TypedArray } from './types';
|
|
2
|
+
export declare function indexOf(haystack: Exclude<TypedArray, BigInt64Array | BigUint64Array>, needle: number, start?: number): number;
|
|
3
|
+
export declare function indexOf(haystack: BigInt64Array | BigUint64Array, needle: bigint, start?: number): number;
|
|
4
|
+
export declare function lastIndexOf(haystack: Exclude<TypedArray, BigInt64Array | BigUint64Array>, needle: number, start?: number): number;
|
|
5
|
+
export declare function lastIndexOf(haystack: BigInt64Array | BigUint64Array, needle: bigint, start?: number): number;
|
|
6
|
+
export declare function indexOfArray<T extends TypedArray>(haystack: T, needle: T, start?: number): number;
|
|
7
|
+
export declare function lastIndexOfArray<T extends TypedArray>(haystack: T, needle: T, start?: number): number;
|
|
8
|
+
export declare function includes(haystack: Exclude<TypedArray, BigInt64Array | BigUint64Array>, needle: number): boolean;
|
|
9
|
+
export declare function includes(haystack: BigInt64Array | BigUint64Array, needle: bigint): boolean;
|
|
10
|
+
export declare function includesArray<T extends TypedArray>(haystack: T, needle: T): boolean;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { TypedArray } from './types';
|
|
2
|
+
export declare function toDataView(buf: TypedArray): DataView;
|
|
3
|
+
export declare function view<R extends TypedArray>(ctor: {
|
|
4
|
+
new (buffer: ArrayBufferLike, byteOffset: number, byteLength: number): R;
|
|
5
|
+
BYTES_PER_ELEMENT: number;
|
|
6
|
+
}, buf: ArrayBufferView): R;
|
|
7
|
+
export declare function getPlatformByteOrder(): "little" | "big";
|
|
8
|
+
export declare namespace getPlatformByteOrder {
|
|
9
|
+
var _cachedByteOrder: boolean | null;
|
|
10
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export declare class BufferPool {
|
|
2
|
+
#private;
|
|
3
|
+
readonly size: number;
|
|
4
|
+
readonly maxAllocSize: number;
|
|
5
|
+
constructor(size?: number);
|
|
6
|
+
allocate(size: number): Uint8Array;
|
|
7
|
+
reset(): void;
|
|
8
|
+
}
|
|
9
|
+
export declare function setDefaultPool(size: number): void;
|
|
10
|
+
export declare function allocate(size: number): Uint8Array;
|
|
11
|
+
export declare function allocateWith(init: ArrayLike<number>): Uint8Array;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Deque } from '../structures';
|
|
2
|
+
export declare class AsyncQueue<T> {
|
|
3
|
+
#private;
|
|
4
|
+
readonly queue: Deque<T>;
|
|
5
|
+
readonly maxSize: number | undefined;
|
|
6
|
+
constructor(from?: ArrayLike<T> | Deque<T>, maxSize?: number);
|
|
7
|
+
get length(): number;
|
|
8
|
+
get isFull(): boolean;
|
|
9
|
+
get remainingCapacity(): number;
|
|
10
|
+
get ended(): boolean;
|
|
11
|
+
enqueue(item: T): Promise<void>;
|
|
12
|
+
tryEnqueue(item: T): boolean;
|
|
13
|
+
end(): void;
|
|
14
|
+
peek(): T | undefined;
|
|
15
|
+
next(): T | undefined;
|
|
16
|
+
nextOrWait(): Promise<T | undefined>;
|
|
17
|
+
[Symbol.asyncIterator](): AsyncIterableIterator<T>;
|
|
18
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { Emitter } from './emitter';
|
|
2
|
+
export interface AsyncResourceContext<T> {
|
|
3
|
+
readonly current: T | null;
|
|
4
|
+
readonly currentFetchedAt: number;
|
|
5
|
+
readonly currentExpiresAt: number;
|
|
6
|
+
readonly isBackground: boolean;
|
|
7
|
+
readonly abort: AbortSignal | null;
|
|
8
|
+
}
|
|
9
|
+
export interface AsyncResourceOptions<T> {
|
|
10
|
+
autoReload?: boolean;
|
|
11
|
+
autoReloadAfter?: number;
|
|
12
|
+
/** @deprecated Use `autoReloadAfter`. */
|
|
13
|
+
authReloadAfter?: number;
|
|
14
|
+
swr?: boolean;
|
|
15
|
+
swrValidator?: (ctx: AsyncResourceContext<T>) => boolean;
|
|
16
|
+
fetcher: (ctx: AsyncResourceContext<T>) => Promise<{
|
|
17
|
+
data: T;
|
|
18
|
+
expiresIn: number;
|
|
19
|
+
}>;
|
|
20
|
+
onError?: (err: unknown, ctx: AsyncResourceContext<T>) => void;
|
|
21
|
+
}
|
|
22
|
+
export declare class AsyncResource<T> {
|
|
23
|
+
#private;
|
|
24
|
+
readonly options: AsyncResourceOptions<T>;
|
|
25
|
+
readonly onUpdated: Emitter<AsyncResourceContext<T>>;
|
|
26
|
+
constructor(options: AsyncResourceOptions<T>);
|
|
27
|
+
get isStale(): boolean;
|
|
28
|
+
setData(data: T, expiresIn: number): void;
|
|
29
|
+
update(force?: boolean): Promise<void>;
|
|
30
|
+
get(): Promise<T | null>;
|
|
31
|
+
getCached(): T | null;
|
|
32
|
+
destroy(): void;
|
|
33
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export declare class Deferred<T = void> {
|
|
2
|
+
readonly resolve: (value: T) => void;
|
|
3
|
+
readonly reject: (reason: unknown) => void;
|
|
4
|
+
readonly promise: Promise<T>;
|
|
5
|
+
constructor();
|
|
6
|
+
}
|
|
7
|
+
export declare class DeferredTracked<T = void> {
|
|
8
|
+
#private;
|
|
9
|
+
readonly promise: Promise<T>;
|
|
10
|
+
readonly status: {
|
|
11
|
+
type: "pending";
|
|
12
|
+
} | {
|
|
13
|
+
type: "fulfilled";
|
|
14
|
+
value: T;
|
|
15
|
+
} | {
|
|
16
|
+
type: "rejected";
|
|
17
|
+
reason: unknown;
|
|
18
|
+
};
|
|
19
|
+
constructor();
|
|
20
|
+
get result(): T | undefined;
|
|
21
|
+
get error(): unknown | undefined;
|
|
22
|
+
resolve(value: T): void;
|
|
23
|
+
reject(reason: unknown): void;
|
|
24
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export declare class Emitter<T> {
|
|
2
|
+
#private;
|
|
3
|
+
get length(): number;
|
|
4
|
+
add(listener: (value: T) => void): void;
|
|
5
|
+
forwardTo(emitter: Emitter<T>): void;
|
|
6
|
+
remove(listener: (value: T) => void): void;
|
|
7
|
+
emit(value: T): void;
|
|
8
|
+
once(listener: (value: T) => void): void;
|
|
9
|
+
listeners(): readonly ((value: T) => void)[];
|
|
10
|
+
clear(): void;
|
|
11
|
+
}
|
package/async/index.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import * as timers from "./timers";
|
|
2
|
+
export * from './async-interval';
|
|
3
|
+
export * from './async-lock';
|
|
4
|
+
export * from './async-queue';
|
|
5
|
+
export * from './async-resource';
|
|
6
|
+
export * from './condition-variable';
|
|
7
|
+
export * from './deferred';
|
|
8
|
+
export * from './emitter';
|
|
9
|
+
export * from './pool';
|
|
10
|
+
export * from './sleep';
|
|
11
|
+
export { timers };
|
package/async/pool.d.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { MaybePromise } from '../types';
|
|
2
|
+
export interface AsyncPoolOptions<T> {
|
|
3
|
+
limit?: number;
|
|
4
|
+
signal?: AbortSignal;
|
|
5
|
+
onErrorStrategy?: (item: T, index: number, error: unknown) => MaybePromise<"ignore" | "collect" | "throw">;
|
|
6
|
+
}
|
|
7
|
+
declare class ErrorInfo<T> {
|
|
8
|
+
readonly item: T;
|
|
9
|
+
readonly index: number;
|
|
10
|
+
readonly error: unknown;
|
|
11
|
+
constructor(item: T, index: number, error: unknown);
|
|
12
|
+
}
|
|
13
|
+
export declare class AggregateError<T> extends Error {
|
|
14
|
+
readonly errors: Array<ErrorInfo<T>>;
|
|
15
|
+
constructor(errors: Array<ErrorInfo<T>>);
|
|
16
|
+
}
|
|
17
|
+
export declare function asyncPool<T>(iterable: Iterable<T> | AsyncIterable<T>, executor: (item: T, index: number) => MaybePromise<T | void>, options?: AsyncPoolOptions<T>): Promise<void>;
|
|
18
|
+
export declare function parallelMap<T, R>(iterable: Iterable<T> | AsyncIterable<T>, executor: (item: T, index: number) => MaybePromise<R>, options?: AsyncPoolOptions<T>): Promise<Array<R>>;
|
|
19
|
+
export {};
|
package/async/sleep.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function sleep(ms: number, signal?: AbortSignal): Promise<void>;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Brand } from '../types/brand';
|
|
2
|
+
export type Timer = Brand<object, "Timer">;
|
|
3
|
+
export type Interval = Brand<object, "Interval">;
|
|
4
|
+
declare const setTimeoutWrap: <T extends (...args: any[]) => any>(fn: T, ms: number, ...args: Parameters<T>) => Timer;
|
|
5
|
+
declare const setIntervalWrap: <T extends (...args: any[]) => any>(fn: T, ms: number, ...args: Parameters<T>) => Interval;
|
|
6
|
+
declare const clearTimeoutWrap: (timer?: Timer) => void;
|
|
7
|
+
declare const clearIntervalWrap: (timer?: Interval) => void;
|
|
8
|
+
export { clearIntervalWrap as clearInterval, clearTimeoutWrap as clearTimeout, setIntervalWrap as setInterval, setTimeoutWrap as setTimeout, };
|
package/bigint/math.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export declare function bitLength(n: bigint): number;
|
|
2
|
+
export declare function twoMultiplicity(n: bigint): bigint;
|
|
3
|
+
export declare function min2(a: bigint, b: bigint): bigint;
|
|
4
|
+
export declare function min(...args: Array<bigint>): bigint;
|
|
5
|
+
export declare function max2(a: bigint, b: bigint): bigint;
|
|
6
|
+
export declare function max(...args: Array<bigint>): bigint;
|
|
7
|
+
export declare function abs(a: bigint): bigint;
|
|
8
|
+
export declare function euclideanGcd(a: bigint, b: bigint): bigint;
|
|
9
|
+
export declare function modPowBinary(base: bigint, exp: bigint, mod: bigint): bigint;
|
|
10
|
+
export declare function modInv(a: bigint, n: bigint): bigint;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export declare const lookup: Map<number, number>;
|
|
2
|
+
export declare const encodeLookup: Map<number, number>;
|
|
3
|
+
export declare function decode(data: string, url?: boolean): Uint8Array;
|
|
4
|
+
export declare function encode(bytes: Uint8Array, url?: boolean): string;
|
|
5
|
+
export declare function encodedLength(n: number): number;
|
|
6
|
+
export declare function decodedLength(n: number): number;
|