diff --git a/packages/changelog/src/core/github.api.ts b/packages/changelog/src/core/github.api.ts index a2b2bc56..4673a58a 100644 --- a/packages/changelog/src/core/github.api.ts +++ b/packages/changelog/src/core/github.api.ts @@ -1,5 +1,5 @@ import type { Commit, GitAuthorInfo } from '@142vip/changelog' -import { HttpMethod, VipColor, VipConsole, vipLogger, VipQs } from '@142vip/utils' +import { HttpMethod, VipColor, VipConsole, vipLogger, vipQs } from '@142vip/utils' import { $fetch } from 'ofetch' function getHeaders(token: string) { @@ -132,7 +132,7 @@ function generateReleaseUrl(markdown: string, config: { prerelease: boolean }): string { const baseUrl = `https://${config.baseUrl}/${config.repo}/releases/new` - const queryParams = VipQs.stringify({ + const queryParams = vipQs.stringify({ title: config.name || config.to, body: markdown, tag: config.to, diff --git a/packages/utils/src/pkgs/data-transform.ts b/packages/utils/src/pkgs/data-transform.ts new file mode 100644 index 00000000..0f98da5e --- /dev/null +++ b/packages/utils/src/pkgs/data-transform.ts @@ -0,0 +1,51 @@ +class VipDataTransform { + /** + * 字符串脱敏,生成指定长度的字符串,默认6位,默认模板:* + */ + public sensitiveStr(length?: number, template?: string): string { + return (template ?? '*').repeat(length ?? 6) + } + + /** + * 手机号脱敏 + */ + public sensitivePhoneNum(phone: string, template?: string): string { + const phoneStr = phone.trim() + const len = phoneStr.length + // 前3位、后4位,中间按照template模板加密,默认* + if (len > 7) { + return phoneStr.replace(/(\d{3})\d*(\d{4})/, `$1${this.sensitiveStr(len - 7, template)}$2`) + } + + return phoneStr + } + + // /** + // * jwt数据加密 + // * @param payload + // * @param secretOrPrivateKey + // * @param expiresIn + // */ + // public jwtEncrypt(payload: string | object, secretOrPrivateKey?: Secret | PrivateKey, expiresIn?: string | number): string { + // // 类型优化 + // return jwt.sign(payload, secretOrPrivateKey, { + // expiresIn, + // }) + // } + // + // /** + // * jwt数据解密 + // * @param data + // * @param cryptoKey + // */ + // public jwtDecrypt(data: string, secretOrPrivateKey: Secret | PrivateKey): string | object | null { + // try { + // return jwt.verify(data, secretOrPrivateKey) + // } + // catch { + // return null + // } + // } +} + +export const vipDataTransform = new VipDataTransform() diff --git a/packages/utils/src/pkgs/dayjs.ts b/packages/utils/src/pkgs/dayjs.ts index 0e7c8d60..1591dcc3 100644 --- a/packages/utils/src/pkgs/dayjs.ts +++ b/packages/utils/src/pkgs/dayjs.ts @@ -75,6 +75,14 @@ export class VipDayjs { public formatCurrentDateToStr(): string { return this.formatDateToStr(new Date(), this.FORMAT_TEMPLATE_STR) } + + /** + * 格式化时间为ISO字符串 + * @param date + */ + public formatToISOStr(date?: dayjs.ConfigType): string { + return dayjs(date).toISOString() + } } // 导出 diff --git a/packages/utils/src/pkgs/index.ts b/packages/utils/src/pkgs/index.ts index 3a29b4c7..a7ec1586 100644 --- a/packages/utils/src/pkgs/index.ts +++ b/packages/utils/src/pkgs/index.ts @@ -2,6 +2,7 @@ export * from './color' export * from './commander' export * from './config' export * from './console' +export * from './data-transform' export * from './dayjs' export * from './detect' export * from './inquirer' diff --git a/packages/utils/src/pkgs/qs.ts b/packages/utils/src/pkgs/qs.ts index fc5e3e1e..2d6ad286 100644 --- a/packages/utils/src/pkgs/qs.ts +++ b/packages/utils/src/pkgs/qs.ts @@ -1,21 +1,20 @@ import type { BooleanOptional, IParseOptions, IStringifyOptions, ParsedQs } from 'qs' import qs from 'qs' -/** - * 序列化 query string - */ -function stringify(obj: any, options?: IStringifyOptions): string { - return qs.stringify(obj, options) -} +export class VipQs { + /** + * 序列化 query string + */ + public stringify(obj: any, options?: IStringifyOptions): string { + return qs.stringify(obj, options) + } -/** - * 解析 query string - */ -function parse(str: string, options?: IParseOptions & { decoder?: never | undefined }): ParsedQs { - return qs.parse(str, options) + /** + * 解析 query string + */ + public parse(str: string, options?: IParseOptions & { decoder?: never | undefined }): ParsedQs { + return qs.parse(str, options) + } } -export const VipQs = { - stringify, - parse, -} +export const vipQs = new VipQs()