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/changelog.api.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { ChangelogCliOptions, ChangelogGenerateOptions, GenerateChangelogResult } from '../enums'
import { parseCliOptions } from '@142vip/changelog'
import { VipColor, VipConsole, VipDayjs, VipGit, vipLogger, VipNodeJS } from '@142vip/utils'
import { VipColor, VipConsole, vipDayjs, VipGit, vipLogger, VipNodeJS } from '@142vip/utils'
import { GitCommitAPI } from './git-commit.api'
import { GithubAPI } from './github.api'

Expand Down Expand Up @@ -58,7 +58,7 @@ async function upsertChangelogDoc(
}

// 添加版本头部
const newMd = `## ${releaseVersionName} (${VipDayjs.formatDateToYMD()})\n\n${markdown}`
const newMd = `## ${releaseVersionName} (${vipDayjs.formatDateToYMD()})\n\n${markdown}`

const lastEntry = changelogMD.match(/^##\s+(?:\S.*)?$/m)

Expand Down
9 changes: 9 additions & 0 deletions packages/utils/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@

All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

## v0.0.1-alpha.43 (2025-11-06)

### 💅 Refactors

- 优化`VipDayjs`类核心逻辑,支持`vipDayjs`对象导出 &nbsp;-&nbsp; by **142vip.cn** in https://github.com/142vip/core-x/issues/732 [<samp>(b7c12)</samp>](https://github.com/142vip/core-x/commit/b7c12ee8)
- 优化`VipNanoId`类核心逻辑 &nbsp;-&nbsp; by **142vip.cn** in https://github.com/142vip/core-x/issues/733 [<samp>(caa65)</samp>](https://github.com/142vip/core-x/commit/caa6536b)

**Release New Version v0.0.1-alpha.43 [👉 View New Package On NPM](https://www.npmjs.com/package/@142vip/utils)**

## v0.0.1-alpha.42 (2025-10-16)

### ✨ Features
Expand Down
2 changes: 1 addition & 1 deletion packages/utils/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@142vip/utils",
"type": "module",
"version": "0.0.1-alpha.42",
"version": "0.0.1-alpha.43",
"private": false,
"description": "通用型基础工具集合,对常用模块的二次集成",
"author": "mmdapl <mmdapl@163.com>",
Expand Down
78 changes: 50 additions & 28 deletions packages/utils/src/pkgs/dayjs.ts
Original file line number Diff line number Diff line change
@@ -1,34 +1,56 @@
import dayjs from 'dayjs'

/**
* 时间格式:年-月-日 时:分:秒
*/
const FormatTemplateStr = 'YYYY-MM-DD HH:mm:ss'
/**
* 获取当前时间戳
*/
function getCurrentTimestamp() {
return dayjs().valueOf()
}
export class VipDayjs {
/**
* 时间格式:年-月-日 时:分:秒
*/
private readonly FORMAT_TEMPLATE_STR = 'YYYY-MM-DD HH:mm:ss'
/**
* 获取当前时间戳。单位:毫秒
*/
public getCurrentTimestamp(): number {
return dayjs().valueOf()
}

/**
* 时间格式化,默认: 年-月-日 时:分:秒
*/
function formatDateToStr(date: Date, template?: string) {
return dayjs(date).format(template ?? FormatTemplateStr)
}
/**
* 获取过期时间戳。单位:毫秒
* @param duration 过期时间,默认:1小时
*/
public getExpiredTimestamp(duration = 60 * 60 * 1000): number {
return this.getCurrentTimestamp() + duration
}

/**
* 年月日格式化当前时间
* - 格式: 2024-08-09
*/
function formatDateToYMD(): string {
return formatDateToStr(new Date(), 'YYYY-MM-DD')
}
/**
* 是否在当前时间之前
* @param date
*/
public isBeforeNow(date: Date): boolean {
return dayjs().isBefore(dayjs(date))
}

export const VipDayjs = {
getCurrentTimestamp,
FormatTemplateStr,
formatDateToStr,
formatDateToYMD,
/**
* 是否在当前时间之后
* @param date
*/
public isAfterNow(date: Date): boolean {
return dayjs().isAfter(dayjs(date))
}

/**
* 时间格式化,默认: 年-月-日 时:分:秒
*/
public formatDateToStr(date: Date, template?: string): string {
return dayjs(date).format(template ?? this.FORMAT_TEMPLATE_STR)
}

/**
* 年月日格式化当前时间
* - 格式: 2024-08-09
*/
public formatDateToYMD(): string {
return this.formatDateToStr(new Date(), 'YYYY-MM-DD')
}
}

// 导出
export const vipDayjs = new VipDayjs()
61 changes: 40 additions & 21 deletions packages/utils/src/pkgs/nanoid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,28 +13,47 @@ export enum Alphabet {
ONLY_CHAR = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ',
COMPLEX = '-0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ',
}
/**
* 获取NanoId对象
* @param alphabet
*/
function getNanoId(alphabet?: string): (size?: number) => string {
return customAlphabet(alphabet ?? Alphabet.DEFAULT)
}

/**
* 获取随机字符串
* - 按照制定规则生成默认字符串
*/
function getRandomId(size?: number): string {
return nanoid(size)
}
export class VipNanoId {
/**
* 获取NanoId对象,默认字符集为 Alphabet.DEFAULT,只有小写字母和数字
* @param alphabet
*/
public getNanoId(alphabet?: string): (size?: number) => string {
return customAlphabet(alphabet ?? Alphabet.DEFAULT)
}

export interface IVipNanoId {
getRandomId: typeof getRandomId
getNanoId: typeof getNanoId
}
/**
* 获取随机字符串,默认长度21
* - 按照制定规则生成默认字符串
*/
public getRandomId(size?: number): string {
return nanoid(size)
}

/**
* 获取纯数字的随机字符串
* @param size
*/
public getRandomNumberId(size?: number): string {
return this.getNanoId(Alphabet.ONLY_NUMBER)(size)
}

export const VipNanoId: IVipNanoId = {
getRandomId,
getNanoId,
/**
* 获取纯字母的随机字符串,包含小写字母和大写字母
* @param size
*/
public getRandomCharId(size?: number): string {
return this.getNanoId(Alphabet.ONLY_CHAR)(size)
}

/**
* 获取复杂的随机字符串,包含数字、小写字母、大写字母和特殊字符
* @param size
*/
public getRandomComplexId(size?: number): string {
return this.getNanoId(Alphabet.COMPLEX)(size)
}
}

export const vipNanoId = new VipNanoId()
Loading