import ansiColors from 'ansi-colors'; import { ConfigType } from 'dayjs'; import _ from 'lodash'; import { IStringifyOptions, BooleanOptional, IParseOptions, ParsedQs } from 'qs'; import originImportSemVer, { ReleaseType, SemVer, RangeOptions } from 'semver'; import { load, loadAll } from 'js-yaml'; export { CliCommandBaseOptions, CpuArchitectureEnum, GitCommit, GitGeneralBranch, GitInfo, HttpMethod, HttpStatus, ProcessExitCodeEnum, RegistryAddressEnum, ReleaseVersionTypeEnum, TimeDurationMs, TimeDurationSec } from './enums/index.mjs'; /** * 博客站点的工具方法 */ declare class VipDocSite { /** * 默认的环境变量的键 */ readonly defaultEnvKey: string; /** * 用于区分base路径,是否nginx代理 * - 路径名称 * - 默认环境变量 NEED_PROXY * @param baseName 路径名称 * @param envKey 环境变量的键 */ getBase(baseName: string, envKey?: string): '/' | `/${string}/`; } /** * VipDocSite的快速初始化对象 */ declare const vipDocSite: VipDocSite; interface LoggerOptions { startLabel?: string; endLabel?: string; } /** * 日志对象构造参数 */ interface VipLoggerOptions { infoColor?: string; logColor?: string; errorColor?: string; } /** * 日志输出 * - 用于终端 * - 用于基本日志定位 */ declare class VipLogger { private static logger; constructor(_opts?: VipLoggerOptions); static getInstance(opts?: VipLoggerOptions): VipLogger; log(msg: string, opts?: LoggerOptions): void; error(msg: string, opts?: LoggerOptions): void; /** * 打印空行 */ println(): void; /** * 上下空行输出 */ logByBlank(message: string): void; } declare const vipLogger: VipLogger; /** * 参考:https://www.npmjs.com/package/ansi-colors */ /** * 终端修改颜色 */ declare const VipColor: typeof ansiColors; /** * 终端标记 */ declare const VipSymbols: { success: "√" | "✔"; error: "×" | "✖"; warning: "‼" | "⚠"; info: "i" | "ℹ"; question: "?"; heart: "❤"; mark: "※"; }; declare enum VipConsoleLogLevel { ERROR = "ERROR", SUCCESS = "SUCCESS", INFO = "INFO" } /** * 普通日志 */ declare function log(message?: string, level?: VipConsoleLogLevel): void; /** * 追踪日志,按照标准日志输出 */ declare function trace(...data: any): void; /** * 错误日志 */ declare function error(e: any): void; /** * 日志 */ declare const VipConsole: { log: typeof log; trace: typeof trace; error: typeof error; }; declare class VipDataTransform { /** * 字符串脱敏,生成指定长度的字符串,默认6位,默认模板:* */ sensitiveStr(length?: number, template?: string): string; /** * 手机号脱敏 */ sensitivePhoneNum(phone: string, template?: string): string; } declare const vipDataTransform: VipDataTransform; /** * dayjs 常用日期格式模板。 * 与 {@link VipDayjs} 配套使用,避免散落魔法字符串。 */ declare enum DateFormatTemplate { /** 年-月-日 时:分:秒 → 2024-08-09 15:20:30 */ DATETIME = "YYYY-MM-DD HH:mm:ss", /** 年-月-日 时:分 → 2024-08-09 15:20 */ DATETIME_MINUTE = "YYYY-MM-DD HH:mm", /** 年-月-日 → 2024-08-09 */ DATE = "YYYY-MM-DD", /** 年.月.日 → 2024.08.09 */ DATE_DOT = "YYYY.MM.DD", /** 年/月/日 → 2024/08/09 */ DATE_SLASH = "YYYY/MM/DD", /** 年月日(紧凑)→ 20240809 */ DATE_COMPACT = "YYYYMMDD", /** 年月日时分秒毫秒 → 20240809152030123 */ TIMESTAMP = "YYYYMMDDHHmmSSS", /** 年-月 → 2024-08 */ YEAR_MONTH = "YYYY-MM", /** 月-日 → 08-09 */ MONTH_DAY = "MM-DD", /** 月/日 → 08/09 */ MONTH_DAY_SLASH = "MM/DD", /** 月/日 时:分 → 08/09 15:20 */ MONTH_DAY_TIME = "MM/DD HH:mm", /** 中文月日 → 8月9日 */ MONTH_DAY_CN = "M\u6708D\u65E5", /** 英文月日 → Aug 9 */ MONTH_DAY_EN = "MMM D", /** 时:分:秒 → 15:20:30 */ TIME = "HH:mm:ss", /** 时:分 → 15:20 */ TIME_MINUTE = "HH:mm", /** 中文年月日 → 2024年08月09日 */ DATE_CN = "YYYY\u5E74MM\u6708DD\u65E5", /** 中文年月日 时:分:秒 → 2024年08月09日 15:20:30 */ DATETIME_CN = "YYYY\u5E74MM\u6708DD\u65E5 HH:mm:ss" } declare class VipDayjs { /** * 时间格式:年-月-日 时:分:秒 */ private readonly FORMAT_TEMPLATE_STR; /** * 时间戳格式:年月日时分秒毫秒 */ private readonly FORMAT_TEMPLATE_STR_TIMESTAMP; /** * 日期格式:年-月-日 */ private readonly FORMAT_TEMPLATE_STR_DATE; /** * 获取当前时间戳。单位:毫秒 */ getCurrentTimestamp(): number; /** * 获取时间戳。单位:毫秒 */ getTimestamp(date: ConfigType): number; /** * 获取过期时间戳。单位:毫秒 * @param duration 过期时间,默认:1小时 */ getExpiredTimestamp(duration?: number): number; /** * 是否在当前时间之前 * @param date */ isBeforeNow(date?: ConfigType): boolean; /** * 是否在当前时间之后 * @param date */ isAfterNow(date?: ConfigType): boolean; /** * 时间格式化,默认: 年-月-日 时:分:秒 */ formatDateToStr(date: ConfigType, template?: DateFormatTemplate | string): string; /** * 格式化为月日(时间轴标题等) * - 中文:`8月9日` * - 英文:`Aug 9` */ formatMonthDay(date: ConfigType, locale?: string): string; /** * 年月日格式化当前时间 * - 格式: 2024-08-09 */ formatCurrentDateToYMD(): string; /** * 时间戳格式化当前时间 * - 格式: 20240809152030123 */ formatCurrentDateToTimestamp(): string; /** * 时间格式化当前时间,默认: 年-月-日 时:分:秒 */ formatCurrentDateToStr(): string; /** * 格式化为 ISO-8601 字符串(UTC)。 * 用于 `meta.fetchedAt`、Token 过期时间等业务持久化字段。 */ formatToISOStr(date?: ConfigType): string; /** * 判断自 `anchorMs` 起是否仍在 `ttlMs` 有效期内(`now - anchorMs < ttlMs`)。 * 用于内存/Session 缓存、前端热数据节流等。 */ isBeforeByTtl(anchorMs: number, ttlMs: number, nowMs?: number): boolean; } /** VipDayjs 单例 */ declare const vipDayjs: VipDayjs; /** 外部 JSON 解析后的平面对象;键为 string,值为任意 JSON 可序列化类型 */ type JsonRecord = Record; type CompactFalsy = false | 0 | '' | null | undefined; declare function isJsonRecord(value: unknown): value is JsonRecord; declare function toJsonRecord(value: unknown): JsonRecord; declare function compactMap(collection: readonly T[] | null | undefined, iteratee: (item: T, index: number) => R): Array>; declare const lodashBase: _.Omit<_.LoDashStatic, "VERSION">; /** * 在 lodash 之上的扩展方法(命名勿与 lodash 原生冲突,避免覆盖 `pick` / `map` 等)。 */ declare const vipLodashExtensions: { readonly isJsonRecord: typeof isJsonRecord; readonly toJsonRecord: typeof toJsonRecord; readonly compactMap: typeof compactMap; }; type VipLodash = typeof lodashBase & typeof vipLodashExtensions; /** * lodash 二次封装:先展开 lodash 原生能力,再挂载扩展。 * 扩展键与 lodash 原生方法互斥;新增扩展前须确认 lodash 无同名导出。 */ declare const vipLodash: VipLodash; /** * 参考:https://github.com/ai/nanoid */ /** * 字符集 */ declare enum Alphabet { DEFAULT = "0123456789abcdefghijklmnopqrstuvwxyz", ONLY_NUMBER = "0123456789", ONLY_LOWER_CHAR = "abcdefghijklmnopqrstuvwxyz", ONLY_UPPER_CHAR = "ABCDEFGHIJKLMNOPQRSTUVWXYZ", ONLY_CHAR = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", COMPLEX = "-0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" } declare class VipNanoId { /** * 获取NanoId对象,默认字符集为 Alphabet.DEFAULT,只有小写字母和数字 * @param alphabet */ getNanoId(alphabet?: string): (size?: number) => string; /** * 获取随机字符串,默认长度21 * - 按照制定规则生成默认字符串 */ getRandomId(size?: number): string; /** * 获取纯数字的随机字符串 * @param size */ getRandomNumberId(size?: number): string; /** * 获取纯字母的随机字符串,包含小写字母和大写字母 * @param size */ getRandomCharId(size?: number): string; /** * 获取纯小写字母的随机字符串 * @param size */ getRandomLowerCharId(size?: number): string; /** * 获取纯大写字母的随机字符串 * @param size */ getRandomUpperCharId(size?: number): string; /** * 获取复杂的随机字符串,包含数字、小写字母、大写字母和特殊字符 * @param size */ getRandomComplexId(size?: number): string; } declare const vipNanoId: VipNanoId; declare class VipQs { /** * 序列化 query string */ stringify(obj: any, options?: IStringifyOptions): string; /** * 解析 query string */ parse(str: string, options?: IParseOptions & { decoder?: never | undefined; }): ParsedQs; } declare const vipQs: VipQs; type VipSemverReleaseType = ReleaseType; /** * 版本类型 */ type VipReleaseType = VipSemverReleaseType | 'next'; /** * 预发布版本类型 */ declare const prereleaseTypes: ReleaseType[]; /** * 所有可能的发布版本 */ declare const releaseTypes: VipReleaseType[]; /** * 支持原生创建Semver实例 */ declare function createSemver(version: string | SemVer, optionsOrLoose?: boolean | RangeOptions): SemVer; /** * Determines whether the specified value is a pre-release. */ declare function isPrereleaseType(value: ReleaseType): boolean; /** * Determines whether the specified value is a valid ReleaseType string. */ declare function isReleaseType(value: ReleaseType): boolean; interface NextVersion { major: string; minor: string; patch: string; preMajor: string; preMinor: string; prePatch: string; next: string; } /** * 获取下一个版本 */ declare function getNextVersions(currentVersion: string, preid?: string): NextVersion | null; /** * 参考:https://www.npmjs.com/package/semver */ declare const VipSemver: { valid: typeof originImportSemVer.valid; clean: typeof originImportSemVer.clean; satisfies: typeof originImportSemVer.satisfies; gt: typeof originImportSemVer.gt; lt: typeof originImportSemVer.lt; eq: typeof originImportSemVer.eq; inc: typeof originImportSemVer.inc; parse: typeof originImportSemVer.parse; compare: typeof originImportSemVer.compare; prerelease: typeof originImportSemVer.prerelease; createSemver: typeof createSemver; originImportSemVer: typeof originImportSemVer; getNextVersions: typeof getNextVersions; isPrereleaseType: typeof isPrereleaseType; isReleaseType: typeof isReleaseType; }; declare const VipYaml: { load: typeof load; loadAll: typeof loadAll; }; export { Alphabet, DateFormatTemplate, type JsonRecord, type LoggerOptions, type NextVersion, VipColor, VipConsole, VipConsoleLogLevel, VipDayjs, VipDocSite, type VipLodash, VipLogger, type VipLoggerOptions, VipNanoId, VipQs, type VipReleaseType, VipSemver, type VipSemverReleaseType, VipSymbols, VipYaml, prereleaseTypes, releaseTypes, vipDataTransform, vipDayjs, vipDocSite, vipLodash, vipLogger, vipNanoId, vipQs };