@semi-kit/utils 1.2.3 → 1.2.5
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/lib/axios.d.mts +10 -6
- package/lib/color.d.mts +9 -5
- package/lib/color.mjs +1 -1
- package/lib/datetime.d.mts +49 -19
- package/lib/extra.d.mts +5 -1
- package/lib/rules.d.mts +57 -17
- package/package.json +1 -1
package/lib/axios.d.mts
CHANGED
|
@@ -1,14 +1,18 @@
|
|
|
1
1
|
import { ParamsSerializerOptions } from "axios";
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
4
|
-
* @param
|
|
5
|
-
* @
|
|
3
|
+
* 过滤请求参数中空值
|
|
4
|
+
* @param data - 需要过滤的数据对象
|
|
5
|
+
* @returns 过滤后的对象,只保留有效值
|
|
6
|
+
* @example
|
|
7
|
+
* useOmitNilRequestParams({ name: 'Tom', age: null, link: '', address: undefined, items: [], info: {} })
|
|
8
|
+
* -> { name: 'Tom' }
|
|
6
9
|
*/
|
|
7
10
|
declare const useOmitNilRequestParams: (data: object) => object;
|
|
8
11
|
/**
|
|
9
|
-
*
|
|
10
|
-
* @
|
|
11
|
-
* @
|
|
12
|
+
* Axios 参数序列化配置
|
|
13
|
+
* @returns Axios 参数序列化选项,数组参数使用 repeat 格式
|
|
14
|
+
* @example
|
|
15
|
+
* 参数 { ids: [1, 2, 3] } 会被序列化为 'ids=1&ids=2&ids=3'
|
|
12
16
|
*/
|
|
13
17
|
declare const useParamsSerializer: () => ParamsSerializerOptions;
|
|
14
18
|
export { useOmitNilRequestParams, useParamsSerializer };
|
package/lib/color.d.mts
CHANGED
|
@@ -1,25 +1,29 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* 将 Hex 颜色值转换为 RGB 格式
|
|
3
|
-
* @param hex -
|
|
4
|
-
* @returns RGB 对象,包含 r、g、b
|
|
2
|
+
* 将 Hex 颜色值转换为 RGB/RGBA 格式
|
|
3
|
+
* @param hex - 十六进制颜色值,支持 6 位或 8 位格式,例如 '#ffffff'、'ffffff'、'#ffffffFF'
|
|
4
|
+
* @returns RGB/RGBA 对象,包含 r、g、b 和可选的 a 属性
|
|
5
5
|
* @example
|
|
6
6
|
* hexToRgb('#ff0000') -> { r: 255, g: 0, b: 0 }
|
|
7
|
+
* hexToRgb('#14443080') -> { r: 20, g: 68, b: 48, a: 0.5 }
|
|
7
8
|
*/
|
|
8
9
|
declare const hexToRgb: (hex: string) => {
|
|
9
10
|
r: number;
|
|
10
11
|
g: number;
|
|
11
12
|
b: number;
|
|
13
|
+
a?: number;
|
|
12
14
|
};
|
|
13
15
|
/**
|
|
14
|
-
* 将 RGB 颜色值转换为 Hex 格式
|
|
16
|
+
* 将 RGB/RGBA 颜色值转换为 Hex 格式
|
|
15
17
|
* @param r - 红色值 (0-255)
|
|
16
18
|
* @param g - 绿色值 (0-255)
|
|
17
19
|
* @param b - 蓝色值 (0-255)
|
|
20
|
+
* @param a - 可选的透明度值 (0-1)
|
|
18
21
|
* @returns 十六进制颜色值字符串
|
|
19
22
|
* @example
|
|
20
23
|
* rgbToHex(255, 0, 0) -> '#ff0000'
|
|
24
|
+
* rgbToHex(20, 68, 48, 0.5) -> '#14443080'
|
|
21
25
|
*/
|
|
22
|
-
declare const rgbToHex: (r: number, g: number, b: number) => string;
|
|
26
|
+
declare const rgbToHex: (r: number, g: number, b: number, a?: number) => string;
|
|
23
27
|
/**
|
|
24
28
|
* 随机生成一个 Hex 颜色值
|
|
25
29
|
* @returns 随机的十六进制颜色值字符串
|
package/lib/color.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
const hexToRgb=e=>{let t=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})
|
|
1
|
+
const hexToRgb=e=>{let t=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})?$/i.exec(e),n={r:parseInt(t?.[1]??`0`,16),g:parseInt(t?.[2]??`0`,16),b:parseInt(t?.[3]??`0`,16)};return t?.[4]?{...n,a:parseInt(t[4],16)/255}:n},rgbToHex=(e,t,n,r)=>{let i=`#${((1<<24)+(e<<16)+(t<<8)+n).toString(16).slice(1)}`;return r===void 0?i:`${i}${Math.round(r*255).toString(16).padStart(2,`0`)}`},randomHex=()=>`#${Math.floor(Math.random()*16777215).toString(16).padEnd(6,`0`)}`;export{hexToRgb,randomHex,rgbToHex};
|
package/lib/datetime.d.mts
CHANGED
|
@@ -1,40 +1,70 @@
|
|
|
1
1
|
import { DateLike } from "@vueuse/core";
|
|
2
2
|
interface FormatDateRangeParamsType {
|
|
3
|
-
endTimeType?:
|
|
3
|
+
endTimeType?: 'now' | 'full';
|
|
4
4
|
format?: string;
|
|
5
5
|
}
|
|
6
|
+
/**
|
|
7
|
+
* 查找给定日期是一年中的第几天
|
|
8
|
+
* @param date - 日期对象或可转换为日期的值, 默认为当前日期
|
|
9
|
+
* @returns 一年中的第几天
|
|
10
|
+
* @example
|
|
11
|
+
* getDayOfYear(new Date('2024-01-01')) -> 1
|
|
12
|
+
* getDayOfYear(new Date('2024-12-31')) -> 366
|
|
13
|
+
*/
|
|
6
14
|
declare const getDayOfYear: (date?: DateLike) => number | undefined;
|
|
15
|
+
/**
|
|
16
|
+
* 判断给定日期是否是工作日
|
|
17
|
+
* @param date - 日期对象或可转换为日期的值
|
|
18
|
+
* @returns 如果是工作日返回 true, 周末返回 false
|
|
19
|
+
* @example
|
|
20
|
+
* isWeekday(new Date('2024-12-05')) -> true
|
|
21
|
+
* isWeekday(new Date('2024-12-07')) -> false
|
|
22
|
+
*/
|
|
7
23
|
declare const isWeekday: (date?: DateLike) => boolean;
|
|
8
24
|
/**
|
|
9
|
-
*
|
|
10
|
-
* @param
|
|
11
|
-
* @param
|
|
12
|
-
* @
|
|
25
|
+
* 时间转换为标准时间格式
|
|
26
|
+
* @param time - 时间戳或日期对象, 默认为当前时间
|
|
27
|
+
* @param type - 生成时间格式, 默认为 'HH:mm:ss'
|
|
28
|
+
* @returns 格式化后的时间字符串
|
|
29
|
+
* @example
|
|
30
|
+
* useFormatTime(new Date()) -> '14:25:59'
|
|
31
|
+
* useFormatTime(1638345600000, 'HH:mm') -> '14:25'
|
|
13
32
|
*/
|
|
14
33
|
declare const useFormatTime: (time?: DateLike, type?: string) => string;
|
|
15
34
|
/**
|
|
16
|
-
*
|
|
17
|
-
* @param
|
|
18
|
-
* @param
|
|
19
|
-
* @
|
|
35
|
+
* 时间转换为标准日期格式
|
|
36
|
+
* @param time - 时间戳或日期对象, 默认为当前时间
|
|
37
|
+
* @param type - 生成日期格式, 默认为 'YYYY-MM-DD'
|
|
38
|
+
* @returns 格式化后的日期字符串
|
|
39
|
+
* @example
|
|
40
|
+
* useFormatDate(new Date()) -> '2022-11-09'
|
|
41
|
+
* useFormatDate(1638345600000, 'YYYY/MM/DD') -> '2021/12/01'
|
|
20
42
|
*/
|
|
21
43
|
declare const useFormatDate: (time?: DateLike, type?: string) => string;
|
|
22
44
|
/**
|
|
23
|
-
*
|
|
24
|
-
* @param
|
|
25
|
-
* @param
|
|
26
|
-
* @param
|
|
27
|
-
* @param
|
|
28
|
-
* @
|
|
45
|
+
* 将日期时间范围转换为请求参数格式
|
|
46
|
+
* @param timestamp - 时间范围数组 [开始时间, 结束时间]
|
|
47
|
+
* @param field - 原日期时间字段名称, 默认为 'timestamp'
|
|
48
|
+
* @param start - 开始时间字段名称, 默认为 'startTime'
|
|
49
|
+
* @param end - 结束时间字段名称, 默认为 'endTime'
|
|
50
|
+
* @returns 包含开始和结束时间的对象, 原字段设为 undefined
|
|
51
|
+
* @example
|
|
52
|
+
* useFormatDateTimeParams(['2024-01-01', '2024-12-31'])
|
|
53
|
+
* -> { timestamp: undefined, startTime: '2024-01-01', endTime: '2024-12-31' }
|
|
29
54
|
*/
|
|
30
55
|
declare const useFormatDateTimeParams: (timestamp: string[] | null | undefined, field?: string, start?: string, end?: string) => {
|
|
31
56
|
[x: string]: string | undefined;
|
|
32
57
|
} | undefined;
|
|
33
58
|
/**
|
|
34
|
-
*
|
|
35
|
-
* @param
|
|
36
|
-
* @param
|
|
37
|
-
* @
|
|
59
|
+
* 生成标准时间范围
|
|
60
|
+
* @param day - 往前推的天数, 默认为 7 天
|
|
61
|
+
* @param options - 配置选项
|
|
62
|
+
* @param options.endTimeType - 结束时间类型: 'full' 表示当天结束时刻, 'now' 表示当前时刻
|
|
63
|
+
* @param options.format - 时间格式,默认为 'YYYY-MM-DD HH:mm:ss'
|
|
64
|
+
* @returns 时间范围数组 [开始时间, 结束时间]
|
|
65
|
+
* @example
|
|
66
|
+
* useFormatDateRange(7) -> ['2024-11-28 00:00:00', '2024-12-05 23:59:59']
|
|
67
|
+
* useFormatDateRange(3, { endTimeType: 'now' }) -> ['2024-12-02 00:00:00', '2024-12-05 14:30:00']
|
|
38
68
|
*/
|
|
39
69
|
declare const useFormatDateRange: (day?: number, {
|
|
40
70
|
endTimeType,
|
package/lib/extra.d.mts
CHANGED
|
@@ -7,6 +7,10 @@
|
|
|
7
7
|
* useOmitExtraParams({ a: 1, b: 2, c: 3 }, { a: 1 })
|
|
8
8
|
*/
|
|
9
9
|
declare const useOmitExtraParams: (sourceData: object, targetData: object) => Pick<object, never>;
|
|
10
|
-
/**
|
|
10
|
+
/**
|
|
11
|
+
* 占位符常量,表示未定义的值
|
|
12
|
+
* @example
|
|
13
|
+
* const value = __ // undefined
|
|
14
|
+
*/
|
|
11
15
|
declare const __: undefined;
|
|
12
16
|
export { __, useOmitExtraParams };
|
package/lib/rules.d.mts
CHANGED
|
@@ -1,42 +1,82 @@
|
|
|
1
1
|
import { FormItemRule } from "naive-ui";
|
|
2
|
+
/**
|
|
3
|
+
* 预设验证规则类型
|
|
4
|
+
*/
|
|
2
5
|
type PresetRules = 'onlyNotChineseRule' | 'onlyChineseRule' | 'onlyNegativeIntRule' | 'onlyPositiveIntRule' | 'onlyPositiveIntZeroRule' | 'officePhoneRule' | 'mobilePhoneRule' | 'emailRule' | 'onlyNumbersRule' | 'onlyLetterRule' | 'onlyLowercaseRule' | 'onlyUppercaseRule' | 'ipRule' | 'onlyIntRule';
|
|
6
|
+
/**
|
|
7
|
+
* 验证触发时机类型
|
|
8
|
+
*/
|
|
3
9
|
type ValidationTrigger = 'input' | 'change' | 'input-number';
|
|
10
|
+
/**
|
|
11
|
+
* 验证触发时机对应的提示前缀类型
|
|
12
|
+
*/
|
|
4
13
|
type PrefixType = { [K in ValidationTrigger]: string };
|
|
14
|
+
/**
|
|
15
|
+
* 规则选项类型
|
|
16
|
+
*/
|
|
5
17
|
interface RuleOptionsType {
|
|
18
|
+
/** 是否必填 */
|
|
6
19
|
required?: boolean;
|
|
20
|
+
/** 自定义错误消息 */
|
|
7
21
|
message?: string;
|
|
8
22
|
}
|
|
23
|
+
/**
|
|
24
|
+
* 创建表单验证规则
|
|
25
|
+
* @param trigger - 验证触发时机: 'input' | 'change' | 'input-number'
|
|
26
|
+
* @param message - 错误提示消息或预设规则名称
|
|
27
|
+
* @param options - 规则选项
|
|
28
|
+
* @param options.required - 是否必填, 默认为 true
|
|
29
|
+
* @param options.message - 自定义错误消息
|
|
30
|
+
* @returns 表单验证规则对象
|
|
31
|
+
* @example
|
|
32
|
+
* // 使用自定义消息
|
|
33
|
+
* useRules('input', '用户名')
|
|
34
|
+
* // 使用预设规则
|
|
35
|
+
* useRules('input', 'emailRule', { required: true })
|
|
36
|
+
*/
|
|
9
37
|
declare function useRules(trigger: ValidationTrigger, message: string, options?: RuleOptionsType): FormItemRule;
|
|
10
38
|
declare function useRules(trigger: ValidationTrigger, message: PresetRules, options?: RuleOptionsType): FormItemRule;
|
|
11
39
|
/**
|
|
12
40
|
* 字符串输入长度限制规则
|
|
13
|
-
* @param
|
|
14
|
-
* @param
|
|
15
|
-
* @param
|
|
16
|
-
* @returns
|
|
41
|
+
* @param min - 最小长度, 默认为 0
|
|
42
|
+
* @param max - 最大长度, 未指定时使用 AppProvider 中的 stringLength 配置
|
|
43
|
+
* @param message - 自定义错误消息
|
|
44
|
+
* @returns 表单验证规则对象
|
|
45
|
+
* @example
|
|
46
|
+
* useRuleStringLength(0, 50) // 最大长度 50
|
|
47
|
+
* useRuleStringLength(5, 20, '长度必须在 5-20 之间')
|
|
17
48
|
*/
|
|
18
49
|
declare const useRuleStringLength: (min?: number, max?: number, message?: string) => FormItemRule;
|
|
19
50
|
/**
|
|
20
|
-
*
|
|
21
|
-
* @param
|
|
22
|
-
* @param
|
|
23
|
-
* @param
|
|
24
|
-
* @returns
|
|
51
|
+
* 数字输入长度限制规则(基于位数)
|
|
52
|
+
* @param min - 最小位数, 默认为 0
|
|
53
|
+
* @param max - 最大位数, 未指定时使用 AppProvider 中的 numberLength 配置
|
|
54
|
+
* @param message - 自定义错误消息
|
|
55
|
+
* @returns 表单验证规则对象
|
|
56
|
+
* @example
|
|
57
|
+
* useRuleNumberLength(0, 6) // 最多 6 位数字
|
|
58
|
+
* useRuleNumberLength(3, 10) // 3-10 位数字
|
|
25
59
|
*/
|
|
26
60
|
declare const useRuleNumberLength: (min?: number, max?: number, message?: string) => FormItemRule;
|
|
27
61
|
/**
|
|
28
|
-
*
|
|
29
|
-
* @param
|
|
30
|
-
* @param
|
|
31
|
-
* @param
|
|
32
|
-
* @returns
|
|
62
|
+
* 数字输入大小限制规则
|
|
63
|
+
* @param min - 最小值, 默认为 0
|
|
64
|
+
* @param max - 最大值的指数 (10 的 max 次方 -1), 未指定时使用 AppProvider 中的 numberSize 配置
|
|
65
|
+
* @param message - 自定义错误消息
|
|
66
|
+
* @returns 表单验证规则对象
|
|
67
|
+
* @example
|
|
68
|
+
* useRuleNumberSize(0, 3) // 0-999
|
|
69
|
+
* useRuleNumberSize(10, 5) // 10-99999
|
|
33
70
|
*/
|
|
34
71
|
declare const useRuleNumberSize: (min?: number, max?: number, message?: string) => FormItemRule;
|
|
35
72
|
/**
|
|
36
73
|
* 小数位数限制规则
|
|
37
|
-
* @param
|
|
38
|
-
* @param
|
|
39
|
-
* @returns
|
|
74
|
+
* @param place - 允许的最大小数位数, 未指定时使用 AppProvider 中的 decimalPlace 配置,默认为 2
|
|
75
|
+
* @param message - 自定义错误消息
|
|
76
|
+
* @returns 表单验证规则对象
|
|
77
|
+
* @example
|
|
78
|
+
* useRuleDecimalPlace(2) // 最多 2 位小数
|
|
79
|
+
* useRuleDecimalPlace(4, '最多保留4位小数')
|
|
40
80
|
*/
|
|
41
81
|
declare const useRuleDecimalPlace: (place?: number, message?: string) => FormItemRule;
|
|
42
82
|
export { PrefixType, PresetRules, ValidationTrigger, useRuleDecimalPlace, useRuleNumberLength, useRuleNumberSize, useRuleStringLength, useRules };
|