export declare const contentLimitLength: (content: string) => boolean; export declare const rid: () => string; /** * UUID v4 生成器 * 符合 RFC 4122 标准 */ /** * 随机数生成器函数类型 */ type RandomBytesGenerator = () => Uint8Array; /** * UUID 生成选项 */ interface UuidOptions { /** 自定义随机数生成器 */ random?: RandomBytesGenerator; /** 自定义 RNG 函数(random 的别名) */ rng?: RandomBytesGenerator; } /** * 浏览器 Crypto API 类型 */ interface CryptoAPI { getRandomValues(array: T): T; } /** * 生成16个随机字节 * @returns 包含16个随机字节的 Uint8Array */ declare function generateRandomBytes(): Uint8Array; /** * 将16字节数组转换为标准UUID字符串格式 * @param bytes - 16字节数组 * @param offset - 起始偏移量(默认为0) * @returns 标准UUID字符串(小写) * @throws 当生成的字符串格式无效时抛出 TypeError */ declare function bytesToUuid(bytes: Uint8Array, offset?: number): string; /** * 生成 UUID v4 * @param options - 配置选项,可自定义随机数生成器 * @param buffer - 可选的目标缓冲区(用于避免内存分配,提升性能) * @param bufferOffset - 在目标缓冲区中的起始位置(默认为0) * @returns UUID字符串(当未提供buffer时)或填充后的Uint8Array(当提供buffer时) * * @example * // 基础用法,返回字符串 * const id: string = uuidv4(); * * @example * // 高性能用法,复用缓冲区 * const buffer = new Uint8Array(16); * uuidv4({}, buffer, 0); * // buffer 现在包含原始字节 */ declare function uuidv4(options?: UuidOptions, buffer?: Uint8Array | null, bufferOffset?: number): string | Uint8Array; export { uuidv4, bytesToUuid, generateRandomBytes }; export type { UuidOptions, RandomBytesGenerator }; declare global { /** IE/Edge 旧版 crypto 对象 */ var msCrypto: CryptoAPI | undefined; }