更新 @kevisual/api 版本至 0.0.29,添加路径处理和哈希功能,新增随机 ID 生成器

This commit is contained in:
2026-01-30 14:23:51 +08:00
parent 0086aeced2
commit ef5d3c3805
5 changed files with 190 additions and 14 deletions

26
query/utils/random.ts Normal file
View File

@@ -0,0 +1,26 @@
import { customAlphabet } from 'nanoid';
export const letter = 'abcdefghijklmnopqrstuvwxyz';
export const number = '0123456789';
const alphanumeric = `${letter}${number}`;
export const alphanumericWithDash = `${alphanumeric}-`;
export const uuid = customAlphabet(letter);
export const nanoid = customAlphabet(alphanumeric, 10);
export const nanoidWithDash = customAlphabet(alphanumericWithDash, 10);
/**
* 创建一个随机的 id以字母开头的字符串
* @param number
* @returns
*/
export const randomId = (number: number) => {
const _letter = uuid(1);
return `${_letter}${nanoid(number)}`;
};
export const randomLetter = (number: number = 8, opts?: { before?: string; after?: string }) => {
const { before = '', after = '' } = opts || {};
return `${before}${uuid(number)}${after}`;
};