@vef-framework/shared 1.0.134 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README +15 -0
- package/dist/cjs/color/color-ops.cjs +76 -0
- package/dist/cjs/color/index.cjs +24 -0
- package/dist/cjs/color/name.cjs +49 -0
- package/dist/cjs/color/palette.cjs +126 -0
- package/dist/cjs/constants/color-names.cjs +1580 -0
- package/dist/cjs/constants/color-palettes.cjs +372 -0
- package/dist/cjs/constants/index.cjs +14 -0
- package/dist/cjs/index.cjs +339 -0
- package/dist/cjs/types/color.cjs +3 -0
- package/dist/cjs/types/common.cjs +3 -0
- package/dist/cjs/types/deep-keys.cjs +3 -0
- package/dist/cjs/types/index.cjs +7 -0
- package/dist/cjs/utils/chrono.cjs +139 -0
- package/dist/cjs/utils/equal.cjs +175 -0
- package/dist/cjs/utils/error.cjs +60 -0
- package/dist/cjs/utils/event.cjs +62 -0
- package/dist/cjs/utils/format.cjs +31 -0
- package/dist/cjs/utils/function.cjs +49 -0
- package/dist/cjs/utils/id.cjs +38 -0
- package/dist/cjs/utils/index.cjs +86 -0
- package/dist/cjs/utils/key.cjs +34 -0
- package/dist/cjs/utils/lib.cjs +234 -0
- package/dist/cjs/utils/object.cjs +20 -0
- package/dist/cjs/utils/path.cjs +63 -0
- package/dist/cjs/utils/pinyin.cjs +53 -0
- package/dist/cjs/utils/security.cjs +44 -0
- package/dist/cjs/utils/string.cjs +13 -0
- package/dist/cjs/utils/task.cjs +17 -0
- package/dist/cjs/utils/tree.cjs +262 -0
- package/dist/cjs/utils/zod.cjs +14 -0
- package/dist/es/color/color-ops.js +62 -0
- package/dist/es/color/index.js +4 -0
- package/dist/es/color/name.js +45 -0
- package/dist/es/color/palette.js +122 -0
- package/dist/es/constants/color-names.js +1575 -0
- package/dist/es/constants/color-palettes.js +367 -0
- package/dist/es/constants/index.js +3 -0
- package/dist/es/index.js +30 -0
- package/dist/es/types/color.js +1 -0
- package/dist/es/types/common.js +1 -0
- package/dist/es/types/deep-keys.js +1 -0
- package/dist/es/types/index.js +4 -0
- package/dist/es/utils/chrono.js +121 -0
- package/dist/es/utils/equal.js +170 -0
- package/dist/es/utils/error.js +33 -0
- package/dist/es/utils/event.js +57 -0
- package/dist/es/utils/format.js +26 -0
- package/dist/es/utils/function.js +41 -0
- package/dist/es/utils/id.js +34 -0
- package/dist/es/utils/index.js +18 -0
- package/dist/es/utils/key.js +30 -0
- package/dist/es/utils/lib.js +10 -0
- package/dist/es/utils/object.js +16 -0
- package/dist/es/utils/path.js +49 -0
- package/dist/es/utils/pinyin.js +47 -0
- package/dist/es/utils/security.js +39 -0
- package/dist/es/utils/string.js +9 -0
- package/dist/es/utils/task.js +13 -0
- package/dist/es/utils/tree.js +252 -0
- package/dist/es/utils/zod.js +6 -0
- package/dist/types/color/color-ops.d.ts +84 -0
- package/dist/types/color/index.d.ts +3 -0
- package/dist/types/color/name.d.ts +7 -0
- package/dist/types/color/palette.d.ts +8 -0
- package/dist/types/constants/color-names.d.ts +11 -0
- package/dist/types/constants/color-palettes.d.ts +823 -0
- package/dist/types/constants/index.d.ts +2 -0
- package/dist/types/index.d.ts +4 -0
- package/dist/types/types/color.d.ts +73 -0
- package/dist/types/types/common.d.ts +25 -0
- package/dist/types/types/deep-keys.d.ts +9 -0
- package/dist/types/types/index.d.ts +3 -0
- package/dist/types/utils/chrono.d.ts +162 -0
- package/dist/types/utils/equal.d.ts +16 -0
- package/dist/types/utils/error.d.ts +38 -0
- package/dist/types/utils/event.d.ts +68 -0
- package/dist/types/utils/format.d.ts +33 -0
- package/dist/types/utils/function.d.ts +59 -0
- package/{types → dist/types/utils}/id.d.ts +2 -2
- package/dist/types/utils/index.d.ts +17 -0
- package/dist/types/utils/key.d.ts +7 -0
- package/dist/types/utils/lib.d.ts +5 -0
- package/dist/types/utils/object.d.ts +9 -0
- package/dist/types/utils/path.d.ts +76 -0
- package/dist/types/utils/pinyin.d.ts +41 -0
- package/dist/types/utils/security.d.ts +18 -0
- package/dist/types/utils/string.d.ts +7 -0
- package/dist/types/utils/task.d.ts +6 -0
- package/dist/types/utils/tree.d.ts +208 -0
- package/dist/types/utils/zod.d.ts +1 -0
- package/package.json +58 -56
- package/README.md +0 -25
- package/cjs/color.cjs +0 -2
- package/cjs/constants.cjs +0 -2
- package/cjs/context.cjs +0 -2
- package/cjs/dom.cjs +0 -2
- package/cjs/error.cjs +0 -2
- package/cjs/event.cjs +0 -2
- package/cjs/expression.cjs +0 -2
- package/cjs/function.cjs +0 -2
- package/cjs/id.cjs +0 -2
- package/cjs/index.cjs +0 -2
- package/cjs/json.cjs +0 -2
- package/cjs/module.cjs +0 -2
- package/cjs/path.cjs +0 -2
- package/cjs/pinyin.cjs +0 -2
- package/cjs/security.cjs +0 -2
- package/cjs/store.cjs +0 -2
- package/cjs/styles.cjs +0 -2
- package/cjs/temporal.cjs +0 -2
- package/cjs/theme-variables.cjs +0 -2
- package/cjs/types.cjs +0 -2
- package/cjs/utils.cjs +0 -2
- package/cjs/validation.cjs +0 -2
- package/cjs/yaml.cjs +0 -2
- package/cjs/zod.cjs +0 -2
- package/esm/color.js +0 -2
- package/esm/constants.js +0 -2
- package/esm/context.js +0 -2
- package/esm/dom.js +0 -2
- package/esm/error.js +0 -2
- package/esm/event.js +0 -2
- package/esm/expression.js +0 -2
- package/esm/function.js +0 -2
- package/esm/id.js +0 -2
- package/esm/index.js +0 -2
- package/esm/json.js +0 -2
- package/esm/module.js +0 -2
- package/esm/path.js +0 -2
- package/esm/pinyin.js +0 -2
- package/esm/security.js +0 -2
- package/esm/store.js +0 -2
- package/esm/styles.js +0 -2
- package/esm/temporal.js +0 -2
- package/esm/theme-variables.js +0 -2
- package/esm/types.js +0 -2
- package/esm/utils.js +0 -2
- package/esm/validation.js +0 -2
- package/esm/yaml.js +0 -2
- package/esm/zod.js +0 -2
- package/types/color.d.ts +0 -7
- package/types/constants.d.ts +0 -28
- package/types/context.d.ts +0 -21
- package/types/dom.d.ts +0 -9
- package/types/error.d.ts +0 -16
- package/types/event.d.ts +0 -6
- package/types/expression.d.ts +0 -23
- package/types/function.d.ts +0 -8
- package/types/index.d.ts +0 -23
- package/types/json.d.ts +0 -7
- package/types/module.d.ts +0 -7
- package/types/path.d.ts +0 -43
- package/types/pinyin.d.ts +0 -14
- package/types/security.d.ts +0 -16
- package/types/store.d.ts +0 -78
- package/types/styles.d.ts +0 -21
- package/types/temporal.d.ts +0 -18
- package/types/theme-variables.d.ts +0 -348
- package/types/types.d.ts +0 -905
- package/types/utils.d.ts +0 -77
- package/types/validation.d.ts +0 -38
- package/types/yaml.d.ts +0 -7
- package/types/zod.d.ts +0 -6
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The color entry
|
|
3
|
+
*/
|
|
4
|
+
export type ColorEntry = [hex: string, name: string];
|
|
5
|
+
/**
|
|
6
|
+
* The color number
|
|
7
|
+
*/
|
|
8
|
+
export type ColorNumber = 50 | 100 | 200 | 300 | 400 | 500 | 600 | 700 | 800 | 900 | 950;
|
|
9
|
+
/**
|
|
10
|
+
* The color swatch
|
|
11
|
+
*/
|
|
12
|
+
export interface ColorSwatch {
|
|
13
|
+
/**
|
|
14
|
+
* The color number
|
|
15
|
+
*/
|
|
16
|
+
number: ColorNumber;
|
|
17
|
+
/**
|
|
18
|
+
* The color hex code
|
|
19
|
+
*/
|
|
20
|
+
hex: string;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* The color palette
|
|
24
|
+
*/
|
|
25
|
+
export interface ColorPalette {
|
|
26
|
+
/**
|
|
27
|
+
* The color name
|
|
28
|
+
*/
|
|
29
|
+
name: string;
|
|
30
|
+
/**
|
|
31
|
+
* The color swatches
|
|
32
|
+
*/
|
|
33
|
+
swatches: ColorSwatch[];
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* The color swatch with delta
|
|
37
|
+
*/
|
|
38
|
+
export interface ColorSwatchWithDelta extends ColorSwatch {
|
|
39
|
+
/**
|
|
40
|
+
* The color delta
|
|
41
|
+
*/
|
|
42
|
+
delta: number;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* The nearest color palette
|
|
46
|
+
*/
|
|
47
|
+
export interface NearestColorPalette extends ColorPalette {
|
|
48
|
+
/**
|
|
49
|
+
* The nearest swatch
|
|
50
|
+
*/
|
|
51
|
+
nearestSwatch: ColorSwatchWithDelta;
|
|
52
|
+
/**
|
|
53
|
+
* The nearest lightness swatch
|
|
54
|
+
*/
|
|
55
|
+
nearestLightnessSwatch: ColorSwatchWithDelta;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* The matched color palette
|
|
59
|
+
*/
|
|
60
|
+
export interface MatchedColorPalette extends ColorPalette {
|
|
61
|
+
/**
|
|
62
|
+
* The color map of the palette
|
|
63
|
+
*/
|
|
64
|
+
colorMap: Map<ColorNumber, string>;
|
|
65
|
+
/**
|
|
66
|
+
* The main color swatch of the palette which number is 500
|
|
67
|
+
*/
|
|
68
|
+
main: ColorSwatch;
|
|
69
|
+
/**
|
|
70
|
+
* The matched color swatch of the palette
|
|
71
|
+
*/
|
|
72
|
+
matched: ColorSwatch;
|
|
73
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { Primitive } from 'type-fest';
|
|
2
|
+
export type Builtin = Primitive | Function | Date | Error | RegExp;
|
|
3
|
+
export type Key = string;
|
|
4
|
+
export type Awaitable<T> = T | Promise<T>;
|
|
5
|
+
export type MaybeArray<T> = T | T[];
|
|
6
|
+
export type MaybeNullish<T> = T | null | undefined;
|
|
7
|
+
export type MaybeUndefined<T> = T | undefined;
|
|
8
|
+
export type MaybeNull<T> = T | null;
|
|
9
|
+
export type Expand<T> = T extends T ? T : never;
|
|
10
|
+
export type Not<A extends boolean> = A extends true ? false : A extends false ? true : never;
|
|
11
|
+
export type IsString<T> = T extends string ? true : false;
|
|
12
|
+
export interface EmptyObject {
|
|
13
|
+
}
|
|
14
|
+
export type AnyObject = Record<keyof any, any>;
|
|
15
|
+
export type RenameKey<T, TOldKey extends keyof T, TNewKey extends string> = {
|
|
16
|
+
[K in keyof T as K extends TOldKey ? TNewKey : K]: T[K];
|
|
17
|
+
};
|
|
18
|
+
export type NonFunctionGuard<T> = T extends Function ? never : T;
|
|
19
|
+
/**
|
|
20
|
+
* Omits all symbol keys from an object type.
|
|
21
|
+
*/
|
|
22
|
+
export type OmitSymbol<T> = {
|
|
23
|
+
[K in keyof T as K extends symbol ? never : K]: T[K];
|
|
24
|
+
};
|
|
25
|
+
export type { And, Except, HasOptionalKeys, HasRequiredKeys, If, IsAny, IsBooleanLiteral, IsEqual, IsFloat, IsInteger, IsLiteral, IsNever, IsNull, IsNullable, IsNumericLiteral, IsOptional, IsOptionalKeyOf, IsReadonlyKeyOf, IsRequiredKeyOf, IsStringLiteral, IsSymbolLiteral, IsTuple, IsUndefined, IsUnknown, IsWritableKeyOf, IterableElement, KebabCase, LiteralUnion, NonEmptyObject, NonEmptyString, NonEmptyTuple, OptionalKeysOf, Or, OverrideProperties, PartialDeep, Simplify as Prettify, SimplifyDeep as PrettifyDeep, Primitive, RequiredDeep, RequiredKeysOf, SetFieldType, SetOptional, SetParameterType, SetReadonly, SetRequired, SetReturnType } from 'type-fest';
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
type ComputeRange<N extends number, Result extends unknown[] = []> = Result["length"] extends N ? Result : ComputeRange<N, [...Result, Result["length"]]>;
|
|
2
|
+
type Index40 = ComputeRange<40>[number];
|
|
3
|
+
type IsTuple<T> = T extends readonly any[] & {
|
|
4
|
+
length: infer Length;
|
|
5
|
+
} ? Length extends Index40 ? T : never : never;
|
|
6
|
+
type AllowedIndexes<Tuple extends readonly any[], Keys extends number = never> = Tuple extends readonly [] ? Keys : Tuple extends readonly [infer _, ...infer Tail] ? AllowedIndexes<Tail, Keys | Tail["length"]> : Keys;
|
|
7
|
+
type DeepKeysPrefix<T, TPrefix, TDepth extends any[]> = TPrefix extends keyof T & (number | string) ? `${TPrefix}.${DeepKeys<T[TPrefix], [...TDepth, any]> & string}` : never;
|
|
8
|
+
export type DeepKeys<T, TDepth extends any[] = []> = TDepth["length"] extends 5 ? never : unknown extends T ? string : T extends readonly any[] & IsTuple<T> ? AllowedIndexes<T> | DeepKeysPrefix<T, AllowedIndexes<T>, TDepth> : T extends any[] ? DeepKeys<T[number], [...TDepth, any]> : T extends Date ? never : T extends object ? (keyof T & string) | DeepKeysPrefix<T, keyof T, TDepth> : never;
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import { DurationUnitType } from 'dayjs/plugin/duration';
|
|
2
|
+
import { MaybeNull } from '../types';
|
|
3
|
+
import { default as dayjs } from 'dayjs';
|
|
4
|
+
export type Dayjs = dayjs.Dayjs;
|
|
5
|
+
/**
|
|
6
|
+
* Temporal picker mode type.
|
|
7
|
+
* Defines the granularity of date/time selection.
|
|
8
|
+
*/
|
|
9
|
+
export type TemporalMode = "minute" | "hour" | "time" | "date" | "datetime" | "week" | "month" | "quarter" | "year";
|
|
10
|
+
export declare const DEFAULT_DATE_FORMAT = "YYYY-MM-DD";
|
|
11
|
+
export declare const DEFAULT_TIME_FORMAT = "HH:mm:ss";
|
|
12
|
+
export declare const DEFAULT_DATETIME_FORMAT = "YYYY-MM-DD HH:mm:ss";
|
|
13
|
+
export declare const LOCALIZED_DATETIME_FORMAT = "LLLL";
|
|
14
|
+
export declare const LOCALIZED_DATE_FORMAT = "LLdddd";
|
|
15
|
+
/**
|
|
16
|
+
* Format duration in seconds to human readable string
|
|
17
|
+
*
|
|
18
|
+
* @param seconds - Duration in seconds
|
|
19
|
+
* @param unit - The unit of the duration (default: "seconds")
|
|
20
|
+
* @returns Formatted duration string
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```ts
|
|
24
|
+
* formatDuration(60) // "1分钟"
|
|
25
|
+
* formatDuration(3600) // "1小时0分钟"
|
|
26
|
+
* formatDuration(86400) // "1天0小时0分钟"
|
|
27
|
+
* formatDuration(90061) // "1天1小时1分钟"
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
export declare function formatDuration(seconds: number, unit?: DurationUnitType): string;
|
|
31
|
+
/**
|
|
32
|
+
* Parses a date string into a dayjs instance with optional format.
|
|
33
|
+
*
|
|
34
|
+
* @param date - The date string or Date object to parse
|
|
35
|
+
* @param format - The format string to use for parsing (optional, ignored for Date objects)
|
|
36
|
+
* @returns A dayjs instance
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* ```ts
|
|
40
|
+
* parseDate("2025-11-10") // dayjs instance
|
|
41
|
+
* parseDate("2025-11-10 16:30:45") // dayjs instance
|
|
42
|
+
* parseDate("20251110", "YYYYMMDD") // dayjs instance with custom format
|
|
43
|
+
* parseDate("10/11/2025", "DD/MM/YYYY") // dayjs instance with custom format
|
|
44
|
+
* parseDate(new Date()) // dayjs instance from Date object
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
47
|
+
export declare function parseDate(date: string | Date, format?: MaybeNull<string>): Dayjs;
|
|
48
|
+
/**
|
|
49
|
+
* Attempts to parse a date string by trying various datetime and date formats.
|
|
50
|
+
* Returns null if parsing fails with all formats.
|
|
51
|
+
*
|
|
52
|
+
* @param date - The date string to parse
|
|
53
|
+
* @returns A dayjs instance if parsing succeeds, null otherwise
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* ```ts
|
|
57
|
+
* tryParseDate("2025-11-10 16:30:45") // dayjs instance
|
|
58
|
+
* tryParseDate("2025/11/10") // dayjs instance
|
|
59
|
+
* tryParseDate("20251110") // dayjs instance
|
|
60
|
+
* tryParseDate("invalid date") // null
|
|
61
|
+
* ```
|
|
62
|
+
*/
|
|
63
|
+
export declare function tryParseDate(date: string): MaybeNull<Dayjs>;
|
|
64
|
+
/**
|
|
65
|
+
* Formats a dayjs instance with the specified format.
|
|
66
|
+
*
|
|
67
|
+
* @param date - The dayjs instance to format
|
|
68
|
+
* @param format - The format string (defaults to "YYYY-MM-DD HH:mm:ss")
|
|
69
|
+
* @returns The formatted date string
|
|
70
|
+
*
|
|
71
|
+
* @example
|
|
72
|
+
* ```ts
|
|
73
|
+
* formatDate(dayjs()) // "2025-11-10 16:30:45"
|
|
74
|
+
* formatDate(dayjs(), "YYYY-MM-DD") // "2025-11-10"
|
|
75
|
+
* formatDate(dayjs(), "HH:mm:ss") // "16:30:45"
|
|
76
|
+
* ```
|
|
77
|
+
*/
|
|
78
|
+
export declare function formatDate(date: Dayjs, format?: string): string;
|
|
79
|
+
/**
|
|
80
|
+
* Gets the current time as a dayjs instance.
|
|
81
|
+
*
|
|
82
|
+
* @returns The current time as a dayjs instance
|
|
83
|
+
*
|
|
84
|
+
* @example
|
|
85
|
+
* ```ts
|
|
86
|
+
* const now = getNow() // dayjs instance
|
|
87
|
+
* now.format("YYYY-MM-DD") // "2025-11-10"
|
|
88
|
+
* ```
|
|
89
|
+
*/
|
|
90
|
+
export declare function getNow(): Dayjs;
|
|
91
|
+
/**
|
|
92
|
+
* Gets the current date string in "YYYY-MM-DD" format.
|
|
93
|
+
*
|
|
94
|
+
* @returns The current date string
|
|
95
|
+
*
|
|
96
|
+
* @example
|
|
97
|
+
* ```ts
|
|
98
|
+
* getNowDateString() // "2025-11-10"
|
|
99
|
+
* ```
|
|
100
|
+
*/
|
|
101
|
+
export declare function getNowDateString(): string;
|
|
102
|
+
/**
|
|
103
|
+
* Gets the current time string in "HH:mm:ss" format.
|
|
104
|
+
*
|
|
105
|
+
* @returns The current time string
|
|
106
|
+
*
|
|
107
|
+
* @example
|
|
108
|
+
* ```ts
|
|
109
|
+
* getNowTimeString() // "16:30:45"
|
|
110
|
+
* ```
|
|
111
|
+
*/
|
|
112
|
+
export declare function getNowTimeString(): string;
|
|
113
|
+
/**
|
|
114
|
+
* Gets the current date time string in "YYYY-MM-DD HH:mm:ss" format.
|
|
115
|
+
*
|
|
116
|
+
* @returns The current date time string
|
|
117
|
+
*
|
|
118
|
+
* @example
|
|
119
|
+
* ```ts
|
|
120
|
+
* getNowDateTimeString() // "2025-11-10 16:30:45"
|
|
121
|
+
* ```
|
|
122
|
+
*/
|
|
123
|
+
export declare function getNowDateTimeString(): string;
|
|
124
|
+
/**
|
|
125
|
+
* Gets the current date time in a localized full format.
|
|
126
|
+
*
|
|
127
|
+
* @returns The localized date time string
|
|
128
|
+
*
|
|
129
|
+
* @example
|
|
130
|
+
* ```ts
|
|
131
|
+
* // With zh-cn locale
|
|
132
|
+
* getLocalizedDateTime() // "2025年11月10日星期日下午4点30分45秒"
|
|
133
|
+
* getLocalizedDateTime(false) // "2025年11月10日星期日"
|
|
134
|
+
* ```
|
|
135
|
+
*/
|
|
136
|
+
export declare function getLocalizedDateTime(includeTime?: boolean): string;
|
|
137
|
+
declare const FORMAT_MAP: {
|
|
138
|
+
readonly year: readonly ["YYYY"];
|
|
139
|
+
readonly quarter: readonly ["YYYY-Q季度"];
|
|
140
|
+
readonly month: readonly ["YYYY-MM", "YYYY/MM", "YYYY.MM", "YYYYMM"];
|
|
141
|
+
readonly week: readonly ["YYYY-wo"];
|
|
142
|
+
readonly date: readonly ["YYYY-MM-DD", "YYYY/MM/DD", "YYYY.MM.DD", "YYYYMMDD", "YY/MM/DD", "YY.MM.DD", "YYMMDD"];
|
|
143
|
+
readonly time: readonly ["HH:mm:ss", "HH.mm.ss", "HHmmss"];
|
|
144
|
+
readonly hour: readonly ["HH"];
|
|
145
|
+
readonly minute: readonly ["HH:mm", "HH.mm", "HHmm"];
|
|
146
|
+
readonly datetime: readonly ["YYYY-MM-DD HH:mm:ss", "YYYY/MM/DD HH:mm:ss", "YYYY.MM.DD HH.mm.ss", "YYYYMMDDHHmmss", "YY/MM/DD HH:mm:ss", "YY.MM.DD HH:mm:ss", "YY.MM.DD HH.mm.ss", "YYMMDDHHmmss"];
|
|
147
|
+
};
|
|
148
|
+
/**
|
|
149
|
+
* Gets the available format patterns for a temporal picker mode.
|
|
150
|
+
*
|
|
151
|
+
* @param mode - The temporal picker mode
|
|
152
|
+
* @returns An array of format strings for the specified mode
|
|
153
|
+
*
|
|
154
|
+
* @example
|
|
155
|
+
* ```ts
|
|
156
|
+
* getTemporalFormats("date") // ["YYYY-MM-DD", "YYYY/MM/DD", ...]
|
|
157
|
+
* getTemporalFormats("time") // ["HH:mm:ss", "HH.mm.ss", "HHmmss"]
|
|
158
|
+
* getTemporalFormats("datetime") // ["YYYY-MM-DD HH:mm:ss", ...]
|
|
159
|
+
* ```
|
|
160
|
+
*/
|
|
161
|
+
export declare function getTemporalFormats<const T extends TemporalMode>(mode: T): typeof FORMAT_MAP[T];
|
|
162
|
+
export {};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shallowly compares two values.
|
|
3
|
+
*
|
|
4
|
+
* @param value1 - The first value to compare.
|
|
5
|
+
* @param value2 - The second value to compare.
|
|
6
|
+
* @returns `true` if the values are shallowly equal, `false` otherwise.
|
|
7
|
+
*/
|
|
8
|
+
export declare function isShallowEqual(value1: unknown, value2: unknown): boolean;
|
|
9
|
+
/**
|
|
10
|
+
* Deeply compares two values, with support for circular references.
|
|
11
|
+
*
|
|
12
|
+
* @param value1 - The first value to compare.
|
|
13
|
+
* @param value2 - The second value to compare.
|
|
14
|
+
* @returns `true` if the values are deeply equal, `false` otherwise.
|
|
15
|
+
*/
|
|
16
|
+
export declare function isDeepEqual(value1: unknown, value2: unknown): boolean;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import * as stackTrace from "stacktrace-js";
|
|
2
|
+
export type StackFrame = stackTrace.StackFrame;
|
|
3
|
+
/**
|
|
4
|
+
* Parse the error stack, filter the stack frames
|
|
5
|
+
*
|
|
6
|
+
* @param error The error to parse
|
|
7
|
+
* @param filter The filter function to filter the stack frames
|
|
8
|
+
* @returns The parsed stack frames
|
|
9
|
+
*/
|
|
10
|
+
export declare function parseErrorStack(error: Error, filter?: (frame: StackFrame) => boolean): Promise<StackFrame[]>;
|
|
11
|
+
/**
|
|
12
|
+
* Filter the user frame
|
|
13
|
+
*
|
|
14
|
+
* @param stackFrame The stack frame to filter
|
|
15
|
+
* @returns The filtered stack frame
|
|
16
|
+
*/
|
|
17
|
+
export declare function filterUserFrame(stackFrame: StackFrame): boolean;
|
|
18
|
+
/**
|
|
19
|
+
* Get the sanitized error stack
|
|
20
|
+
*
|
|
21
|
+
* @param error The error to sanitize
|
|
22
|
+
* @returns The sanitized error stack
|
|
23
|
+
*/
|
|
24
|
+
export declare function getSanitizedErrorStack(error: Error): Promise<string>;
|
|
25
|
+
/**
|
|
26
|
+
* Get the current stack
|
|
27
|
+
*
|
|
28
|
+
* @param filter The filter function to filter the stack frames
|
|
29
|
+
* @returns The current stack
|
|
30
|
+
*/
|
|
31
|
+
export declare function getCurrentStack(filter?: (frame: StackFrame) => boolean): Promise<StackFrame[]>;
|
|
32
|
+
/**
|
|
33
|
+
* Get the current stack synchronously
|
|
34
|
+
*
|
|
35
|
+
* @param filter The filter function to filter the stack frames
|
|
36
|
+
* @returns The current stack
|
|
37
|
+
*/
|
|
38
|
+
export declare function getCurrentStackSync(filter?: (frame: StackFrame) => boolean): StackFrame[];
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { EventHandlerMap, EventType, Handler } from 'mitt';
|
|
2
|
+
/**
|
|
3
|
+
* A type-safe event emitter wrapper around mitt library.
|
|
4
|
+
* Provides a clean API for event subscription, emission, and cleanup.
|
|
5
|
+
*
|
|
6
|
+
* @template TEvents - A record type defining the available events and their payload types
|
|
7
|
+
*/
|
|
8
|
+
export declare class EventEmitter<TEvents extends Record<EventType, unknown>> {
|
|
9
|
+
#private;
|
|
10
|
+
/**
|
|
11
|
+
* Subscribe to an event with a listener function.
|
|
12
|
+
* Returns an unsubscribe function for easy cleanup.
|
|
13
|
+
*
|
|
14
|
+
* @param eventType - The type of event to listen for
|
|
15
|
+
* @param eventListener - The function to call when the event is emitted
|
|
16
|
+
* @returns A function that removes this specific listener when called
|
|
17
|
+
*/
|
|
18
|
+
on<const TEventType extends keyof TEvents>(eventType: TEventType, eventListener: Handler<TEvents[TEventType]>): () => void;
|
|
19
|
+
/**
|
|
20
|
+
* Emit an event with the specified payload.
|
|
21
|
+
* All registered listeners for this event type will be called synchronously.
|
|
22
|
+
*
|
|
23
|
+
* @param eventType - The type of event to emit
|
|
24
|
+
* @param eventPayload - The data to pass to all listeners
|
|
25
|
+
*/
|
|
26
|
+
emit<const TEventType extends keyof TEvents>(eventType: undefined extends TEvents[TEventType] ? TEventType : never): void;
|
|
27
|
+
emit<const TEventType extends keyof TEvents>(eventType: TEventType, eventPayload: TEvents[TEventType]): void;
|
|
28
|
+
/**
|
|
29
|
+
* Remove a specific listener for an event type.
|
|
30
|
+
* If no listener is provided, removes all listeners for that event type.
|
|
31
|
+
*
|
|
32
|
+
* @param eventType - The type of event to remove listeners from
|
|
33
|
+
* @param eventListener - Optional specific listener to remove
|
|
34
|
+
*/
|
|
35
|
+
off<const TEventType extends keyof TEvents>(eventType: TEventType, eventListener?: Handler<TEvents[TEventType]>): void;
|
|
36
|
+
/**
|
|
37
|
+
* Remove all event listeners from all event types.
|
|
38
|
+
* Useful for cleanup when the emitter is no longer needed.
|
|
39
|
+
*/
|
|
40
|
+
clear(): void;
|
|
41
|
+
/**
|
|
42
|
+
* Get all registered listeners for debugging purposes.
|
|
43
|
+
* Returns a Map of event types to their listener arrays.
|
|
44
|
+
*/
|
|
45
|
+
getAllListeners(): EventHandlerMap<TEvents>;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Factory function to create a new EventEmitter instance.
|
|
49
|
+
* Provides a more functional approach to creating event emitters.
|
|
50
|
+
*
|
|
51
|
+
* @template TEvents - A record type defining the available events and their payload types
|
|
52
|
+
* @returns A new EventEmitter instance
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* ```typescript
|
|
56
|
+
* interface AppEvents {
|
|
57
|
+
* 'user:login': { userId: string };
|
|
58
|
+
* 'user:logout': void;
|
|
59
|
+
* }
|
|
60
|
+
*
|
|
61
|
+
* const emitter = createEventEmitter<AppEvents>();
|
|
62
|
+
* const unsubscribe = emitter.on('user:login', ({ userId }) => {
|
|
63
|
+
* console.log(`User ${userId} logged in`);
|
|
64
|
+
* });
|
|
65
|
+
* ```
|
|
66
|
+
*/
|
|
67
|
+
export declare function createEventEmitter<TEvents extends Record<EventType, unknown>>(): EventEmitter<TEvents>;
|
|
68
|
+
export { type Handler as EventHandler, type EventType } from 'mitt';
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Format bytes to human readable string
|
|
3
|
+
*
|
|
4
|
+
* @param bytes - Number of bytes
|
|
5
|
+
* @param decimals - Number of decimal places (default: 2)
|
|
6
|
+
* @returns Formatted string with unit (B, KB, MB, GB, TB, PB)
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts
|
|
10
|
+
* formatBytes(1024) // "1 KB"
|
|
11
|
+
* formatBytes(1536, 1) // "1.5 KB"
|
|
12
|
+
* formatBytes(1048576) // "1 MB"
|
|
13
|
+
* formatBytes(0) // "0 B"
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
export declare function formatBytes(bytes: number, decimals?: number): string;
|
|
17
|
+
/**
|
|
18
|
+
* Format large numbers to human readable string with units (K, M, B, T)
|
|
19
|
+
*
|
|
20
|
+
* @param num - Number to format
|
|
21
|
+
* @param decimals - Number of decimal places (default: 2)
|
|
22
|
+
* @returns Formatted string with unit (K, M, B, T)
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```ts
|
|
26
|
+
* formatNumber(1000) // "1 K"
|
|
27
|
+
* formatNumber(1500, 1) // "1.5 K"
|
|
28
|
+
* formatNumber(1234567) // "1.23 M"
|
|
29
|
+
* formatNumber(999) // "999"
|
|
30
|
+
* formatNumber(0) // "0"
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
export declare function formatNumber(num: number, decimals?: number): string;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { Awaitable, MaybeUndefined } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Awaitable function invocation options.
|
|
4
|
+
*/
|
|
5
|
+
export interface AwaitableFnInvocationOptions<in TResult, in out TContext = unknown> {
|
|
6
|
+
/**
|
|
7
|
+
* The function to call before invoking the awaitable function.
|
|
8
|
+
*/
|
|
9
|
+
onInvoke?: () => MaybeUndefined<TContext>;
|
|
10
|
+
/**
|
|
11
|
+
* The function to call when the awaitable function succeeds.
|
|
12
|
+
*/
|
|
13
|
+
onSuccess?: (result: TResult, context: MaybeUndefined<TContext>) => void;
|
|
14
|
+
/**
|
|
15
|
+
* The function to call when the awaitable function fails.
|
|
16
|
+
*/
|
|
17
|
+
onError?: (error: unknown, context: MaybeUndefined<TContext>) => void;
|
|
18
|
+
/**
|
|
19
|
+
* The function to call after invoking the awaitable function.
|
|
20
|
+
*/
|
|
21
|
+
onFinally?: (context: MaybeUndefined<TContext>) => void;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Checks if a function is an async function.
|
|
25
|
+
*
|
|
26
|
+
* @param fn - The function to check.
|
|
27
|
+
* @returns `true` if the function is an async function, `false` otherwise.
|
|
28
|
+
*/
|
|
29
|
+
export declare function isAsyncFunction(fn: Function): fn is (...args: any[]) => Promise<any>;
|
|
30
|
+
/**
|
|
31
|
+
* Invokes an awaitable function.
|
|
32
|
+
*
|
|
33
|
+
* @param fn - The awaitable function to invoke.
|
|
34
|
+
* @param args - The arguments to pass to the awaitable function.
|
|
35
|
+
* @param options - The options to pass to the awaitable function.
|
|
36
|
+
* @returns The result of the awaitable function.
|
|
37
|
+
*/
|
|
38
|
+
export declare function invokeAwaitableFn<TArgs extends any[] = any[], TResult = unknown, TContext = unknown>(fn: (...args: TArgs) => Awaitable<TResult>, args: NoInfer<TArgs>, options: AwaitableFnInvocationOptions<NoInfer<TResult>, TContext>): Promise<TResult>;
|
|
39
|
+
/**
|
|
40
|
+
* Returns the value itself.
|
|
41
|
+
*
|
|
42
|
+
* @param value - The value to return.
|
|
43
|
+
* @returns The value itself.
|
|
44
|
+
*/
|
|
45
|
+
export declare function identity<T>(value: T): T;
|
|
46
|
+
/**
|
|
47
|
+
* Creates a function that throws an error indicating the feature/function is not implemented.
|
|
48
|
+
*
|
|
49
|
+
* @param feature - The feature/function name to include in the error message.
|
|
50
|
+
* @returns A function that throws an error indicating the feature/function is not implemented.
|
|
51
|
+
*/
|
|
52
|
+
export declare function createThrowNotImplementedFn(feature?: string): () => never;
|
|
53
|
+
/**
|
|
54
|
+
* Throws an error indicating the feature/function is not implemented.
|
|
55
|
+
*
|
|
56
|
+
* @param feature - The feature/function name to include in the error message.
|
|
57
|
+
* @throws Always throws an Error to indicate a missing implementation.
|
|
58
|
+
*/
|
|
59
|
+
export declare function throwNotImplemented(feature?: string): never;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export * from './chrono';
|
|
2
|
+
export * from './equal';
|
|
3
|
+
export * from './error';
|
|
4
|
+
export * from './event';
|
|
5
|
+
export * from './format';
|
|
6
|
+
export * from './function';
|
|
7
|
+
export * from './id';
|
|
8
|
+
export * from './key';
|
|
9
|
+
export * from './lib';
|
|
10
|
+
export * from './object';
|
|
11
|
+
export * from './path';
|
|
12
|
+
export * from './pinyin';
|
|
13
|
+
export * from './security';
|
|
14
|
+
export * from './string';
|
|
15
|
+
export * from './task';
|
|
16
|
+
export * from './tree';
|
|
17
|
+
export * from './zod';
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export declare const alwaysTrue: () => boolean;
|
|
2
|
+
export declare const alwaysFalse: () => boolean;
|
|
3
|
+
export { klona as cloneDeep } from 'klona';
|
|
4
|
+
export { parse as decodeQueryString, stringify as encodeQueryString } from 'qs';
|
|
5
|
+
export { always, assign, camel as camelCase, capitalize, cluster, debounce, first, get, isArray, isBigInt, isBoolean, isDate, isEmpty, isError, isFloat, isFunction, isInt, isIntString, isMap, isNullish, isNumber, isObject, isPlainObject, isPrimitive, isPromise, isRegExp, isSet, isString, isSymbol, isUndefined, isWeakMap, isWeakSet, dash as kebabCase, last, max, memo as memoize, min, noop, omit, once, pascal as pascalCase, pick, set, similarity, snake as snakeCase, sum, template, throttle, toFloat, toInt, trim, unique } from 'radashi';
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Merges the source object into the target object
|
|
3
|
+
*
|
|
4
|
+
* @param target - The target object
|
|
5
|
+
* @param source - The source object
|
|
6
|
+
* @param overrideExisting - Whether to override existing values
|
|
7
|
+
* @returns The merged object with the source object merged into the target object
|
|
8
|
+
*/
|
|
9
|
+
export declare function mergeWith<T extends object>(target: T, source: Partial<T>, overrideExisting?: boolean): T;
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { default as path } from 'path-browserify';
|
|
2
|
+
declare const pathSeparator: string;
|
|
3
|
+
export type PathObject = path.PathObject;
|
|
4
|
+
/**
|
|
5
|
+
* Get the base name from a path
|
|
6
|
+
*
|
|
7
|
+
* @param path The path
|
|
8
|
+
* @param keepExt Whether to keep the extension
|
|
9
|
+
* @returns The base name
|
|
10
|
+
*/
|
|
11
|
+
export declare function getBaseName(path: string, keepExt?: boolean): string;
|
|
12
|
+
/**
|
|
13
|
+
* Get the extension name from a path
|
|
14
|
+
*
|
|
15
|
+
* @param path The path
|
|
16
|
+
* @returns The extension name
|
|
17
|
+
*/
|
|
18
|
+
export declare function getExtName(path: string): string;
|
|
19
|
+
/**
|
|
20
|
+
* Get the dir name from a path
|
|
21
|
+
*
|
|
22
|
+
* @param path The path
|
|
23
|
+
* @returns The dir name
|
|
24
|
+
*/
|
|
25
|
+
export declare function getDirName(path: string): string;
|
|
26
|
+
/**
|
|
27
|
+
* Joins paths
|
|
28
|
+
*
|
|
29
|
+
* @param paths The paths
|
|
30
|
+
* @returns The joined path
|
|
31
|
+
*/
|
|
32
|
+
export declare function joinPaths(...paths: string[]): string;
|
|
33
|
+
/**
|
|
34
|
+
* Checks if a path is absolute
|
|
35
|
+
*
|
|
36
|
+
* @param path The path
|
|
37
|
+
* @returns Whether the path is absolute
|
|
38
|
+
*/
|
|
39
|
+
export declare function isAbsolutePath(path: string): boolean;
|
|
40
|
+
/**
|
|
41
|
+
* Normalizes a path
|
|
42
|
+
*
|
|
43
|
+
* @param path The path
|
|
44
|
+
* @returns The normalized path
|
|
45
|
+
*/
|
|
46
|
+
export declare function normalizePath(path: string): string;
|
|
47
|
+
/**
|
|
48
|
+
* Parse a path
|
|
49
|
+
*
|
|
50
|
+
* @param path The path
|
|
51
|
+
* @returns The parsed path
|
|
52
|
+
*/
|
|
53
|
+
export declare function parsePath(path: string): PathObject;
|
|
54
|
+
/**
|
|
55
|
+
* Format a path object
|
|
56
|
+
*
|
|
57
|
+
* @param pathObject The path object
|
|
58
|
+
* @returns The formatted path
|
|
59
|
+
*/
|
|
60
|
+
export declare function formatPath(pathObject: PathObject): string;
|
|
61
|
+
/**
|
|
62
|
+
* Get the relative path from one path to another
|
|
63
|
+
*
|
|
64
|
+
* @param from The starting path
|
|
65
|
+
* @param to The destination path
|
|
66
|
+
* @returns The relative path
|
|
67
|
+
*/
|
|
68
|
+
export declare function getRelativePath(from: string, to: string): string;
|
|
69
|
+
/**
|
|
70
|
+
* Resolve a path
|
|
71
|
+
*
|
|
72
|
+
* @param pathSegments The path segments
|
|
73
|
+
* @returns The resolved path
|
|
74
|
+
*/
|
|
75
|
+
export declare function resolvePath(...pathSegments: string[]): string;
|
|
76
|
+
export { pathSeparator };
|