Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/changelog/src/core/github.api.ts
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down Expand Up @@ -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,
Expand Down
51 changes: 51 additions & 0 deletions packages/utils/src/pkgs/data-transform.ts
Original file line number Diff line number Diff line change
@@ -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()
8 changes: 8 additions & 0 deletions packages/utils/src/pkgs/dayjs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}

// 导出
Expand Down
1 change: 1 addition & 0 deletions packages/utils/src/pkgs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
29 changes: 14 additions & 15 deletions packages/utils/src/pkgs/qs.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
import type { BooleanOptional, IParseOptions, IStringifyOptions, ParsedQs } from 'qs'
import qs from 'qs'

/**
* 序列化 query string
*/
function stringify(obj: any, options?: IStringifyOptions<BooleanOptional>): string {
return qs.stringify(obj, options)
}
export class VipQs {
/**
* 序列化 query string
*/
public stringify(obj: any, options?: IStringifyOptions<BooleanOptional>): string {
return qs.stringify(obj, options)
}

/**
* 解析 query string
*/
function parse(str: string, options?: IParseOptions<BooleanOptional> & { decoder?: never | undefined }): ParsedQs {
return qs.parse(str, options)
/**
* 解析 query string
*/
public parse(str: string, options?: IParseOptions<BooleanOptional> & { decoder?: never | undefined }): ParsedQs {
return qs.parse(str, options)
}
}

export const VipQs = {
stringify,
parse,
}
export const vipQs = new VipQs()
Loading