@kokkoro/utils
Advanced tools
+15
-2
@@ -1,2 +0,15 @@ | ||
| export * from './colorful.js'; | ||
| export * from './common.js'; | ||
| /** | ||
| * 检测对象是否是 Class | ||
| * | ||
| * @param value - 检测对象 | ||
| * @returns 布尔值 | ||
| */ | ||
| export declare function isClass(value: unknown): boolean; | ||
| /** | ||
| * 字符串转换为数字,可携带 `k` `w` `e` 单位 | ||
| * | ||
| * @param value - 字符串 | ||
| * @returns 数字结果 | ||
| */ | ||
| export declare function stringToNumber(value: unknown): number; | ||
| export declare function wait(ms: number): Promise<void>; |
+47
-2
@@ -1,2 +0,47 @@ | ||
| export * from './colorful.js'; | ||
| export * from './common.js'; | ||
| /** | ||
| * 检测对象是否是 Class | ||
| * | ||
| * @param value - 检测对象 | ||
| * @returns 布尔值 | ||
| */ | ||
| export function isClass(value) { | ||
| if (typeof value !== 'function') { | ||
| return false; | ||
| } | ||
| return value.toString().startsWith('class'); | ||
| } | ||
| /** | ||
| * 字符串转换为数字,可携带 `k` `w` `e` 单位 | ||
| * | ||
| * @param value - 字符串 | ||
| * @returns 数字结果 | ||
| */ | ||
| export function stringToNumber(value) { | ||
| if (typeof value !== 'string') { | ||
| return NaN; | ||
| } | ||
| const number = Number(value); | ||
| if (isNaN(number)) { | ||
| let float = parseFloat(value); | ||
| const units = value.replace(/$\d+/g, ''); | ||
| for (let i = 0; i < units.length; i++) { | ||
| const unit = units[i]; | ||
| switch (unit) { | ||
| case 'k': | ||
| float *= 1000; | ||
| break; | ||
| case 'w': | ||
| float *= 10000; | ||
| break; | ||
| case 'e': | ||
| float *= 100000000; | ||
| break; | ||
| } | ||
| } | ||
| return float; | ||
| } | ||
| return number; | ||
| } | ||
| export async function wait(ms) { | ||
| return new Promise(resolve => setTimeout(resolve, ms)); | ||
| } |
+2
-2
| { | ||
| "name": "@kokkoro/utils", | ||
| "version": "0.8.2", | ||
| "version": "0.8.3", | ||
| "description": "Utilities for kokkoro.", | ||
| "engines": { | ||
| "node": ">=20.6.0" | ||
| "node": ">=18.0.0" | ||
| }, | ||
@@ -8,0 +8,0 @@ "files": [ |
| declare enum Color { | ||
| Red = 31, | ||
| Green = 32, | ||
| Yellow = 33, | ||
| Blue = 34, | ||
| Magenta = 35, | ||
| Cyan = 36, | ||
| White = 37 | ||
| } | ||
| /** | ||
| * 生成彩色字体 | ||
| * | ||
| * @param type - 颜色 | ||
| * @param text - 文本 | ||
| * @returns 彩色字体 | ||
| */ | ||
| export declare function colorful(type: keyof typeof Color, text: string): string; | ||
| export {}; |
| var Color; | ||
| (function (Color) { | ||
| Color[Color["Red"] = 31] = "Red"; | ||
| Color[Color["Green"] = 32] = "Green"; | ||
| Color[Color["Yellow"] = 33] = "Yellow"; | ||
| Color[Color["Blue"] = 34] = "Blue"; | ||
| Color[Color["Magenta"] = 35] = "Magenta"; | ||
| Color[Color["Cyan"] = 36] = "Cyan"; | ||
| Color[Color["White"] = 37] = "White"; | ||
| })(Color || (Color = {})); | ||
| /** | ||
| * 生成彩色字体 | ||
| * | ||
| * @param type - 颜色 | ||
| * @param text - 文本 | ||
| * @returns 彩色字体 | ||
| */ | ||
| export function colorful(type, text) { | ||
| return `\u001b[${Color[type]}m${text}\u001b[0m`; | ||
| } |
| /** | ||
| * 创建只读 Map | ||
| * | ||
| * @param map - Map 对象 | ||
| * @returns 只读对象 | ||
| */ | ||
| export declare function createReadonlyMap<T extends Map<number | string, unknown>>(map: T): T; | ||
| /** | ||
| * 检测对象是否是 Class | ||
| * | ||
| * @param value - 检测对象 | ||
| * @returns 布尔值 | ||
| */ | ||
| export declare function isClass(value: unknown): boolean; | ||
| export declare function none(): void; | ||
| /** | ||
| * 对象转换为字符串 | ||
| * | ||
| * @param value - 对象 | ||
| * @returns 字符串结果 | ||
| */ | ||
| export declare function objectToString(value: unknown): string; | ||
| /** | ||
| * 字符串转换为数字,可携带 `k` `w` `e` 单位 | ||
| * | ||
| * @param value - 字符串 | ||
| * @returns 数字结果 | ||
| */ | ||
| export declare function stringToNumber(value: unknown): number; | ||
| export declare function wait(ms: number): Promise<void>; |
| /** | ||
| * 创建只读 Map | ||
| * | ||
| * @param map - Map 对象 | ||
| * @returns 只读对象 | ||
| */ | ||
| export function createReadonlyMap(map) { | ||
| const proxy = new Proxy(map, { | ||
| set() { | ||
| return false; | ||
| }, | ||
| get(target, property) { | ||
| const value = Reflect.get(target, property); | ||
| if (typeof value !== 'function') { | ||
| return value; | ||
| } | ||
| switch (property) { | ||
| case 'set': | ||
| case 'clear': | ||
| case 'delete': | ||
| return none; | ||
| default: | ||
| return value.bind(target); | ||
| } | ||
| }, | ||
| }); | ||
| return proxy; | ||
| } | ||
| /** | ||
| * 检测对象是否是 Class | ||
| * | ||
| * @param value - 检测对象 | ||
| * @returns 布尔值 | ||
| */ | ||
| export function isClass(value) { | ||
| if (typeof value !== 'function') { | ||
| return false; | ||
| } | ||
| return value.toString().startsWith('class'); | ||
| } | ||
| export function none() { } | ||
| /** | ||
| * 对象转换为字符串 | ||
| * | ||
| * @param value - 对象 | ||
| * @returns 字符串结果 | ||
| */ | ||
| export function objectToString(value) { | ||
| if (typeof value === 'string') { | ||
| return value; | ||
| } | ||
| return JSON.stringify(value, null, 2); | ||
| } | ||
| /** | ||
| * 字符串转换为数字,可携带 `k` `w` `e` 单位 | ||
| * | ||
| * @param value - 字符串 | ||
| * @returns 数字结果 | ||
| */ | ||
| export function stringToNumber(value) { | ||
| if (typeof value !== 'string') { | ||
| return NaN; | ||
| } | ||
| const number = Number(value); | ||
| if (isNaN(number)) { | ||
| let float = parseFloat(value); | ||
| const units = value.replace(/$\d+/g, ''); | ||
| for (let i = 0; i < units.length; i++) { | ||
| const unit = units[i]; | ||
| switch (unit) { | ||
| case 'k': | ||
| float *= 1000; | ||
| break; | ||
| case 'w': | ||
| float *= 10000; | ||
| break; | ||
| case 'e': | ||
| float *= 100000000; | ||
| break; | ||
| } | ||
| } | ||
| return float; | ||
| } | ||
| return number; | ||
| } | ||
| export async function wait(ms) { | ||
| return new Promise(resolve => setTimeout(resolve, ms)); | ||
| } |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
2286
-50.3%3
-57.14%62
-61.25%1
Infinity%