lyb-js 1.0.2 → 1.0.3
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.md +406 -9
- package/dist/Base/LibGetDataType/index.d.ts +3 -3
- package/dist/Base/LibGetDataType/index.js +3 -3
- package/dist/Browser/LibColorConsole/index.d.ts +2 -2
- package/dist/Browser/LibColorConsole/index.js +3 -3
- package/dist/Browser/LibIsMobile/index.d.ts +1 -1
- package/dist/Browser/LibIsMobile/index.js +1 -1
- package/dist/Browser/LibIsPad/index.d.ts +1 -1
- package/dist/Browser/LibIsPad/index.js +1 -1
- package/dist/Browser/LibPathParams/index.d.ts +1 -1
- package/dist/Browser/LibPathParams/index.js +1 -1
- package/dist/Data/LibChunkArray/index.d.ts +1 -1
- package/dist/Data/LibChunkArray/index.js +1 -1
- package/dist/Data/LibDeepJSONParse/index.d.ts +1 -1
- package/dist/Data/LibDeepJSONParse/index.js +7 -7
- package/dist/Data/LibGroupArrayByKey/index.d.ts +4 -4
- package/dist/Data/LibGroupArrayByKey/index.js +4 -4
- package/dist/Data/LibMatchEmail/index.d.ts +1 -1
- package/dist/Data/LibMatchEmail/index.js +1 -1
- package/dist/Data/LibShuffleArray/index.d.ts +2 -2
- package/dist/Data/LibShuffleArray/index.js +2 -2
- package/dist/Data/LibStepArray/index.d.ts +1 -1
- package/dist/Data/LibStepArray/index.js +1 -1
- package/dist/File/LibDownloadImageLink/index.d.ts +2 -2
- package/dist/File/LibDownloadImageLink/index.js +2 -2
- package/dist/File/LibImageOptimizer/index.d.ts +5 -5
- package/dist/File/LibImageOptimizer/index.js +4 -4
- package/dist/File/LibSaveJson/index.d.ts +1 -0
- package/dist/File/LibSaveJson/index.js +1 -0
- package/dist/Formatter/LibFormatterByte/index.d.ts +1 -1
- package/dist/Formatter/LibFormatterByte/index.js +1 -1
- package/dist/Formatter/LibMaskPhoneNumber/index.d.ts +3 -3
- package/dist/Formatter/LibMaskPhoneNumber/index.js +3 -3
- package/dist/Formatter/LibNumComma/index.d.ts +1 -1
- package/dist/Formatter/LibNumComma/index.js +1 -1
- package/dist/Formatter/LibNumberUnit/index.d.ts +1 -1
- package/dist/Formatter/LibNumberUnit/index.js +1 -1
- package/dist/Formatter/LibSecondsFormatterChinese/index.d.ts +11 -0
- package/dist/Formatter/LibSecondsFormatterChinese/index.js +42 -0
- package/dist/Math/LibCalculateExpression/index.d.ts +1 -2
- package/dist/Math/LibCalculateExpression/index.js +17 -18
- package/dist/Math/LibConvertAngle/index.d.ts +4 -4
- package/dist/Math/LibConvertAngle/index.js +4 -4
- package/dist/Math/LibCoordsAngle/index.d.ts +3 -3
- package/dist/Math/LibCoordsAngle/index.js +8 -8
- package/dist/Math/LibCoordsDistance/index.d.ts +3 -3
- package/dist/Math/LibCoordsDistance/index.js +5 -5
- package/dist/Math/LibDecimal/index.d.ts +3 -4
- package/dist/Math/LibDecimal/index.js +3 -4
- package/dist/Misc/LibRegFormValidate/index.d.ts +9 -9
- package/dist/Misc/LibRegFormValidate/index.js +9 -9
- package/dist/Random/LibProbabilityResult/index.d.ts +3 -3
- package/dist/Random/LibProbabilityResult/index.js +3 -3
- package/dist/Random/LibRandom/index.d.ts +3 -4
- package/dist/Random/LibRandom/index.js +3 -4
- package/dist/Random/LibRandomColor/index.d.ts +2 -2
- package/dist/Random/LibRandomColor/index.js +2 -2
- package/dist/Random/LibUniqueRandomNumbers/index.d.ts +3 -3
- package/dist/Random/LibUniqueRandomNumbers/index.js +3 -3
- package/dist/Time/LibSameTimeCheck/index.d.ts +5 -1
- package/dist/Time/LibSameTimeCheck/index.js +5 -1
- package/dist/Time/LibTimeAgo/index.d.ts +4 -4
- package/dist/Time/LibTimeAgo/index.js +4 -4
- package/dist/Time/LibTimeGreeting/index.d.ts +5 -5
- package/dist/Time/LibTimeGreeting/index.js +5 -5
- package/dist/lib.d.ts +77 -78
- package/dist/lib.js +78 -79
- package/package.json +1 -1
- package/test/index.js +0 -0
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
/** @description
|
|
1
|
+
/** @description 随机获取两个数之间的值,包含两数自身
|
|
2
2
|
* @param min 最小值
|
|
3
3
|
* @param max 最大值
|
|
4
4
|
* @param num 保留小数位数
|
|
5
5
|
* @example
|
|
6
|
-
* libRandom(1, 10); //
|
|
7
|
-
* libRandom(1, 10, 2); //
|
|
8
|
-
* libRandom(5, 5, 3); // 返回 5.000
|
|
6
|
+
* libRandom(1, 10); //1 到 10 之间的随机整数
|
|
7
|
+
* libRandom(1, 10, 2); //1 到 10 之间保留两位小数的随机数
|
|
9
8
|
*/
|
|
10
9
|
export const libRandom = (min, max, num = 0) => {
|
|
11
10
|
return parseFloat((Math.random() * (max - min) + min).toFixed(num));
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/** @description 随机 RGBA 颜色
|
|
2
2
|
* @param alpha 透明度
|
|
3
3
|
* @example
|
|
4
|
-
* libRandomColor();
|
|
5
|
-
* libRandomColor(0.5);
|
|
4
|
+
* libRandomColor(); //生成随机的 RGBA 颜色,默认透明度 1
|
|
5
|
+
* libRandomColor(0.5); //生成随机的 RGBA 颜色,透明度为 0.5
|
|
6
6
|
*/
|
|
7
7
|
export declare const libRandomColor: (alpha?: number) => string;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/** @description 随机 RGBA 颜色
|
|
2
2
|
* @param alpha 透明度
|
|
3
3
|
* @example
|
|
4
|
-
* libRandomColor();
|
|
5
|
-
* libRandomColor(0.5);
|
|
4
|
+
* libRandomColor(); //生成随机的 RGBA 颜色,默认透明度 1
|
|
5
|
+
* libRandomColor(0.5); //生成随机的 RGBA 颜色,透明度为 0.5
|
|
6
6
|
*/
|
|
7
7
|
export const libRandomColor = (alpha = 1) => {
|
|
8
8
|
const r = Math.floor(Math.random() * 256);
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
/** @description
|
|
1
|
+
/** @description 随机生成指定个数、指定范围不重复的随机数数组
|
|
2
2
|
* @param min 最小值
|
|
3
3
|
* @param max 最大值
|
|
4
4
|
* @param count 数组长度
|
|
5
5
|
* @example
|
|
6
|
-
* libUniqueRandomNumbers(1, 10, 5);
|
|
7
|
-
* libUniqueRandomNumbers(1, 100, 10);
|
|
6
|
+
* libUniqueRandomNumbers(1, 10, 5); //从 1 到 10 中随机生成 5 个唯一数字
|
|
7
|
+
* libUniqueRandomNumbers(1, 100, 10); //从 1 到 100 中随机生成 10 个唯一数字
|
|
8
8
|
*/
|
|
9
9
|
export declare const libUniqueRandomNumbers: (min: number, max: number, count: number) => number[];
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
/** @description
|
|
1
|
+
/** @description 随机生成指定个数、指定范围不重复的随机数数组
|
|
2
2
|
* @param min 最小值
|
|
3
3
|
* @param max 最大值
|
|
4
4
|
* @param count 数组长度
|
|
5
5
|
* @example
|
|
6
|
-
* libUniqueRandomNumbers(1, 10, 5);
|
|
7
|
-
* libUniqueRandomNumbers(1, 100, 10);
|
|
6
|
+
* libUniqueRandomNumbers(1, 10, 5); //从 1 到 10 中随机生成 5 个唯一数字
|
|
7
|
+
* libUniqueRandomNumbers(1, 100, 10); //从 1 到 100 中随机生成 10 个唯一数字
|
|
8
8
|
*/
|
|
9
9
|
export const libUniqueRandomNumbers = (min, max, count) => {
|
|
10
10
|
const numbers = Array.from({ length: max - min + 1 }, (_, i) => i + min);
|
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
import dayjs from "dayjs";
|
|
2
2
|
/**
|
|
3
|
-
* @description
|
|
3
|
+
* @description 传入时间戳与当前时间判断是否为同一分、同一时、同一天、同一周、同一月、同一年
|
|
4
4
|
* @param timestamp 毫秒时间戳
|
|
5
5
|
* @param unit 判断单位
|
|
6
6
|
* @returns 0-同一单位时间 1-新单位时间 -1时间戳大于当前时间
|
|
7
|
+
* @example
|
|
8
|
+
* const timestamp = 1679872800000; //时间戳
|
|
9
|
+
* const result = libSameTimeCheck(timestamp, 'day'); //判断是否为同一天
|
|
10
|
+
* console.log(result); //0: 同一天, 1: 新的一天, -1: 时间戳大于当前时间
|
|
7
11
|
*/
|
|
8
12
|
export declare const libSameTimeCheck: (timestamp: number, unit: dayjs.OpUnitType) => 0 | 1 | -1;
|
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
import dayjs from "dayjs";
|
|
2
2
|
/**
|
|
3
|
-
* @description
|
|
3
|
+
* @description 传入时间戳与当前时间判断是否为同一分、同一时、同一天、同一周、同一月、同一年
|
|
4
4
|
* @param timestamp 毫秒时间戳
|
|
5
5
|
* @param unit 判断单位
|
|
6
6
|
* @returns 0-同一单位时间 1-新单位时间 -1时间戳大于当前时间
|
|
7
|
+
* @example
|
|
8
|
+
* const timestamp = 1679872800000; //时间戳
|
|
9
|
+
* const result = libSameTimeCheck(timestamp, 'day'); //判断是否为同一天
|
|
10
|
+
* console.log(result); //0: 同一天, 1: 新的一天, -1: 时间戳大于当前时间
|
|
7
11
|
*/
|
|
8
12
|
export const libSameTimeCheck = (timestamp, unit) => {
|
|
9
13
|
const inputTime = dayjs(timestamp).startOf(unit);
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/** @description 时间差计算
|
|
2
2
|
* @param timestamp 毫秒时间戳
|
|
3
3
|
* @example
|
|
4
|
-
* libTimeAgotamp(Date.now() - 3600000); //
|
|
5
|
-
* libTimeAgotamp(Date.now() - 86400000); //
|
|
6
|
-
* libTimeAgotamp(Date.now() - 31536000000); //
|
|
7
|
-
* libTimeAgotamp(Date.now() - 10000); //
|
|
4
|
+
* libTimeAgotamp(Date.now() - 3600000); //"1 小时前"
|
|
5
|
+
* libTimeAgotamp(Date.now() - 86400000); //"1 天前"
|
|
6
|
+
* libTimeAgotamp(Date.now() - 31536000000); //"1 年前"
|
|
7
|
+
* libTimeAgotamp(Date.now() - 10000); //"刚刚"
|
|
8
8
|
*/
|
|
9
9
|
export declare const libTimeAgo: (timestamp: number) => string;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/** @description 时间差计算
|
|
2
2
|
* @param timestamp 毫秒时间戳
|
|
3
3
|
* @example
|
|
4
|
-
* libTimeAgotamp(Date.now() - 3600000); //
|
|
5
|
-
* libTimeAgotamp(Date.now() - 86400000); //
|
|
6
|
-
* libTimeAgotamp(Date.now() - 31536000000); //
|
|
7
|
-
* libTimeAgotamp(Date.now() - 10000); //
|
|
4
|
+
* libTimeAgotamp(Date.now() - 3600000); //"1 小时前"
|
|
5
|
+
* libTimeAgotamp(Date.now() - 86400000); //"1 天前"
|
|
6
|
+
* libTimeAgotamp(Date.now() - 31536000000); //"1 年前"
|
|
7
|
+
* libTimeAgotamp(Date.now() - 10000); //"刚刚"
|
|
8
8
|
*/
|
|
9
9
|
export const libTimeAgo = (timestamp) => {
|
|
10
10
|
const timeUnits = [
|
|
@@ -7,11 +7,11 @@ export interface LibTimeGreetingParams {
|
|
|
7
7
|
evening?: string;
|
|
8
8
|
}
|
|
9
9
|
/**
|
|
10
|
-
* @description
|
|
11
|
-
* @param greet
|
|
10
|
+
* @description 根据当前时间返回问候语
|
|
11
|
+
* @param greet 自定义问候语对象
|
|
12
12
|
* @example
|
|
13
|
-
* libTimeGreeting();
|
|
14
|
-
* libTimeGreeting({ morning: "早安" });
|
|
15
|
-
* libTimeGreeting({ afternoon: "午后好" });
|
|
13
|
+
* libTimeGreeting(); //根据当前时间返回默认问候语
|
|
14
|
+
* libTimeGreeting({ morning: "早安" }); //自定义早上问候语
|
|
15
|
+
* libTimeGreeting({ afternoon: "午后好" }); //自定义下午问候语
|
|
16
16
|
*/
|
|
17
17
|
export declare const libTimeGreeting: (greet?: LibTimeGreetingParams) => string;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @description
|
|
3
|
-
* @param greet
|
|
2
|
+
* @description 根据当前时间返回问候语
|
|
3
|
+
* @param greet 自定义问候语对象
|
|
4
4
|
* @example
|
|
5
|
-
* libTimeGreeting();
|
|
6
|
-
* libTimeGreeting({ morning: "早安" });
|
|
7
|
-
* libTimeGreeting({ afternoon: "午后好" });
|
|
5
|
+
* libTimeGreeting(); //根据当前时间返回默认问候语
|
|
6
|
+
* libTimeGreeting({ morning: "早安" }); //自定义早上问候语
|
|
7
|
+
* libTimeGreeting({ afternoon: "午后好" }); //自定义下午问候语
|
|
8
8
|
*/
|
|
9
9
|
export const libTimeGreeting = (greet = {}) => {
|
|
10
10
|
const { midnight = "午夜好", morning = "早上好", forenoon = "上午好", noon = "中午好", afternoon = "下午好", evening = "晚上好", } = greet;
|
package/dist/lib.d.ts
CHANGED
|
@@ -4,9 +4,9 @@ export declare const Base: {
|
|
|
4
4
|
* @description 返回数据类型
|
|
5
5
|
* @param v 需要判断类型的数据
|
|
6
6
|
* @example
|
|
7
|
-
* libGetDataType(123); //
|
|
8
|
-
* libGetDataType("hello"); //
|
|
9
|
-
* libGetDataType([1, 2, 3]); //
|
|
7
|
+
* libGetDataType(123); //"number"
|
|
8
|
+
* libGetDataType("hello"); //"string"
|
|
9
|
+
* libGetDataType([1, 2, 3]); //"array"
|
|
10
10
|
*/
|
|
11
11
|
libGetDataType: (v: any) => import("./Base/LibGetDataType").LibGetDataTypeReturnType;
|
|
12
12
|
/**
|
|
@@ -27,10 +27,10 @@ export declare const Browser: {
|
|
|
27
27
|
* @param color 颜色
|
|
28
28
|
* @param logs 信息
|
|
29
29
|
* @example
|
|
30
|
-
*
|
|
30
|
+
* //使用红色打印日志
|
|
31
31
|
* libColorConsole("错误提示", "red", [{ label: "错误代码", value: 500 }]);
|
|
32
32
|
*
|
|
33
|
-
*
|
|
33
|
+
* //使用蓝色打印简单日志
|
|
34
34
|
* libColorConsole("信息", "blue", "操作成功");
|
|
35
35
|
*/
|
|
36
36
|
libColorConsole: (title: string, color: "red" | "orange" | "yellow" | "green" | "blue" | "purple", logs?: {
|
|
@@ -40,19 +40,19 @@ export declare const Browser: {
|
|
|
40
40
|
/** @description 判断是否为移动设备
|
|
41
41
|
* @example
|
|
42
42
|
* const isMobile = libIsMobile();
|
|
43
|
-
* console.log(isMobile); //
|
|
43
|
+
* console.log(isMobile); //true 或 false
|
|
44
44
|
*/
|
|
45
45
|
libIsMobile: () => boolean;
|
|
46
46
|
/** @description 判断是否为平板
|
|
47
47
|
* @example
|
|
48
48
|
* const isPad = libIsPad();
|
|
49
|
-
* console.log(isPad); //
|
|
49
|
+
* console.log(isPad); //true 或 false
|
|
50
50
|
*/
|
|
51
51
|
libIsPad: () => boolean;
|
|
52
52
|
/** @description 获取浏览器地址栏参数
|
|
53
53
|
* @example
|
|
54
54
|
* const params = libPathParams();
|
|
55
|
-
* console.log(params); //
|
|
55
|
+
* console.log(params); //{ param1: "value1", param2: "value2" }
|
|
56
56
|
*/
|
|
57
57
|
libPathParams: () => Record<string, string>;
|
|
58
58
|
/** @description 动态设置网站标题及图标
|
|
@@ -78,23 +78,23 @@ export declare const Data: {
|
|
|
78
78
|
* @param chunkSize 每个数组的元素数量
|
|
79
79
|
* @example
|
|
80
80
|
* const chunks = libChunkArray([1, 2, 3, 4, 5, 6], 2);
|
|
81
|
-
* console.log(chunks); //
|
|
81
|
+
* console.log(chunks); //[[1, 2], [3, 4], [5, 6]]
|
|
82
82
|
*/
|
|
83
83
|
libChunkArray: <T>(arr: T[], chunkSize: number) => T[][];
|
|
84
84
|
/** @description 递归将JSON字符串深度解析为对象
|
|
85
85
|
* @example
|
|
86
86
|
* const obj = libDeepJSONParse('{"a": 1, "b": "{\"c\": 2}"}');
|
|
87
|
-
* console.log(obj); //
|
|
87
|
+
* console.log(obj); //{ a: 1, b: { c: 2 } }
|
|
88
88
|
*/
|
|
89
89
|
libDeepJSONParse: <T>(data: any) => T;
|
|
90
90
|
/**
|
|
91
91
|
* @description 分类汇总,将数组对象按照指定键值整理成一个以键值为键名的对象
|
|
92
|
-
* @param arr
|
|
93
|
-
* @param key
|
|
94
|
-
* @returns
|
|
92
|
+
* @param arr 要分组的数组
|
|
93
|
+
* @param key 分组的键
|
|
94
|
+
* @returns 分组后的对象
|
|
95
95
|
* @example
|
|
96
96
|
* const grouped = libGroupArrayByKey([{ id: 1, name: 'A' }, { id: 2, name: 'B' }, { id: 1, name: 'C' }], 'id');
|
|
97
|
-
* console.log(grouped); //
|
|
97
|
+
* console.log(grouped); //{ 1: [{ id: 1, name: 'A' }, { id: 1, name: 'C' }], 2: [{ id: 2, name: 'B' }] }
|
|
98
98
|
*/
|
|
99
99
|
libGroupArrayByKey: (arr: any[] | undefined, key: string) => any;
|
|
100
100
|
/**
|
|
@@ -104,14 +104,14 @@ export declare const Data: {
|
|
|
104
104
|
* @returns 匹配结果数组
|
|
105
105
|
* @example
|
|
106
106
|
* const emails = libMatchEmail("user", ["@gmail.com", "@yahoo.com"]);
|
|
107
|
-
* console.log(emails); //
|
|
107
|
+
* console.log(emails); //["user@gmail.com", "user@yahoo.com"]
|
|
108
108
|
*/
|
|
109
109
|
libMatchEmail: (str: string, emailList: string[]) => string[];
|
|
110
110
|
/** @description 数组乱序
|
|
111
111
|
* @param arr 需要乱序的数组
|
|
112
112
|
* @example
|
|
113
113
|
* const shuffled = libShuffleArray([1, 2, 3, 4, 5]);
|
|
114
|
-
* console.log(shuffled); //
|
|
114
|
+
* console.log(shuffled); //[3, 5, 2, 1, 4] (结果每次不同)
|
|
115
115
|
*/
|
|
116
116
|
libShuffleArray: <T>(arr: T[]) => T[];
|
|
117
117
|
/** @description 数组元素整体步数移动
|
|
@@ -119,7 +119,7 @@ export declare const Data: {
|
|
|
119
119
|
* @param step 负数为向后移动,正数为向前移动
|
|
120
120
|
* @example
|
|
121
121
|
* const moved = libStepArray([1, 2, 3, 4, 5], 2);
|
|
122
|
-
* console.log(moved); //
|
|
122
|
+
* console.log(moved); //[4, 5, 1, 2, 3]
|
|
123
123
|
*/
|
|
124
124
|
libStepArray: <T>(arr: T[], step: number) => T[];
|
|
125
125
|
};
|
|
@@ -135,7 +135,7 @@ export declare const File: {
|
|
|
135
135
|
/** @description 图片压缩
|
|
136
136
|
* @param obj 压缩参数
|
|
137
137
|
* @example
|
|
138
|
-
*
|
|
138
|
+
* //图片压缩使用示例
|
|
139
139
|
* libImageOptimizerOptionsParams({
|
|
140
140
|
* file: myFile,
|
|
141
141
|
* ratio: 0.8,
|
|
@@ -167,15 +167,15 @@ export declare const Formatter: {
|
|
|
167
167
|
* @returns ['大小', '单位', '大小及单位']
|
|
168
168
|
* @example
|
|
169
169
|
* const [size, unit, formatted] = libFormatterByte(2048);
|
|
170
|
-
* console.log(size, unit, formatted); //
|
|
170
|
+
* console.log(size, unit, formatted); //2.00 KB 2.00 KB
|
|
171
171
|
*/
|
|
172
172
|
libFormatterByte: (bytes: number) => (string | number)[];
|
|
173
173
|
/**
|
|
174
|
-
* @description
|
|
175
|
-
* @param mobile
|
|
174
|
+
* @description 隐藏手机号码中间的四位数字
|
|
175
|
+
* @param mobile 需要处理的手机号码
|
|
176
176
|
* @example
|
|
177
177
|
* const masked = libMaskPhoneNumber("13812345678");
|
|
178
|
-
* console.log(masked); //
|
|
178
|
+
* console.log(masked); //138****5678
|
|
179
179
|
*/
|
|
180
180
|
libMaskPhoneNumber: (mobile: number | string) => string;
|
|
181
181
|
/**
|
|
@@ -184,7 +184,7 @@ export declare const Formatter: {
|
|
|
184
184
|
* @param reserve 保留小数位数
|
|
185
185
|
* @example
|
|
186
186
|
* const formatted = libNumComma(1234567.89);
|
|
187
|
-
* console.log(formatted); //
|
|
187
|
+
* console.log(formatted); //1,234,567.89
|
|
188
188
|
*/
|
|
189
189
|
libNumComma: (num: number, reserve?: number) => string;
|
|
190
190
|
/** @description 将大于1000的数字使用k为单位
|
|
@@ -193,9 +193,20 @@ export declare const Formatter: {
|
|
|
193
193
|
* @returns [数字, 单位]
|
|
194
194
|
* @example
|
|
195
195
|
* const [value, unit] = libNumberUnit(1500, { K: 1000, M: 1000000 });
|
|
196
|
-
* console.log(value, unit); //
|
|
196
|
+
* console.log(value, unit); //1.50 K
|
|
197
197
|
*/
|
|
198
198
|
libNumberUnit: (num: number, units: import("./Formatter/LibNumberUnit").LibNumberUnitParams) => string[];
|
|
199
|
+
/**
|
|
200
|
+
* @description 将秒数格式化为中文时间描述,支持扩展到年和月
|
|
201
|
+
* @param seconds 秒数
|
|
202
|
+
* @returns 格式化后的中文时间
|
|
203
|
+
* @example
|
|
204
|
+
* libSecondsFormatterChinese(100000); //"1天3小时46分40秒"
|
|
205
|
+
* libSecondsFormatterChinese(31536000); //"1年"
|
|
206
|
+
* libSecondsFormatterChinese(3600); //"1小时"
|
|
207
|
+
* libSecondsFormatterChinese(90); //"1分30秒"
|
|
208
|
+
*/
|
|
209
|
+
libSecondsFormatterChinese: (seconds: number) => string;
|
|
199
210
|
};
|
|
200
211
|
/** @description 数学相关方法 */
|
|
201
212
|
export declare const Math: {
|
|
@@ -206,7 +217,7 @@ export declare const Math: {
|
|
|
206
217
|
*
|
|
207
218
|
* @example
|
|
208
219
|
* const result = libCalculateExpression("(1+2)-(3*4)/5");
|
|
209
|
-
* console.log(result); //
|
|
220
|
+
* console.log(result); //0.6
|
|
210
221
|
*/
|
|
211
222
|
libCalculateExpression: (expression: string, point?: number) => number;
|
|
212
223
|
/**
|
|
@@ -214,20 +225,20 @@ export declare const Math: {
|
|
|
214
225
|
* @param value 角度值或弧度值
|
|
215
226
|
* @param type 角度类型或弧度类型
|
|
216
227
|
* @example
|
|
217
|
-
*
|
|
218
|
-
* libConvertAngle(90, "rad");
|
|
228
|
+
* //角度转弧度
|
|
229
|
+
* libConvertAngle(90, "rad"); //返回 1.5708... (π/2)
|
|
219
230
|
*
|
|
220
|
-
*
|
|
221
|
-
* libConvertAngle(Math.PI, "deg");
|
|
231
|
+
* //弧度转角度
|
|
232
|
+
* libConvertAngle(Math.PI, "deg"); //返回 180
|
|
222
233
|
*/
|
|
223
234
|
libConvertAngle: (value: number, type: "rad" | "deg") => number;
|
|
224
235
|
/** @description 计算两点角度
|
|
225
236
|
* @param coord1 起点坐标
|
|
226
237
|
* @param coord2 终点坐标
|
|
227
238
|
* @example
|
|
228
|
-
* libCoordsAngle({ x: 0, y: 0 }, { x: 1, y: 0 }); //
|
|
229
|
-
* libCoordsAngle({ x: 0, y: 0 }, { x: 1, y: 1 }); //
|
|
230
|
-
* libCoordsAngle({ x: 0, y: 0 }, { x: 0, y: 1 }); //
|
|
239
|
+
* libCoordsAngle({ x: 0, y: 0 }, { x: 1, y: 0 }); //0
|
|
240
|
+
* libCoordsAngle({ x: 0, y: 0 }, { x: 1, y: 1 }); //45
|
|
241
|
+
* libCoordsAngle({ x: 0, y: 0 }, { x: 0, y: 1 }); //90
|
|
231
242
|
*/
|
|
232
243
|
libCoordsAngle: (coord1: {
|
|
233
244
|
x: number;
|
|
@@ -240,9 +251,9 @@ export declare const Math: {
|
|
|
240
251
|
* @param coord1 起点坐标
|
|
241
252
|
* @param coord2 终点坐标
|
|
242
253
|
* @example
|
|
243
|
-
* libCoordsDistance({ x: 0, y: 0 }, { x: 3, y: 4 }); //
|
|
244
|
-
* libCoordsDistance({ x: 1, y: 1 }, { x: 4, y: 5 }); //
|
|
245
|
-
* libCoordsDistance({ x: 0, y: 0 }, { x: 0, y: 0 }); //
|
|
254
|
+
* libCoordsDistance({ x: 0, y: 0 }, { x: 3, y: 4 }); //5
|
|
255
|
+
* libCoordsDistance({ x: 1, y: 1 }, { x: 4, y: 5 }); //5
|
|
256
|
+
* libCoordsDistance({ x: 0, y: 0 }, { x: 0, y: 0 }); //0
|
|
246
257
|
*/
|
|
247
258
|
libCoordsDistance: (coord1: {
|
|
248
259
|
x: number;
|
|
@@ -256,20 +267,19 @@ export declare const Math: {
|
|
|
256
267
|
* @param num2 第二个数
|
|
257
268
|
* @param operator 运算符,支持加减乘除
|
|
258
269
|
* @example
|
|
259
|
-
* //
|
|
260
|
-
* libDecimal(10, 3, "
|
|
261
|
-
* libDecimal(10, 3, "
|
|
262
|
-
* libDecimal(10, 3, "/", 2); // 3.33
|
|
270
|
+
* libDecimal(10, 3, "+"); //13
|
|
271
|
+
* libDecimal(10, 3, "-"); //7
|
|
272
|
+
* libDecimal(10, 3, "/", 2); //3.33
|
|
263
273
|
*/
|
|
264
274
|
libDecimal: (num1: number, num2: number, operator: "+" | "-" | "*" | "/", point?: number) => number;
|
|
265
275
|
};
|
|
266
276
|
/** @description 杂项相关方法 */
|
|
267
277
|
export declare const Misc: {
|
|
268
278
|
/**
|
|
269
|
-
* @description
|
|
270
|
-
* @param form
|
|
271
|
-
* @param rules
|
|
272
|
-
* @returns
|
|
279
|
+
* @description 表单验证函数
|
|
280
|
+
* @param form 表单数据对象
|
|
281
|
+
* @param rules 验证规则数组
|
|
282
|
+
* @returns 验证结果数组,包含未通过验证的项
|
|
273
283
|
* @example
|
|
274
284
|
* const form = { username: "john", email: "john@example.com" };
|
|
275
285
|
* const rules = [
|
|
@@ -277,14 +287,14 @@ export declare const Misc: {
|
|
|
277
287
|
* { key: "email", verify: /^\S+@\S+\.\S+$/, msg: "邮箱格式不正确", name: "邮箱" },
|
|
278
288
|
* ];
|
|
279
289
|
* libRegFormValidate(form, rules);
|
|
280
|
-
*
|
|
290
|
+
* //返回结果: []
|
|
281
291
|
*
|
|
282
292
|
* const invalidForm = { username: "jo", email: "invalid-email" };
|
|
283
293
|
* libRegFormValidate(invalidForm, rules);
|
|
284
|
-
*
|
|
285
|
-
* //
|
|
286
|
-
* //
|
|
287
|
-
* //
|
|
294
|
+
* //返回结果: [
|
|
295
|
+
* // { key: "username", msg: "用户名不合法", name: "用户名" },
|
|
296
|
+
* // { key: "email", msg: "邮箱格式不正确", name: "邮箱" }
|
|
297
|
+
* //]
|
|
288
298
|
*/
|
|
289
299
|
libRegFormValidate: (form: Record<string, any>, rules: Array<{
|
|
290
300
|
key: string;
|
|
@@ -322,9 +332,9 @@ export declare const Random: {
|
|
|
322
332
|
/** @description 百分比概率结果
|
|
323
333
|
* @param probability 触发概率,百分比,0-100
|
|
324
334
|
* @example
|
|
325
|
-
* libProbabilityResult(50); //
|
|
326
|
-
* libProbabilityResult(80); //
|
|
327
|
-
* libProbabilityResult(100); //
|
|
335
|
+
* libProbabilityResult(50); //50% 概率为 true
|
|
336
|
+
* libProbabilityResult(80); //80% 概率为 true
|
|
337
|
+
* libProbabilityResult(100); //100% 概率为 true
|
|
328
338
|
*/
|
|
329
339
|
libProbabilityResult: (probability: number) => boolean;
|
|
330
340
|
/** @description 随机数
|
|
@@ -332,16 +342,16 @@ export declare const Random: {
|
|
|
332
342
|
* @param max 最大值
|
|
333
343
|
* @param num 保留小数位数
|
|
334
344
|
* @example
|
|
335
|
-
* libRandom(1, 10); //
|
|
336
|
-
* libRandom(1, 10, 2); //
|
|
337
|
-
* libRandom(5, 5, 3);
|
|
345
|
+
* libRandom(1, 10); //1 到 10 之间的随机整数
|
|
346
|
+
* libRandom(1, 10, 2); //1 到 10 之间保留两位小数的随机数
|
|
347
|
+
* libRandom(5, 5, 3); //返回 5.000
|
|
338
348
|
*/
|
|
339
349
|
libRandom: (min: number, max: number, num?: number) => number;
|
|
340
350
|
/** @description 随机 RGBA 颜色
|
|
341
351
|
* @param alpha 透明度
|
|
342
352
|
* @example
|
|
343
|
-
* libRandomColor();
|
|
344
|
-
* libRandomColor(0.5);
|
|
353
|
+
* libRandomColor(); //生成随机的 RGBA 颜色,默认透明度 1
|
|
354
|
+
* libRandomColor(0.5); //生成随机的 RGBA 颜色,透明度为 0.5
|
|
345
355
|
*/
|
|
346
356
|
libRandomColor: (alpha?: number) => string;
|
|
347
357
|
/** @description 随机生成n个指定范围的随机数数组
|
|
@@ -349,8 +359,8 @@ export declare const Random: {
|
|
|
349
359
|
* @param max 最大值
|
|
350
360
|
* @param count 数组长度
|
|
351
361
|
* @example
|
|
352
|
-
* libUniqueRandomNumbers(1, 10, 5);
|
|
353
|
-
* libUniqueRandomNumbers(1, 100, 10);
|
|
362
|
+
* libUniqueRandomNumbers(1, 10, 5); //从 1 到 10 中随机生成 5 个唯一数字
|
|
363
|
+
* libUniqueRandomNumbers(1, 100, 10); //从 1 到 100 中随机生成 10 个唯一数字
|
|
354
364
|
*/
|
|
355
365
|
libUniqueRandomNumbers: (min: number, max: number, count: number) => number[];
|
|
356
366
|
};
|
|
@@ -363,33 +373,22 @@ export declare const Time: {
|
|
|
363
373
|
* @returns 0-同一单位时间 1-新单位时间 -1时间戳大于当前时间
|
|
364
374
|
*/
|
|
365
375
|
libSameTimeCheck: (timestamp: number, unit: import("dayjs").OpUnitType) => 0 | 1 | -1;
|
|
366
|
-
/**
|
|
367
|
-
* @description 将秒数格式化为中文时间描述,支持扩展到年和月。
|
|
368
|
-
* @param seconds 秒数
|
|
369
|
-
* @returns 格式化后的中文时间
|
|
370
|
-
* @example
|
|
371
|
-
* libSecondsFormatterChinese(100000); // "1天3小时46分40秒"
|
|
372
|
-
* libSecondsFormatterChinese(31536000); // "1年"
|
|
373
|
-
* libSecondsFormatterChinese(3600); // "1小时"
|
|
374
|
-
* libSecondsFormatterChinese(90); // "1分30秒"
|
|
375
|
-
*/
|
|
376
|
-
libSecondsFormatterChinese: (seconds: number) => string;
|
|
377
376
|
/** @description 时间差计算
|
|
378
377
|
* @param timestamp 毫秒时间戳
|
|
379
378
|
* @example
|
|
380
|
-
* libTimeAgotamp(Date.now() - 3600000); //
|
|
381
|
-
* libTimeAgotamp(Date.now() - 86400000); //
|
|
382
|
-
* libTimeAgotamp(Date.now() - 31536000000); //
|
|
383
|
-
* libTimeAgotamp(Date.now() - 10000); //
|
|
379
|
+
* libTimeAgotamp(Date.now() - 3600000); //"1 小时前"
|
|
380
|
+
* libTimeAgotamp(Date.now() - 86400000); //"1 天前"
|
|
381
|
+
* libTimeAgotamp(Date.now() - 31536000000); //"1 年前"
|
|
382
|
+
* libTimeAgotamp(Date.now() - 10000); //"刚刚"
|
|
384
383
|
*/
|
|
385
384
|
libTimeAgo: (timestamp: number) => string;
|
|
386
385
|
/**
|
|
387
|
-
* @description
|
|
388
|
-
* @param greet
|
|
386
|
+
* @description 根据当前时间返回问候语
|
|
387
|
+
* @param greet 自定义问候语对象
|
|
389
388
|
* @example
|
|
390
|
-
* libTimeGreeting();
|
|
391
|
-
* libTimeGreeting({ morning: "早安" });
|
|
392
|
-
* libTimeGreeting({ afternoon: "午后好" });
|
|
389
|
+
* libTimeGreeting(); //根据当前时间返回默认问候语
|
|
390
|
+
* libTimeGreeting({ morning: "早安" }); //自定义早上问候语
|
|
391
|
+
* libTimeGreeting({ afternoon: "午后好" }); //自定义下午问候语
|
|
393
392
|
*/
|
|
394
393
|
libTimeGreeting: (greet?: import("./Time/LibTimeGreeting").LibTimeGreetingParams) => string;
|
|
395
394
|
};
|