//#region src/types/function.d.ts /** 指定参数和返回值的函数 */ type TypedFunction = (...args: Args) => R; /** 任意函数 */ type AnyFunction = (...args: any[]) => any; /** 任意返回 Promise 的函数 */ type AsyncFunction = (...args: any[]) => Promise; /** 无参数回调 */ type Callback = () => void; /** 类构造函数类型(可实例化) */ type Class = new (...args: any[]) => T; /** 类构造函数类型(支持抽象类) */ type AbstractClass = abstract new (...args: any[]) => T; /** 同步或异步值 */ type MaybePromise = T | Promise; /** 提取 Promise 返回值类型 */ type PromiseReturnType = Awaited>; /** 取第 N 个参数类型定义 */ type ParamAtSafe = Parameters extends { [K in I]: infer R; } ? R : never; /** 参数类型与原函数一致;返回值变为 Promise<原返回类型> */ type Promisified = (...args: Parameters) => Promise>; /** 将对象中的所有函数类型转换为异步函数 */ type Asyncify = { [K in keyof T]: T[K] extends ((...args: infer A) => infer R) ? (...args: A) => Promise> : T[K]; }; //#endregion //#region src/types/key.d.ts /** 提取指定类型 T 的 keys */ type KeysOf = keyof T; /** 提取 string 类型的 keys */ type StringKeyOf = Extract; /** 所有方法的键名 */ type MethodsOf = { [P in keyof T]: T[P] extends AnyFunction ? P : never; }[keyof T]; /** 同步方法(不返回 Promise)的键名 */ type SyncMethodsOf = { [P in keyof T]: T[P] extends AsyncFunction ? never : T[P] extends AnyFunction ? P : never; }[keyof T]; /** 异步方法的键名 */ type AsyncMethodsOf = { [P in keyof T]: T[P] extends AsyncFunction ? P : never; }[keyof T]; /** 普通字段的键名 */ type FieldKeysOf = { [P in keyof T]: T[P] extends AnyFunction ? never : P; }[keyof T]; //#endregion //#region src/types/primitive.d.ts /** TS 原始数据类型 */ type Primitive = string | number | boolean | bigint | symbol | null | undefined; /** TS 内置数据类型 */ type Builtin = Primitive | Date | RegExp | Error | Map | Set | WeakMap | WeakSet; //#endregion //#region src/types/object.d.ts /** 简化包装类型 */ type Simplify = { [K in keyof T]: T[K]; } & {}; /** 移除 readonly 修饰符 */ type Mutable = { -readonly [K in keyof T]: T[K]; }; /** 指定属性可选 */ type MarkOptional = Simplify, K> & Omit>; /** 指定属性必填 */ type MarkRequired = Simplify, K> & Omit>; /** 至少包含一个属性(非空对象约束) */ type RequireAtLeastOne = { [K in keyof T]-?: Simplify> & Partial>>>; }[keyof T]; /** 对象类型转可索引对象类型 */ type Indexable = { [K in keyof T]: T[K]; }; /** 递归 Partial */ type DeepPartial = T extends Builtin ? T : T extends AnyFunction ? T : T extends readonly [...infer U] ? { [K in keyof U]?: DeepPartial; } : T extends readonly (infer U)[] ? DeepPartial[] : T extends object ? { [K in keyof T]?: DeepPartial; } : T; /** 递归 Required */ type DeepRequired = T extends Builtin ? T : T extends AnyFunction ? T : T extends readonly [...infer U] ? { [K in keyof U]-?: DeepRequired; } : T extends readonly (infer U)[] ? DeepRequired[] : T extends object ? { [K in keyof T]-?: DeepRequired; } : T; /** 以字符串为键的字典对象 */ type Dict = Record; //#endregion //#region src/types/pick.d.ts /** 所有函数成员 */ type PickMethods = { [P in keyof T as T[P] extends AnyFunction ? P : never]: T[P]; }; /** 同步函数成员 * @see Omit, AsyncMethodsOf> */ type PickSyncMethods = { [P in keyof T as T[P] extends AsyncFunction ? never : T[P] extends AnyFunction ? P : never]: T[P]; }; /** 异步函数成员 */ type PickAsyncMethods = { [P in keyof T as T[P] extends AsyncFunction ? P : never]: T[P]; }; /** 普通字段成员 * @see Pick> */ type PickFields = { [P in keyof T as T[P] extends AnyFunction ? never : P]: T[P]; }; //#endregion //#region src/functions/is.d.ts /** 判断一个值是否为 Object(非 null) */ declare const isObject: (v: unknown) => v is object; /** 判断一个值是否不是 Object */ declare const isNotObject: (v: unknown) => boolean; /** 判断一个值是否为普通对象({} 或 Object.create(null)) */ declare const isPlainObject: (v: unknown) => v is object; /** 判断一个值是否为函数 */ declare const isFunction: (v: unknown) => v is AnyFunction; /** 判断一个值是否为同步函数(即 `[object Function]`) */ declare const isSyncFunction: (v: unknown) => boolean; /** 判断一个值是否为异步函数(即 `[object AsyncFunction]`) */ declare const isAsyncFunction: (v: unknown) => v is AsyncFunction; /** 安全判断对象是否为特定类实例 */ declare const isInstanceOf: (v: unknown, ctor: AbstractClass) => v is T; /** 判断一个值是否为布尔值 */ declare const isBoolean: (v: unknown) => v is boolean; /** 判断一个值是否为字符串 */ declare const isString: (v: unknown) => v is string; /** 判断值是否为数字类型 */ declare const isNumber: (v: unknown) => v is number; /** 判断一个值是否为 bigint */ declare const isBigInt: (v: unknown) => v is bigint; /** 判断是否为有限数字 */ declare const isFinite: (v: unknown) => v is number; /** 判断是否为整数 */ declare const isInteger: (v: unknown) => v is number; /** 判断是否为正数 */ declare const isPositive: (v: unknown) => v is number; /** 判断一个值是否为 symbol */ declare const isSymbol: (v: unknown) => v is symbol; /** 判断一个值是否为原始类型 */ declare const isPrimitive: (v: unknown) => v is Primitive; /** 判断一个值是否为数组 */ declare const isArray: (v: unknown) => v is unknown[]; /** 判断一个值是否为有效日期 */ declare const isDate: (v: unknown) => v is Date; /** 判断一个值是否为正则 */ declare const isRegExp: (v: unknown) => v is RegExp; /** 判断一个值是否为 Promise */ declare const isPromise: (v: unknown) => v is Promise; /** 判断一个值是否可以使用 new 调用 */ declare const isNewable: (v: unknown) => v is Class; /** 判断一个值是否为 Map */ declare const isMap: (v: unknown) => v is Map; /** 判断一个值是否为 Set */ declare const isSet: (v: unknown) => v is Set; /** undefined 值判断 */ declare const isUndefined: (v: unknown) => v is undefined; /** null 值判断 */ declare const isNull: (v: unknown) => v is null; /** 断值不是 null/undefined */ declare const isNonNullable: (v: unknown) => v is {}; /** 断值是不是 null/undefined */ declare const isNullable: (v: unknown) => v is null | undefined; /** 0 值判断 */ declare const isZero: (v: number) => v is 0; /** 数组索引值判断 */ declare const isIndex: (v: number) => boolean; /** 判断对象是否为空对象(无自身属性) */ declare const isEmptyObject: (v: unknown) => boolean; /** 判断字符串是否为空 */ declare const isEmptyString: (v: unknown) => boolean; /** 判断数组是否为空 */ declare const isEmptyArray: (v: unknown) => boolean; /** 判断字符串是否为空白 */ declare const isBlankString: (v: unknown) => boolean; /** 判断 Map 是否为空 */ declare const isEmptyMap: (v: unknown) => boolean; /** 判断 Set 是否为空 */ declare const isEmptySet: (v: unknown) => boolean; /** 断值是不是空 */ declare const isEmpty: (v: unknown) => boolean; /** 断值是不是非空 */ declare const isNotEmpty: (v: unknown) => boolean; //#endregion //#region src/functions/number.d.ts /** 创建范围随机整数函数 */ declare const createRandom: (rng?: () => number) => (min: number, max: number) => number; /** 范围随机整数 */ declare const randomInt: (min: number, max: number) => number; /** 四舍五入 */ declare const round: (value: number, digits?: number) => number; /** 判断值是否处于范围内(包含边界) */ declare const isBetween: (value: number, min: number, max: number) => boolean; //#endregion //#region src/functions/string.d.ts /** 大写字符串的首字符 */ declare const upperFirst: (string: string) => string; /** 多空格函数 */ declare const space: (n?: number) => string; /** 去掉模板首尾空行 */ declare const trimTemplate: (str: string) => string; /** 按行拆分 */ declare const splitLines: (text: string) => string[]; /** 按行拆分(过滤空行) */ declare const splitNonEmptyLines: (text: string) => string[]; /** 折叠连续空白行 */ declare const collapseBlankLines: (str: string, opts?: { threshold?: number; preserve?: number; }) => string; /** 生成一个或多个换行 */ declare const newline: (n?: number) => string; /** 消除缩进 */ declare const dedent: (str: string) => string; //#endregion //#region src/functions/object.d.ts /** 安全转换对象为特定类实例 */ declare const asInstanceOf: (obj: unknown, ctor: AbstractClass) => T | undefined; /** 运行时删除对象指定属性(浅拷贝) */ declare const omit: (obj: T, keys: K) => Simplify>; /** 运行时挑选对象指定属性(浅拷贝) */ declare const pick: (obj: T, keys: K) => Simplify>; /** 获取对象原始类型字符串 */ declare const toRawString: (self: unknown) => string; /** @deprecated Use toRawString instead. */ declare const toString: (self: unknown) => string; /** 获取值的类型标签 */ declare const getTag: (self: unknown) => string; /** 类型化实体 */ declare const typedEntries: (obj: T) => { [P in StringKeyOf]: [P, T[P]]; }[StringKeyOf][]; /** 映射对象的键和值,并返回新的对象 */ declare const mapObject: , S extends Extract = Extract, R extends PropertyKey = S, V = unknown>(obj: T, mapper:

