/** * Copyright 2007 - 2025 MAIYUN.NET * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ export interface IClassPrototype { 'method': Record; 'access': Record; } /** * --- 完整的克隆一份数组/对象 --- * @param obj 要克隆的对象 */ export declare function clone(obj: T): T; /** * --- 获取 class 的所有 method 和 get/set --- * @param obj 实例化 class 对象 * @param over 不传入此参数 * @param level 不传入此参数 */ export declare function getClassPrototype(obj: object, over?: string[], level?: number): IClassPrototype; /** * --- 等待毫秒 --- * @param ms 等待的毫秒,默认 0 */ export declare function sleep(ms?: number): Promise; /** * --- 生成范围内的随机数 --- * @param min >= 最小值 * @param max <= 最大值 * @param prec 保留几位小数 */ export declare function rand(min: number, max: number, prec?: number): number; export declare const RANDOM_N = "0123456789"; export declare const RANDOM_U = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; export declare const RANDOM_L = "abcdefghijklmnopqrstuvwxyz"; export declare const RANDOM_UN: string; export declare const RANDOM_LN: string; export declare const RANDOM_LU: string; export declare const RANDOM_LUN: string; export declare const RANDOM_V = "ACEFGHJKLMNPRSTWXY34567"; export declare const RANDOM_LUNS: string; export declare function random(length?: number, source?: string, block?: string): string; /** * --- 根据参数获取最终的布尔值 --- * @param param 参数 */ export declare function getBoolean(param: boolean | string | number | undefined): boolean; /** * --- 根据参数获取最终的数字型 --- * @param param 参数 */ export declare function getNumber(param: string | number): number; /** * --- 根据参数获取最终的数组型,可传入类似 [1,2,3] 或 1,2,3 --- * @param param 参数 */ export declare function getArray(param: string | any[]): any[]; /** --- 获取数字的单纯小数点部分 --- */ export declare function getDecimal(number: number): number; /** * --- 转义 HTML --- * @param html HTML 字符 */ export declare function escapeHTML(html: string): string; /** * --- 还原转义后的 HTML --- * @param html 已转义的 HTML 字符 */ export declare function unescapeHTML(html: string): string; /** * --- 发起一个网络请求,若是返回值是 JSON 则自动解析,否则直接返回字符串 --- * @param url 网址 * @param opt 选项 */ export declare function request(url: string, opt: IRequestOptions): Promise; /** * --- 发起 fetch 请求 --- * @param url 网址 * @param init 选项 * @returns 文本或二进制数据,失败时返回 null */ export declare function fetch(url: string, init?: RequestInit): Promise; /** * --- 发起 GET 请求 --- * @param url 网址 * @param init 选项 * @param opt 选项 * @returns 文本或二进制数据,失败时返回 null */ export declare function get(url: string, init?: RequestInit, opt?: { /** --- 重试次数,默认 3 次 --- */ 'retry'?: number; }): Promise; /** * --- 发起 POST 请求 --- * @param url 网址 * @param data 数据 * @param init 选项 * @returns 文本或二进制数据,失败时返回 null */ export declare function post(url: string, data: Record | FormData, init?: RequestInit): Promise; /** * --- 发起 GET 请求并解析 JSON 响应 --- * @param url 网址 * @param init 选项 * @returns JSON 数据,失败时返回 null */ export declare function getResponseJson(url: string, init?: RequestInit): Promise; /** * --- 发起 POST 请求并解析 JSON 响应 --- * @param url 网址 * @param data 数据 * @param init 选项 * @returns JSON 数据,失败时返回 null */ export declare function postResponseJson(url: string, data: Record | FormData, init?: RequestInit): Promise; /** * --- 传输 url 并解析为 IUrl 对象 --- * @param url url 字符串 */ export declare function parseUrl(url: string): IUrl; /** * --- 将相对路径根据基准路径进行转换 --- * @param from 基准路径 * @param to 相对路径 */ export declare function urlResolve(from: string, to: string): string; /** --- 处理 URL 中的 .. / . 等 --- */ export declare function urlAtom(url: string): string; /** * --- 将 blob 对象转换为 text --- * @param blob 对象 */ export declare function blob2Text(blob: Blob): Promise; /** * --- 将 blob 对象转换为 base64 url --- * @param blob 对象 */ export declare function blob2DataUrl(blob: Blob): Promise; /** --- 将秒数格式化为 0:0:0 的字符串 --- */ export declare function formatSecond(second: number): string; /** * --- 将日期对象或毫秒级时间戳转换为字符串 --- * @param ts 时间戳或日期对象 * @param tz 传入要显示的时区,小时,如 8,默认以当前客户端时区为准 */ export declare function formatTime(ts: number | Date, tz?: number): { 'date': string; 'time': string; 'zone': string; }; /** * --- 将对象转换为 query string --- * @param query 要转换的对象 */ export declare function queryStringify(query: Record): string; /** * --- 将 query string 转换为对象 --- * @param query 要转换的字符串 */ export declare function queryParse(query: string): Record; /** * --- 是否是邮件地址 --- * @param email */ export declare function isEMail(email: string): boolean; /** * --- 是否是 IPv4 --- * @param ip */ export declare function isIPv4(ip: string): boolean; /** * --- 是否是 IPv6 --- * @param ip */ export declare function isIPv6(ip: string): boolean; /** * --- 判断是否是域名 --- * @param domain 域名 * @return bool */ export declare function isDomain(domain: string): boolean; /** * --- 判断手机号是否是 11 位,不做真实性校验 --- * @param p 手机号 */ export declare function isPhoneCN(p: string): boolean; /** * --- 去除 html 的空白符、换行以及注释 --- * @param text 要纯净的字符串 */ export declare function purify(text: string): string; /** * --- 加载脚本 --- * @param url 脚本网址 */ export declare function loadScript(url: string): Promise; /** * --- 批量加载 js 文件 --- * @param urls js 文件列表 * @param opt 选项 */ export declare function loadScripts(urls: string[], opt?: { loaded?: (url: string, state: number) => void; }): Promise; /** * --- 加载 css 文件 --- * @param url css 文件网址 * @returns 加载是否成功 */ export declare function loadLink(url: string, pos?: 'before' | 'after'): Promise; /** * --- 批量加载 css 文件 --- * @param urls css 文件列表 * @param opt 选项 */ export declare function loadLinks(urls: string[], opt?: { loaded?: (url: string, state: number) => void; }): Promise; /** --- 网址对象 --- */ export interface IUrl { 'auth': string | null; 'hash': string | null; 'host': string | null; 'hostname': string | null; 'pass': string | null; 'path': string | null; 'pathname': string; 'protocol': string | null; 'port': string | null; 'query': string | null; 'user': string | null; } export interface IRequestOptions { 'credentials'?: boolean; 'method'?: 'GET' | 'POST'; 'body'?: FormData; 'timeout'?: number; 'responseType'?: XMLHttpRequestResponseType; 'headers'?: HeadersInit; uploadStart?: (total: number) => void | Promise; uploadProgress?: (loaded: number, total: number) => void | Promise; uploadEnd?: () => void | Promise; start?: (total: number) => void | Promise; end?: () => void | Promise; progress?: (loaded: number, total: number) => void | Promise; load?: (res: any) => void | Promise; error?: () => void | Promise; }