lazy-js-utils
Version:
A collection of lazy-loaded JavaScript utilities for efficient development
208 lines (206 loc) • 7.02 kB
text/typescript
declare global {
interface Window {
webkitRequestAnimationFrame: (callback: FrameRequestCallback) => number;
mozRequestAnimationFrame: (callback: FrameRequestCallback) => number;
msRequestAnimationFrame: (callback: FrameRequestCallback) => number;
oRequestAnimationFrame: (callback: FrameRequestCallback) => number;
webkitCancelAnimationFrame: (handle: number) => void;
mozCancelAnimationFrame: (handle: number) => void;
oCancelAnimationFrame: (handle: number) => void;
msCancelAnimationFrame: (handle: number) => void;
webkitIndexedDB: IDBFactory;
mozIndexedDB: IDBFactory;
msIndexedDB: IDBFactory;
indexedDB: IDBFactory;
SpeechRecognition: any;
webkitSpeechRecognition: any;
}
interface Navigator {
webkitGetUserMedia: () => void;
mozGetUserMedia: () => void;
msGetUserMedia: () => void;
getUserMedia: () => void;
}
}
type Redirect = 'follow' | 'error' | 'manual';
type Cache = 'default' | 'no-store' | 'reload' | 'no-cache' | 'force-cache';
type Mode = 'cors' | 'no-cors' | 'same-origin' | 'navigate';
type ResponseType = 'formData' | 'text' | 'blob' | 'arrayBuffer' | 'json';
type BodyType = 'form' | 'json' | 'file';
type Method = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'OPTIONS';
type Credentials = 'omit' | 'include' | 'same-origin';
interface IFetchInterceptors {
request?: {
success?: (config: IFetchConfig) => IFetchConfig;
error?: (error: any) => Promise<never>;
};
response?: {
success?: (response: any) => any;
error?: (error: any) => Promise<never>;
};
success?: (response: Response) => Response;
error?: (error: any) => Promise<never>;
}
interface IFetchConfig extends IFetchOptions {
url?: string;
keepalive?: boolean;
body?: any;
retry?: number;
integrity?: string;
referrer?: string;
referrerPolicy?: 'no-referrer' | 'no-referrer-when-downgrade' | 'origin' | 'origin-when-cross-origin' | 'unsafe-url' | 'strict-origin' | 'strict-origin-when-cross-origin' | 'same-origin';
method?: Method;
credentials?: Credentials;
params?: Record<string, string>;
responseType?: ResponseType;
bodyType?: BodyType;
cache?: Cache;
redirect?: Redirect;
mode?: Mode;
signal?: AbortSignal;
cancel?: () => void;
transformResponse?: (response: Response) => Response;
}
interface IFetchOptions {
baseURL?: string;
timeout?: number;
headers?: Record<string, any>;
interceptors?: IFetchInterceptors;
}
interface DeviceType {
os: string;
dev: string;
}
type TrimType = 'all' | 'pre' | 'around' | 'post';
interface EventBus {
data: Record<string, Function[]>;
emit: (event: string, data?: any) => void;
on: (event: string, fn: (data?: any) => void) => void;
off: (event: string, fn: Function) => void;
}
interface Position {
x: number;
y: number;
}
type FileType = 'file' | 'blob' | 'url';
interface JSCookie {
get: (key: string) => string | undefined;
set: (key: string, value: string, extdays?: number) => void;
delete: (key: string) => void;
}
interface LRU {
set: (key: string, value: any) => void;
get: (key: string) => any;
cache: Map<string, any>;
max: number;
size: () => number;
}
interface ISignature {
canvas: HTMLCanvasElement;
ctx: CanvasRenderingContext2D;
createCanvas: (lineWidth: number, w: number, h: number) => void;
clearCanvas: () => void;
mount: (el: MaybeElement) => void;
unmount: () => void;
setColor: (color: string) => void;
setBgColor: (bg: string) => void;
undo: () => void;
redo: () => void;
save: (type?: string, quality?: any) => string;
}
interface FileMD5 {
HASH: string;
suffix: string;
filename: string;
buffer: ArrayBuffer;
}
interface FileChunk {
file: Blob;
filename: string;
}
type ChunkDetail = ChunkInfo & {
isDone: boolean;
remaining: number;
type: string;
size: number;
lastModified: number;
};
interface ChunkInfo {
start: number;
end: number;
index: number;
hash: string;
}
interface FileSpliceOptions {
file: File;
chunkSize: number;
callback: (chunk: ChunkDetail) => void;
}
interface Deadline {
timeRemaining: () => number;
didTimeout: boolean;
}
interface DragEvent {
dragStart?: (e: any) => void;
dragMove?: (e: any) => void;
dragEnd?: (e: any) => void;
}
interface MutationObserverInit {
childList?: boolean;
attributes?: boolean;
characterData?: boolean;
subtree?: boolean;
attributeOldValue?: boolean;
characterDataOldValue?: boolean;
attributeFilter?: string[];
}
interface ParsedURL {
protocol?: string;
host?: string;
auth?: string;
pathname: string;
hash: string;
search: string;
}
interface IShellMessage {
status: number | null;
result: string;
pid: number;
}
type PkgTool = 'npm' | 'yarn' | 'pnpm' | 'bun';
type Keys<A, B> = keyof A | keyof B;
type Val<key, A, B> = key extends keyof A ? key extends keyof B ? A[key] extends number | string | boolean | symbol | null | undefined ? A[key] | B[key] : Merge<A[key], B[key]> : A[key] : key extends keyof B ? B[key] : never;
type Merge<A, B> = {
[key in Keys<A, B>]: Val<key, A, B>;
};
interface IsESModule {
default: any;
}
interface NodeWorkerPayload {
params: string | string[];
stdio?: 'inherit' | 'pipe';
errorExit?: boolean;
isLog?: boolean;
}
type UseTimeoutReturn<T> = T extends Function ? () => void : undefined;
type MaybeElement = string | HTMLElement;
type Lang = 'zh-CN' | 'en-US' | 'ja-JP' | 'ko-KR' | 'zh-TW' | 'zh-HK' | 'zh-MO' | 'zh-SG';
type Direction = 'horizontal' | 'horizontal-reverse' | 'vertical' | 'vertical-reverse' | 'center-out' | 'out-center';
type TimeUnit = 'days' | 'hours' | 'minutes' | 'seconds';
type DateString = `${number}-${number}-${number}` | `${number}/${number}/${number}`;
interface ImageData {
width: number;
height: number;
data: Uint8ClampedArray;
}
interface DotTextCanvasOptions {
text: string;
fontSize: number;
color: string;
fontWeight: number;
direction?: Direction;
isPreferred?: boolean;
charSpacing?: number;
charSpacings?: number[];
}
export type { BodyType as B, ChunkDetail as C, Direction as D, EventBus as E, FileSpliceOptions as F, IShellMessage as I, JSCookie as J, LRU as L, MaybeElement as M, NodeWorkerPayload as N, PkgTool as P, ResponseType as R, TimeUnit as T, UseTimeoutReturn as U, ISignature as a, DotTextCanvasOptions as b, ImageData as c, DateString as d, DragEvent as e, MutationObserverInit as f, IsESModule as g, DeviceType as h, ParsedURL as i, ChunkInfo as j, IFetchConfig as k, IFetchOptions as l, Position as m, Lang as n, TrimType as o, Redirect as p, Cache as q, Mode as r, Method as s, Credentials as t, IFetchInterceptors as u, FileType as v, FileMD5 as w, FileChunk as x, Deadline as y, Merge as z };