(key: P, value: T[P]) => [R, V], keys?: readonly S[]) => { [P in R]: V; }; /** 将点分隔路径转换为键数组,支持使用 `\.` 转义点号 */ declare const pathToKeys: (path: string) => string[]; /** 根据键路径删除对象的嵌套属性 */ declare const deleteProperty: (object: Dict, keys: readonly string[]) => boolean; /** 根据点分隔路径删除对象的嵌套属性 */ declare const unset: (object: Dict, path: string) => boolean; /** 根据键路径设置对象的嵌套属性 */ declare const setProperty: (object: Dict, keys: readonly string[], value: unknown) => boolean; /** 根据点分隔路径设置对象的嵌套属性 */ declare const set: (object: Dict, path: string, value: unknown) => boolean; /** 根据键路径获取对象的嵌套属性 */ declare const getProperty: (object: Dict, keys: readonly string[]) => V | undefined; /** 根据点分隔路径获取对象的嵌套属性 */ declare const get: (object: Dict, path: string) => V | undefined; /** 克隆实例 */ declare const cloneInstance: (inst: T) => T; //#endregion //#region src/functions/array.d.ts /** 参数数组化 */ declare const castArray: (v: T | readonly T[]) => T[]; /** 过滤数组中的 undefined 值 */ declare const nonUndefined: (arr: readonly T[]) => Exclude[]; /** 过滤数组中的 null 值 */ declare const nonNull: (arr: readonly T[]) => Exclude[]; /** 过滤数组中的 null 和 undefined 值 */ declare const nonNullable: (arr: readonly T[]) => NonNullable[]; /** 按固定大小分组数组元素 */ declare const chunk: (arr: readonly T[], size: number) => T[][]; /** 按固定间隔替换数组元素 */ declare const replaceEvery: (arr: readonly T[], step: number, val: V) => (T | V)[]; declare const partition: (arr: readonly T[], predicate: (item: T) => boolean) => [T[], T[]]; //#endregion //#region src/functions/binary.d.ts /** ArrayBuffer → Uint8Array (copy-safe) */ declare const arrayBufferToUint8: (data: ArrayBuffer) => Uint8Array; /** Uint8Array → ArrayBuffer (copy-safe) */ declare const uint8ToArrayBuffer: (data: Uint8Array) => ArrayBuffer; /** 复制为 uint8 */ declare const safeUint8: (data: ArrayBuffer | Uint8Array) => Uint8Array; //#endregion //#region src/functions/compare.d.ts /** 判断两个值相等 */ declare const equals: (a: A, b: B) => boolean; /** 判断两个值不等 */ declare const notEquals: (a: A, b: B) => boolean; /** 判断两个数组内容是否相同 */ declare const arrayEquals: (a1: readonly T[], a2: readonly T[], key?: (item: T) => K) => boolean; //#endregion //#region src/functions/function.d.ts /** 仅执行一次的方法 */ declare const once: (fn: (...args: Args) => R) => (...args: Args) => R; /** 仅执行一次的异步方法 */ declare const onceAsync: (fn: (...args: Args) => Promise) => (...args: Args) => Promise; /** 同步函数转为异步 */ declare const promisify: (fn: T) => Promisified; /** 安全调用函数,异常时返回 undefined */ declare const tryCall: (fn: () => MaybePromise, fallback: F | ((error: unknown) => F)) => Promise; /** {@link tryCall} 的同步版本 */ declare const tryCallSync: (fn: () => T, fallback: F | ((error: unknown) => F)) => T | F; /** 判断函数执行是否成功 */ declare const isSuccess: (fn: () => MaybePromise) => Promise; /** {@link isSuccess} 的同步版本 */ declare const isSuccessSync: (fn: () => unknown) => boolean; //#endregion //#region src/functions/async.d.ts /** 延后执行 */ declare const sleep: (ms: number) => Promise; //#endregion //#region src/functions/url.d.ts /** https:// 或 http:// */ declare const isHttpUrl: (url: string) => boolean; /** file:// */ declare const isFileUrl: (url: string) => boolean; /** /page 或 #/page */ declare const isInternalRoute: (url: string) => boolean; /** localhost 或 127.0.0.1 或 [::1] */ declare const isLocalhost: (url: string) => boolean; //#endregion //#region src/functions/color.d.ts declare namespace channel { const random: () => number; const dark: () => number; const light: () => number; } declare namespace alpha { const random: () => number; const visible: () => number; const opaque: () => number; const solid: () => number; } declare namespace hex { const random: (r: () => number) => `#${string}`; const randomColor: () => `#${string}`; const randomDarkColor: () => `#${string}`; const randomLightColor: () => `#${string}`; const is: (color: string) => boolean; } declare namespace hexa { const random: (r: () => number, a: () => number) => `#${string}`; const randomColor: () => `#${string}`; const randomDarkColor: () => `#${string}`; const randomLightColor: () => `#${string}`; const is: (color: string) => boolean; } declare namespace rgb { const random: (r: () => number) => `rgb(${string})`; const randomColor: () => `rgb(${string})`; const randomDarkColor: () => `rgb(${string})`; const randomLightColor: () => `rgb(${string})`; const is: (color: string) => boolean; } declare namespace rgba { const random: (r: () => number, a: () => number) => `rgba(${string})`; const randomColor: () => `rgba(${string})`; const randomDarkColor: () => `rgba(${string})`; const randomLightColor: () => `rgba(${string})`; const is: (color: string) => boolean; } //#endregion //#region src/functions/error.d.ts /** 抛出错误 */ declare const throwError: (err: string | Error) => never; /** 断言 */ declare const assert: (value: unknown, message?: string | Error) => asserts value; /** 获取当前调用堆栈 */ declare const getCallStack: () => string[]; //#endregion //#region src/constants/mime.d.ts declare const MimeType: { readonly TEXT: "text/plain"; readonly CSV: "text/csv"; readonly HTML: "text/html"; readonly CSS: "text/css"; readonly MARKDOWN: "text/markdown"; readonly JSON: "application/json"; readonly XML: "application/xml"; readonly WASM: "application/wasm"; readonly PNG: "image/png"; readonly JPEG: "image/jpeg"; readonly GIF: "image/gif"; readonly WEBP: "image/webp"; readonly SVG: "image/svg+xml"; readonly BMP: "image/bmp"; readonly MP3: "audio/mpeg"; readonly WAV: "audio/wav"; readonly OGG_AUDIO: "audio/ogg"; readonly MP4: "video/mp4"; readonly WEBM_VIDEO: "video/webm"; readonly PDF: "application/pdf"; readonly RTF: "application/rtf"; readonly DOC: "application/msword"; readonly XLS: "application/vnd.ms-excel"; readonly PPT: "application/vnd.ms-powerpoint"; readonly DOCX: "application/vnd.openxmlformats-officedocument.wordprocessingml.document"; readonly XLSX: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; readonly PPTX: "application/vnd.openxmlformats-officedocument.presentationml.presentation"; readonly ZIP: "application/zip"; readonly GZIP: "application/gzip"; readonly RAR: "application/vnd.rar"; readonly SEVEN_ZIP: "application/x-7z-compressed"; readonly OCTET_STREAM: "application/octet-stream"; }; type MimeType = typeof MimeType[keyof typeof MimeType]; //#endregion export { type AbstractClass, type AnyFunction, type AsyncFunction, type AsyncMethodsOf, type Asyncify, type Builtin, type Callback, type Class, type DeepPartial, type DeepRequired, type Dict, type FieldKeysOf, type Indexable, type KeysOf, type MarkOptional, type MarkRequired, type MaybePromise, type MethodsOf, MimeType, type Mutable, type ParamAtSafe, type PickAsyncMethods, type PickFields, type PickMethods, type PickSyncMethods, type Primitive, type PromiseReturnType, type Promisified, type RequireAtLeastOne, type Simplify, type StringKeyOf, type SyncMethodsOf, type TypedFunction, alpha, arrayBufferToUint8, arrayEquals, asInstanceOf, assert, castArray, channel, chunk, cloneInstance, collapseBlankLines, createRandom, dedent, deleteProperty, equals, get, getCallStack, getProperty, getTag, hex, hexa, isArray, isAsyncFunction, isBetween, isBigInt, isBlankString, isBoolean, isDate, isEmpty, isEmptyArray, isEmptyMap, isEmptyObject, isEmptySet, isEmptyString, isFileUrl, isFinite, isFunction, isHttpUrl, isIndex, isInstanceOf, isInteger, isInternalRoute, isLocalhost, isMap, isNewable, isNonNullable, isNotEmpty, isNotObject, isNull, isNullable, isNumber, isObject, isPlainObject, isPositive, isPrimitive, isPromise, isRegExp, isSet, isString, isSuccess, isSuccessSync, isSymbol, isSyncFunction, isUndefined, isZero, mapObject, newline, nonNull, nonNullable, nonUndefined, notEquals, omit, once, onceAsync, partition, pathToKeys, pick, promisify, randomInt, replaceEvery, rgb, rgba, round, safeUint8, set, setProperty, sleep, space, splitLines, splitNonEmptyLines, throwError, toRawString, toString, trimTemplate, tryCall, tryCallSync, typedEntries, uint8ToArrayBuffer, unset, upperFirst };