@yorozu/utils 0.3.0 → 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/arrays/u8/pool.d.ts +5 -1
- package/async/async-interval.d.ts +9 -1
- package/async/async-lock.d.ts +5 -1
- package/async/async-queue.d.ts +5 -1
- package/async/async-resource.d.ts +9 -1
- package/async/condition-variable.d.ts +2 -1
- package/async/deferred.d.ts +2 -1
- package/async/emitter.d.ts +5 -1
- 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/index.d.ts +1 -0
- package/index.js +1599 -264
- package/package.json +1 -1
- package/structures/custom-map.d.ts +3 -1
- package/structures/custom-set.d.ts +3 -1
- package/structures/deque.d.ts +4 -1
- package/structures/lru-map.d.ts +2 -1
- package/structures/lru-set.d.ts +2 -1
package/arrays/u8/pool.d.ts
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
export declare class BufferPool {
|
|
2
|
-
#private;
|
|
3
2
|
readonly size: number;
|
|
4
3
|
readonly maxAllocSize: number;
|
|
4
|
+
protected _pool: ArrayBuffer;
|
|
5
|
+
protected _offset: number;
|
|
5
6
|
constructor(size?: number);
|
|
7
|
+
protected get _remaining(): number;
|
|
6
8
|
allocate(size: number): Uint8Array;
|
|
7
9
|
reset(): void;
|
|
10
|
+
protected _reallocate(): void;
|
|
11
|
+
protected _align(): void;
|
|
8
12
|
}
|
|
9
13
|
export declare function setDefaultPool(size: number): void;
|
|
10
14
|
export declare function allocate(size: number): Uint8Array;
|
|
@@ -1,8 +1,16 @@
|
|
|
1
|
+
import * as timers from "./timers";
|
|
1
2
|
export declare class AsyncInterval {
|
|
2
|
-
|
|
3
|
+
protected _handler: (abortSignal: AbortSignal) => Promise<void>;
|
|
4
|
+
protected _interval: number;
|
|
5
|
+
protected _timer?: timers.Timer;
|
|
6
|
+
protected _onError: (err: unknown) => void;
|
|
7
|
+
protected _stopped: boolean;
|
|
8
|
+
protected _generation: number;
|
|
9
|
+
protected _abortController: AbortController;
|
|
3
10
|
constructor(handler: (abortSignal: AbortSignal) => Promise<void>, interval: number);
|
|
4
11
|
start(after?: number): void;
|
|
5
12
|
startNow(): void;
|
|
6
13
|
stop(): void;
|
|
7
14
|
onError(handler: (err: unknown) => void): void;
|
|
15
|
+
protected _onTimeout: (generation: number) => void;
|
|
8
16
|
}
|
package/async/async-lock.d.ts
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
|
+
import { NoneToVoidFunction } from '../types';
|
|
2
|
+
import { Deque } from '../structures';
|
|
3
|
+
type LockInfo = [Promise<void>, NoneToVoidFunction];
|
|
1
4
|
export declare class AsyncLock {
|
|
2
|
-
|
|
5
|
+
protected _queue: Deque<LockInfo>;
|
|
3
6
|
acquire(): Promise<void>;
|
|
4
7
|
release(): void;
|
|
5
8
|
with<T>(func: () => Promise<T>): Promise<T>;
|
|
6
9
|
}
|
|
10
|
+
export {};
|
package/async/async-queue.d.ts
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import { Deque } from '../structures';
|
|
2
|
+
import { Deferred } from './deferred';
|
|
2
3
|
export declare class AsyncQueue<T> {
|
|
3
|
-
#private;
|
|
4
4
|
readonly queue: Deque<T>;
|
|
5
5
|
readonly maxSize: number | undefined;
|
|
6
|
+
protected _consumerWaiters: Deque<Deferred<T | undefined>>;
|
|
7
|
+
protected _producerWaiters: Deque<Deferred<void>>;
|
|
8
|
+
protected _ended: boolean;
|
|
6
9
|
constructor(from?: ArrayLike<T> | Deque<T>, maxSize?: number);
|
|
7
10
|
get length(): number;
|
|
8
11
|
get isFull(): boolean;
|
|
@@ -15,4 +18,5 @@ export declare class AsyncQueue<T> {
|
|
|
15
18
|
next(): T | undefined;
|
|
16
19
|
nextOrWait(): Promise<T | undefined>;
|
|
17
20
|
[Symbol.asyncIterator](): AsyncIterableIterator<T>;
|
|
21
|
+
protected _wakeProducerIfNeeded(): void;
|
|
18
22
|
}
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
+
import { UnsafeMutate } from '../types';
|
|
2
|
+
import { Deferred } from './deferred';
|
|
1
3
|
import { Emitter } from './emitter';
|
|
4
|
+
import * as timers from "./timers";
|
|
2
5
|
export interface AsyncResourceContext<T> {
|
|
3
6
|
readonly current: T | null;
|
|
4
7
|
readonly currentFetchedAt: number;
|
|
@@ -20,9 +23,13 @@ export interface AsyncResourceOptions<T> {
|
|
|
20
23
|
onError?: (err: unknown, ctx: AsyncResourceContext<T>) => void;
|
|
21
24
|
}
|
|
22
25
|
export declare class AsyncResource<T> {
|
|
23
|
-
#private;
|
|
24
26
|
readonly options: AsyncResourceOptions<T>;
|
|
25
27
|
readonly onUpdated: Emitter<AsyncResourceContext<T>>;
|
|
28
|
+
protected _abort?: AbortController;
|
|
29
|
+
protected _ctx: UnsafeMutate<AsyncResourceContext<T>>;
|
|
30
|
+
protected _updating?: Deferred<void>;
|
|
31
|
+
protected _timeout?: timers.Timer;
|
|
32
|
+
protected _destroyed: boolean;
|
|
26
33
|
constructor(options: AsyncResourceOptions<T>);
|
|
27
34
|
get isStale(): boolean;
|
|
28
35
|
setData(data: T, expiresIn: number): void;
|
|
@@ -30,4 +37,5 @@ export declare class AsyncResource<T> {
|
|
|
30
37
|
get(): Promise<T | null>;
|
|
31
38
|
getCached(): T | null;
|
|
32
39
|
destroy(): void;
|
|
40
|
+
protected _clearTimer(): void;
|
|
33
41
|
}
|
package/async/deferred.d.ts
CHANGED
|
@@ -5,7 +5,6 @@ export declare class Deferred<T = void> {
|
|
|
5
5
|
constructor();
|
|
6
6
|
}
|
|
7
7
|
export declare class DeferredTracked<T = void> {
|
|
8
|
-
#private;
|
|
9
8
|
readonly promise: Promise<T>;
|
|
10
9
|
readonly status: {
|
|
11
10
|
type: "pending";
|
|
@@ -16,6 +15,8 @@ export declare class DeferredTracked<T = void> {
|
|
|
16
15
|
type: "rejected";
|
|
17
16
|
reason: unknown;
|
|
18
17
|
};
|
|
18
|
+
protected _resolve: (value: T) => void;
|
|
19
|
+
protected _reject: (reason: unknown) => void;
|
|
19
20
|
constructor();
|
|
20
21
|
get result(): T | undefined;
|
|
21
22
|
get error(): unknown | undefined;
|
package/async/emitter.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export declare class Emitter<T> {
|
|
2
|
-
|
|
2
|
+
protected _listeners: ((value: T) => void)[];
|
|
3
|
+
protected _emit: (value: T) => void;
|
|
3
4
|
get length(): number;
|
|
4
5
|
add(listener: (value: T) => void): void;
|
|
5
6
|
forwardTo(emitter: Emitter<T>): void;
|
|
@@ -8,4 +9,7 @@ export declare class Emitter<T> {
|
|
|
8
9
|
once(listener: (value: T) => void): void;
|
|
9
10
|
listeners(): readonly ((value: T) => void)[];
|
|
10
11
|
clear(): void;
|
|
12
|
+
protected _emitFew: (value: T) => void;
|
|
13
|
+
protected _emitAll: (value: T) => void;
|
|
14
|
+
protected _updateEmit: () => void;
|
|
11
15
|
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export declare function readBits(data: Uint8Array, bitPos: number, mask: number): number;
|
|
2
|
+
export declare function readBits16(data: Uint8Array, bitPos: number): number;
|
|
3
|
+
export declare function writeBits(data: Uint8Array, bitPos: number, value: number): void;
|
|
4
|
+
export declare function writeBits16(data: Uint8Array, bitPos: number, value: number): void;
|
|
5
|
+
export declare function byteCeil(bitPos: number): number;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export declare class Crc32 {
|
|
2
|
+
protected _c: number;
|
|
3
|
+
constructor(seed?: number);
|
|
4
|
+
update(data: Uint8Array): this;
|
|
5
|
+
digest(): number;
|
|
6
|
+
}
|
|
7
|
+
export declare function crc32(data: Uint8Array, seed?: number): number;
|
|
8
|
+
export declare class Adler32 {
|
|
9
|
+
protected _a: number;
|
|
10
|
+
protected _b: number;
|
|
11
|
+
constructor(seed?: number);
|
|
12
|
+
update(data: Uint8Array): this;
|
|
13
|
+
digest(): number;
|
|
14
|
+
}
|
|
15
|
+
export declare function adler32(data: Uint8Array, seed?: number): number;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { CompressOptions } from './types';
|
|
2
|
+
export type DeflateState = {
|
|
3
|
+
head?: Uint16Array;
|
|
4
|
+
prev?: Uint16Array;
|
|
5
|
+
index?: number;
|
|
6
|
+
end?: number;
|
|
7
|
+
wait?: number;
|
|
8
|
+
remainder?: number;
|
|
9
|
+
last: number;
|
|
10
|
+
};
|
|
11
|
+
export declare function deflateWithOptions(data: Uint8Array, options: CompressOptions, pre: number, post: number, state?: DeflateState): Uint8Array;
|
|
12
|
+
export declare function compress(data: Uint8Array, options?: CompressOptions): Uint8Array;
|
|
13
|
+
export declare class Compressor {
|
|
14
|
+
protected _options: CompressOptions;
|
|
15
|
+
protected _state: DeflateState;
|
|
16
|
+
protected _buffer: Uint8Array;
|
|
17
|
+
protected _done: boolean;
|
|
18
|
+
constructor(options?: CompressOptions);
|
|
19
|
+
protected _emit(final: boolean): Uint8Array;
|
|
20
|
+
push(chunk: Uint8Array, final?: boolean): Uint8Array;
|
|
21
|
+
flush(sync?: boolean): Uint8Array;
|
|
22
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export declare class FlateError extends Error {
|
|
2
|
+
constructor(message: string, options?: ErrorOptions);
|
|
3
|
+
}
|
|
4
|
+
export declare class UnexpectedEofError extends FlateError {
|
|
5
|
+
constructor(options?: ErrorOptions);
|
|
6
|
+
}
|
|
7
|
+
export declare class InvalidBlockTypeError extends FlateError {
|
|
8
|
+
constructor(options?: ErrorOptions);
|
|
9
|
+
}
|
|
10
|
+
export declare class InvalidLengthLiteralError extends FlateError {
|
|
11
|
+
constructor(options?: ErrorOptions);
|
|
12
|
+
}
|
|
13
|
+
export declare class InvalidDistanceError extends FlateError {
|
|
14
|
+
constructor(options?: ErrorOptions);
|
|
15
|
+
}
|
|
16
|
+
export declare class InvalidHeaderError extends FlateError {
|
|
17
|
+
constructor(message?: string, options?: ErrorOptions);
|
|
18
|
+
}
|
|
19
|
+
export declare class StreamFinishedError extends FlateError {
|
|
20
|
+
constructor(options?: ErrorOptions);
|
|
21
|
+
}
|
|
22
|
+
export declare class ChecksumMismatchError extends FlateError {
|
|
23
|
+
constructor(options?: ErrorOptions);
|
|
24
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { Crc32 } from './checksum';
|
|
2
|
+
import { Compressor as RawCompressor } from './deflate';
|
|
3
|
+
import { InflateState } from './inflate';
|
|
4
|
+
import { DecompressOptions, GzipCompressOptions } from './types';
|
|
5
|
+
export declare function gzipHeaderLength(data: Uint8Array): number;
|
|
6
|
+
export declare function compress(data: Uint8Array, options?: GzipCompressOptions): Uint8Array;
|
|
7
|
+
export declare function decompress(data: Uint8Array, options?: DecompressOptions): Uint8Array;
|
|
8
|
+
export declare class Compressor {
|
|
9
|
+
protected _inner: RawCompressor;
|
|
10
|
+
protected _options: GzipCompressOptions;
|
|
11
|
+
protected _crc: Crc32;
|
|
12
|
+
protected _length: number;
|
|
13
|
+
protected _header: boolean;
|
|
14
|
+
protected _done: boolean;
|
|
15
|
+
constructor(options?: GzipCompressOptions);
|
|
16
|
+
protected _wrap(raw: Uint8Array, final: boolean): Uint8Array;
|
|
17
|
+
push(chunk: Uint8Array, final?: boolean): Uint8Array;
|
|
18
|
+
flush(sync?: boolean): Uint8Array;
|
|
19
|
+
}
|
|
20
|
+
export declare class Decompressor {
|
|
21
|
+
protected _pending: Uint8Array;
|
|
22
|
+
protected _needHeader: boolean;
|
|
23
|
+
protected _state: InflateState;
|
|
24
|
+
protected _window: Uint8Array;
|
|
25
|
+
protected _crc: Crc32;
|
|
26
|
+
protected _length: number;
|
|
27
|
+
protected _check: boolean;
|
|
28
|
+
protected _done: boolean;
|
|
29
|
+
constructor(options?: DecompressOptions);
|
|
30
|
+
push(chunk: Uint8Array, final?: boolean): Uint8Array;
|
|
31
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export declare function buildEncodeMap(lengths: Uint8Array, maxBits: number): Uint16Array;
|
|
2
|
+
export declare function buildDecodeMap(lengths: Uint8Array, maxBits: number): Uint16Array;
|
|
3
|
+
export declare function buildLengthLimitedTree(freqs: Uint16Array, maxBits: number): {
|
|
4
|
+
lengths: Uint8Array;
|
|
5
|
+
maxBits: number;
|
|
6
|
+
};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { adler32, Adler32, crc32, Crc32 } from './checksum';
|
|
2
|
+
export * as compress from './compress';
|
|
3
|
+
export * as decompress from './decompress';
|
|
4
|
+
export { ChecksumMismatchError, FlateError, InvalidBlockTypeError, InvalidDistanceError, InvalidHeaderError, InvalidLengthLiteralError, StreamFinishedError, UnexpectedEofError, } from './errors';
|
|
5
|
+
export type { CompressOptions, DecompressOptions, GzipCompressOptions } from './types';
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { DecompressOptions } from './types';
|
|
2
|
+
export type InflateState = {
|
|
3
|
+
lengthMap?: Uint16Array;
|
|
4
|
+
distanceMap?: Uint16Array;
|
|
5
|
+
lengthBits?: number;
|
|
6
|
+
distanceBits?: number;
|
|
7
|
+
final?: number;
|
|
8
|
+
bitPos?: number;
|
|
9
|
+
outputLength?: number;
|
|
10
|
+
mode: number;
|
|
11
|
+
};
|
|
12
|
+
export declare function inflateRaw(data: Uint8Array, state: InflateState, buf?: Uint8Array, dictionary?: Uint8Array): Uint8Array;
|
|
13
|
+
export declare function decompress(data: Uint8Array, options?: DecompressOptions): Uint8Array;
|
|
14
|
+
export declare class Decompressor {
|
|
15
|
+
protected _state: InflateState;
|
|
16
|
+
protected _window: Uint8Array;
|
|
17
|
+
protected _pending: Uint8Array;
|
|
18
|
+
protected _done: boolean;
|
|
19
|
+
constructor(options?: DecompressOptions);
|
|
20
|
+
push(chunk: Uint8Array, final?: boolean): Uint8Array;
|
|
21
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export interface CompressOptions {
|
|
2
|
+
level?: 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9;
|
|
3
|
+
mem?: 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12;
|
|
4
|
+
dictionary?: Uint8Array;
|
|
5
|
+
}
|
|
6
|
+
export interface DecompressOptions {
|
|
7
|
+
dictionary?: Uint8Array;
|
|
8
|
+
out?: Uint8Array;
|
|
9
|
+
check?: boolean;
|
|
10
|
+
}
|
|
11
|
+
export interface GzipCompressOptions extends CompressOptions {
|
|
12
|
+
mtime?: Date | string | number;
|
|
13
|
+
filename?: string;
|
|
14
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { Adler32 } from './checksum';
|
|
2
|
+
import { Compressor as RawCompressor } from './deflate';
|
|
3
|
+
import { InflateState } from './inflate';
|
|
4
|
+
import { CompressOptions, DecompressOptions } from './types';
|
|
5
|
+
export declare function zlibHeaderLength(data: Uint8Array, dictionary?: Uint8Array): number;
|
|
6
|
+
export declare function compress(data: Uint8Array, options?: CompressOptions): Uint8Array;
|
|
7
|
+
export declare function decompress(data: Uint8Array, options?: DecompressOptions): Uint8Array;
|
|
8
|
+
export declare class Compressor {
|
|
9
|
+
protected _inner: RawCompressor;
|
|
10
|
+
protected _options: CompressOptions;
|
|
11
|
+
protected _sum: Adler32;
|
|
12
|
+
protected _header: boolean;
|
|
13
|
+
protected _done: boolean;
|
|
14
|
+
constructor(options?: CompressOptions);
|
|
15
|
+
protected _wrap(raw: Uint8Array, final: boolean): Uint8Array;
|
|
16
|
+
push(chunk: Uint8Array, final?: boolean): Uint8Array;
|
|
17
|
+
flush(sync?: boolean): Uint8Array;
|
|
18
|
+
}
|
|
19
|
+
export declare class Decompressor {
|
|
20
|
+
protected _pending: Uint8Array;
|
|
21
|
+
protected _header: boolean;
|
|
22
|
+
protected _state: InflateState;
|
|
23
|
+
protected _window: Uint8Array;
|
|
24
|
+
protected _sum: Adler32;
|
|
25
|
+
protected _dictionary?: Uint8Array;
|
|
26
|
+
protected _check: boolean;
|
|
27
|
+
protected _done: boolean;
|
|
28
|
+
constructor(options?: DecompressOptions);
|
|
29
|
+
push(chunk: Uint8Array, final?: boolean): Uint8Array;
|
|
30
|
+
}
|
package/index.d.ts
CHANGED