lyb-js 1.1.5 → 1.1.6
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 +107 -45
- package/dist/Base/LibJsGetDataType/index.d.ts +1 -5
- package/dist/Base/LibJsGetDataType/index.js +1 -5
- package/dist/Base/LibJsPromiseTimeout/index.d.ts +1 -5
- package/dist/Base/LibJsPromiseTimeout/index.js +1 -5
- package/dist/Browser/LibJsColorConsole/index.d.ts +1 -7
- package/dist/Browser/LibJsColorConsole/index.js +1 -7
- package/dist/Browser/LibJsIsMobile/index.d.ts +1 -4
- package/dist/Browser/LibJsIsMobile/index.js +1 -4
- package/dist/Browser/LibJsIsPad/index.d.ts +1 -4
- package/dist/Browser/LibJsIsPad/index.js +1 -4
- package/dist/Browser/LibJsObjToUrlParams/index.d.ts +1 -4
- package/dist/Browser/LibJsObjToUrlParams/index.js +1 -4
- package/dist/Browser/LibJsPathParams/index.d.ts +1 -4
- package/dist/Browser/LibJsPathParams/index.js +1 -4
- package/dist/Browser/LibJsSetTitleIcon/index.d.ts +1 -3
- package/dist/Browser/LibJsSetTitleIcon/index.js +1 -3
- package/dist/Browser/LibJsTagTitleTip/index.d.ts +1 -3
- package/dist/Browser/LibJsTagTitleTip/index.js +1 -3
- package/dist/Data/LibJsChunkArray/index.d.ts +1 -4
- package/dist/Data/LibJsChunkArray/index.js +1 -4
- package/dist/Data/LibJsDeepJSONParse/index.d.ts +1 -4
- package/dist/Data/LibJsDeepJSONParse/index.js +1 -4
- package/dist/Data/LibJsGroupArrayByKey/index.d.ts +1 -4
- package/dist/Data/LibJsGroupArrayByKey/index.js +1 -4
- package/dist/Data/LibJsMatchEmail/index.d.ts +1 -4
- package/dist/Data/LibJsMatchEmail/index.js +1 -4
- package/dist/Data/LibJsShuffleArray/index.d.ts +1 -4
- package/dist/Data/LibJsShuffleArray/index.js +1 -4
- package/dist/Data/LibJsStepArray/index.d.ts +1 -4
- package/dist/Data/LibJsStepArray/index.js +1 -4
- package/dist/Data/LibReverseArrayFromIndex/index.d.ts +1 -4
- package/dist/Data/LibReverseArrayFromIndex/index.js +1 -4
- package/dist/File/LibJsDownloadImageLink/index.d.ts +1 -3
- package/dist/File/LibJsDownloadImageLink/index.js +1 -3
- package/dist/File/LibJsImageOptimizer/index.d.ts +1 -14
- package/dist/File/LibJsImageOptimizer/index.js +1 -14
- package/dist/File/LibJsSaveJson/index.d.ts +1 -4
- package/dist/File/LibJsSaveJson/index.js +1 -4
- package/dist/Formatter/LibJsFormatterByte/index.d.ts +1 -4
- package/dist/Formatter/LibJsFormatterByte/index.js +1 -4
- package/dist/Formatter/LibJsMaskPhoneNumber/index.d.ts +1 -4
- package/dist/Formatter/LibJsMaskPhoneNumber/index.js +1 -4
- package/dist/Formatter/LibJsNumComma/index.d.ts +1 -4
- package/dist/Formatter/LibJsNumComma/index.js +1 -4
- package/dist/Formatter/LibJsNumberUnit/index.d.ts +1 -4
- package/dist/Formatter/LibJsNumberUnit/index.js +1 -4
- package/dist/Formatter/LibJsSecondsFormatterChinese/index.d.ts +1 -6
- package/dist/Formatter/LibJsSecondsFormatterChinese/index.js +1 -6
- package/dist/Math/LibJsCalculateExpression/index.d.ts +1 -4
- package/dist/Math/LibJsCalculateExpression/index.js +16 -17
- package/dist/Math/LibJsConvertAngle/index.d.ts +1 -7
- package/dist/Math/LibJsConvertAngle/index.js +1 -7
- package/dist/Math/LibJsCoordsAngle/index.d.ts +1 -5
- package/dist/Math/LibJsCoordsAngle/index.js +1 -5
- package/dist/Math/LibJsCoordsDistance/index.d.ts +1 -5
- package/dist/Math/LibJsCoordsDistance/index.js +1 -5
- package/dist/Math/LibJsDecimal/index.d.ts +1 -5
- package/dist/Math/LibJsDecimal/index.js +1 -5
- package/dist/Misc/LibJsRegFormValidate/index.d.ts +1 -16
- package/dist/Misc/LibJsRegFormValidate/index.js +1 -16
- package/dist/Misc/LibJsRetryRequest/index.d.ts +1 -12
- package/dist/Misc/LibJsRetryRequest/index.js +1 -12
- package/dist/Misc/LibNumerStepper/index.d.ts +1 -6
- package/dist/Misc/LibNumerStepper/index.js +1 -6
- package/dist/Random/LibJsProbabilityResult/index.d.ts +1 -5
- package/dist/Random/LibJsProbabilityResult/index.js +1 -5
- package/dist/Random/LibJsRandom/index.d.ts +1 -4
- package/dist/Random/LibJsRandom/index.js +1 -4
- package/dist/Random/LibJsRandomColor/index.d.ts +1 -4
- package/dist/Random/LibJsRandomColor/index.js +1 -4
- package/dist/Random/LibJsUniqueRandomNumbers/index.d.ts +1 -4
- package/dist/Random/LibJsUniqueRandomNumbers/index.js +1 -4
- package/dist/Time/LibJsSameTimeCheck/index.d.ts +1 -5
- package/dist/Time/LibJsSameTimeCheck/index.js +1 -5
- package/dist/Time/LibJsTimeAgo/index.d.ts +1 -6
- package/dist/Time/LibJsTimeAgo/index.js +1 -6
- package/dist/Time/LibJsTimeGreeting/index.d.ts +1 -5
- package/dist/Time/LibJsTimeGreeting/index.js +1 -5
- package/dist/libJs.d.ts +39 -199
- package/dist/libJs.js +39 -199
- package/package.json +1 -1
|
@@ -1,8 +1,5 @@
|
|
|
1
1
|
/** @description 随机 RGBA 颜色
|
|
2
2
|
* @param alpha 透明度
|
|
3
|
-
* @link
|
|
4
|
-
* @example
|
|
5
|
-
* libJsRandomColor(); //生成随机的 RGBA 颜色,默认透明度 1
|
|
6
|
-
* libJsRandomColor(0.5); //生成随机的 RGBA 颜色,透明度为 0.5
|
|
3
|
+
* @link 使用方法:https://www.npmjs.com/package/lyb-js#LibJsRandomColor-随机色
|
|
7
4
|
*/
|
|
8
5
|
export declare const libJsRandomColor: (alpha?: number) => string;
|
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
/** @description 随机 RGBA 颜色
|
|
2
2
|
* @param alpha 透明度
|
|
3
|
-
* @link
|
|
4
|
-
* @example
|
|
5
|
-
* libJsRandomColor(); //生成随机的 RGBA 颜色,默认透明度 1
|
|
6
|
-
* libJsRandomColor(0.5); //生成随机的 RGBA 颜色,透明度为 0.5
|
|
3
|
+
* @link 使用方法:https://www.npmjs.com/package/lyb-js#LibJsRandomColor-随机色
|
|
7
4
|
*/
|
|
8
5
|
export const libJsRandomColor = (alpha = 1) => {
|
|
9
6
|
const r = Math.floor(Math.random() * 256);
|
|
@@ -2,9 +2,6 @@
|
|
|
2
2
|
* @param min 最小值
|
|
3
3
|
* @param max 最大值
|
|
4
4
|
* @param count 数组长度
|
|
5
|
-
* @link
|
|
6
|
-
* @example
|
|
7
|
-
* libJsUniqueRandomNumbers(1, 10, 5); //从 1 到 10 中随机生成 5 个唯一数字
|
|
8
|
-
* libJsUniqueRandomNumbers(1, 100, 10); //从 1 到 100 中随机生成 10 个唯一数字
|
|
5
|
+
* @link 使用方法:https://www.npmjs.com/package/lyb-js#LibJsUniqueRandomNumbers-随机数数组
|
|
9
6
|
*/
|
|
10
7
|
export declare const libJsUniqueRandomNumbers: (min: number, max: number, count: number) => number[];
|
|
@@ -2,10 +2,7 @@
|
|
|
2
2
|
* @param min 最小值
|
|
3
3
|
* @param max 最大值
|
|
4
4
|
* @param count 数组长度
|
|
5
|
-
* @link
|
|
6
|
-
* @example
|
|
7
|
-
* libJsUniqueRandomNumbers(1, 10, 5); //从 1 到 10 中随机生成 5 个唯一数字
|
|
8
|
-
* libJsUniqueRandomNumbers(1, 100, 10); //从 1 到 100 中随机生成 10 个唯一数字
|
|
5
|
+
* @link 使用方法:https://www.npmjs.com/package/lyb-js#LibJsUniqueRandomNumbers-随机数数组
|
|
9
6
|
*/
|
|
10
7
|
export const libJsUniqueRandomNumbers = (min, max, count) => {
|
|
11
8
|
const numbers = Array.from({ length: max - min + 1 }, (_, i) => i + min);
|
|
@@ -4,10 +4,6 @@ import dayjs from "dayjs";
|
|
|
4
4
|
* @param timestamp 毫秒时间戳
|
|
5
5
|
* @param unit 判断单位
|
|
6
6
|
* @returns 0-同一单位时间 1-新单位时间 -1时间戳大于当前时间
|
|
7
|
-
* @link
|
|
8
|
-
* @example
|
|
9
|
-
* const timestamp = 1679872800000; //时间戳
|
|
10
|
-
* const result = libSameTimeCheck(timestamp, 'day'); //判断是否为同一天
|
|
11
|
-
* console.log(result); //0: 同一天, 1: 新的一天, -1: 时间戳大于当前时间
|
|
7
|
+
* @link 使用方法:https://www.npmjs.com/package/lyb-js#LibJsSameTimeCheck-时间比对
|
|
12
8
|
*/
|
|
13
9
|
export declare const libJsSameTimeCheck: (timestamp: number, unit: dayjs.OpUnitType) => 0 | 1 | -1;
|
|
@@ -4,11 +4,7 @@ import dayjs from "dayjs";
|
|
|
4
4
|
* @param timestamp 毫秒时间戳
|
|
5
5
|
* @param unit 判断单位
|
|
6
6
|
* @returns 0-同一单位时间 1-新单位时间 -1时间戳大于当前时间
|
|
7
|
-
* @link
|
|
8
|
-
* @example
|
|
9
|
-
* const timestamp = 1679872800000; //时间戳
|
|
10
|
-
* const result = libSameTimeCheck(timestamp, 'day'); //判断是否为同一天
|
|
11
|
-
* console.log(result); //0: 同一天, 1: 新的一天, -1: 时间戳大于当前时间
|
|
7
|
+
* @link 使用方法:https://www.npmjs.com/package/lyb-js#LibJsSameTimeCheck-时间比对
|
|
12
8
|
*/
|
|
13
9
|
export const libJsSameTimeCheck = (timestamp, unit) => {
|
|
14
10
|
const inputTime = dayjs(timestamp).startOf(unit);
|
|
@@ -1,10 +1,5 @@
|
|
|
1
1
|
/** @description 时间差计算
|
|
2
2
|
* @param timestamp 毫秒时间戳
|
|
3
|
-
* @link
|
|
4
|
-
* @example
|
|
5
|
-
* libJsTimeAgotamp(Date.now() - 3600000); //"1 小时前"
|
|
6
|
-
* libJsTimeAgotamp(Date.now() - 86400000); //"1 天前"
|
|
7
|
-
* libJsTimeAgotamp(Date.now() - 31536000000); //"1 年前"
|
|
8
|
-
* libJsTimeAgotamp(Date.now() - 10000); //"刚刚"
|
|
3
|
+
* @link 使用方法:https://www.npmjs.com/package/lyb-js#LibJsTimeAgo-中文时间差
|
|
9
4
|
*/
|
|
10
5
|
export declare const libJsTimeAgo: (timestamp: number) => string;
|
|
@@ -1,11 +1,6 @@
|
|
|
1
1
|
/** @description 时间差计算
|
|
2
2
|
* @param timestamp 毫秒时间戳
|
|
3
|
-
* @link
|
|
4
|
-
* @example
|
|
5
|
-
* libJsTimeAgotamp(Date.now() - 3600000); //"1 小时前"
|
|
6
|
-
* libJsTimeAgotamp(Date.now() - 86400000); //"1 天前"
|
|
7
|
-
* libJsTimeAgotamp(Date.now() - 31536000000); //"1 年前"
|
|
8
|
-
* libJsTimeAgotamp(Date.now() - 10000); //"刚刚"
|
|
3
|
+
* @link 使用方法:https://www.npmjs.com/package/lyb-js#LibJsTimeAgo-中文时间差
|
|
9
4
|
*/
|
|
10
5
|
export const libJsTimeAgo = (timestamp) => {
|
|
11
6
|
const timeUnits = [
|
|
@@ -9,10 +9,6 @@ export interface LibTimeGreetingParams {
|
|
|
9
9
|
/**
|
|
10
10
|
* @description 根据当前时间返回问候语
|
|
11
11
|
* @param greet 自定义问候语对象
|
|
12
|
-
* @link
|
|
13
|
-
* @example
|
|
14
|
-
* libJsTimeGreeting(); //根据当前时间返回默认问候语
|
|
15
|
-
* libJsTimeGreeting({ morning: "早安" }); //自定义早上问候语
|
|
16
|
-
* libJsTimeGreeting({ afternoon: "午后好" }); //自定义下午问候语
|
|
12
|
+
* @link 使用方法:https://www.npmjs.com/package/lyb-js#LibJsTimeGreeting-时间问候
|
|
17
13
|
*/
|
|
18
14
|
export declare const libJsTimeGreeting: (greet?: LibTimeGreetingParams) => string;
|
|
@@ -1,11 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @description 根据当前时间返回问候语
|
|
3
3
|
* @param greet 自定义问候语对象
|
|
4
|
-
* @link
|
|
5
|
-
* @example
|
|
6
|
-
* libJsTimeGreeting(); //根据当前时间返回默认问候语
|
|
7
|
-
* libJsTimeGreeting({ morning: "早安" }); //自定义早上问候语
|
|
8
|
-
* libJsTimeGreeting({ afternoon: "午后好" }); //自定义下午问候语
|
|
4
|
+
* @link 使用方法:https://www.npmjs.com/package/lyb-js#LibJsTimeGreeting-时间问候
|
|
9
5
|
*/
|
|
10
6
|
export const libJsTimeGreeting = (greet = {}) => {
|
|
11
7
|
const { midnight = "午夜好", morning = "早上好", forenoon = "上午好", noon = "中午好", afternoon = "下午好", evening = "晚上好", } = greet;
|
package/dist/libJs.d.ts
CHANGED
|
@@ -4,22 +4,14 @@ export declare const Base: {
|
|
|
4
4
|
/**
|
|
5
5
|
* @description 返回数据类型
|
|
6
6
|
* @param v 需要判断类型的数据
|
|
7
|
-
* @link
|
|
8
|
-
* @example
|
|
9
|
-
* libJsGetDataType(123); //"number"
|
|
10
|
-
* libJsGetDataType("hello"); //"string"
|
|
11
|
-
* libJsGetDataType([1, 2, 3]); //"array"
|
|
7
|
+
* @link 使用方法:https://www.npmjs.com/package/lyb-js#LibJsColorConsole-有色打印
|
|
12
8
|
*/
|
|
13
9
|
libJsGetDataType: (v: any) => import("./Base/LibJsGetDataType").LibJsGetDataTypeReturnType;
|
|
14
10
|
/**
|
|
15
11
|
* @description 延时执行,切换到其他页面会暂停
|
|
16
12
|
* @param delay 延时毫秒数
|
|
17
13
|
* @param fn 延时执行函数
|
|
18
|
-
* @link
|
|
19
|
-
* @example
|
|
20
|
-
* libJsPromiseTimeout(3000, () => {
|
|
21
|
-
* console.log("执行延时函数");
|
|
22
|
-
* });
|
|
14
|
+
* @link 使用方法:https://www.npmjs.com/package/lyb-js#LibJsPromiseTimeout-延时执行
|
|
23
15
|
*/
|
|
24
16
|
libJsPromiseTimeout: (delay?: number, fn?: () => void) => Promise<void>;
|
|
25
17
|
};
|
|
@@ -29,61 +21,39 @@ export declare const Browser: {
|
|
|
29
21
|
* @param title 标题
|
|
30
22
|
* @param color 颜色
|
|
31
23
|
* @param logs 信息
|
|
32
|
-
* @link
|
|
33
|
-
* @example
|
|
34
|
-
* //使用红色打印日志
|
|
35
|
-
* libJsColorConsole("错误提示", "red", [{ label: "错误代码", value: 500 }]);
|
|
36
|
-
*
|
|
37
|
-
* //使用蓝色打印简单日志
|
|
38
|
-
* libJsColorConsole("信息", "blue", "操作成功");
|
|
24
|
+
* @link 使用方法:https://www.npmjs.com/package/lyb-js#LibJsColorConsole-有色打印
|
|
39
25
|
*/
|
|
40
26
|
libJsColorConsole: (title: string, color: "red" | "orange" | "yellow" | "green" | "blue" | "purple", logs?: {
|
|
41
27
|
label: string;
|
|
42
28
|
value: any;
|
|
43
29
|
}[] | any) => void;
|
|
44
30
|
/** @description 判断是否为移动设备
|
|
45
|
-
* @link
|
|
46
|
-
* @example
|
|
47
|
-
* const isMobile = libJsIsMobile();
|
|
48
|
-
* console.log(isMobile); //true 或 false
|
|
31
|
+
* @link 使用方法:https://www.npmjs.com/package/lyb-js#LibJsIsMobile-判断手机
|
|
49
32
|
*/
|
|
50
33
|
libJsIsMobile: () => boolean;
|
|
51
34
|
/** @description 判断是否为平板
|
|
52
|
-
* @link
|
|
53
|
-
* @example
|
|
54
|
-
* const isPad = libJsIsPad();
|
|
55
|
-
* console.log(isPad); //true 或 false
|
|
35
|
+
* @link 使用方法:https://www.npmjs.com/package/lyb-js#LibJsIsPad-判断平板
|
|
56
36
|
*/
|
|
57
37
|
libJsIsPad: () => boolean;
|
|
58
38
|
/** @description 获取浏览器地址栏参数
|
|
59
|
-
* @link
|
|
60
|
-
* @example
|
|
61
|
-
* const params = libJsPathParams();
|
|
62
|
-
* console.log(params); //{ param1: "value1", param2: "value2" }
|
|
39
|
+
* @link 使用方法:https://www.npmjs.com/package/lyb-js#LibJsPathParams-地址栏参数
|
|
63
40
|
*/
|
|
64
41
|
libJsPathParams: () => Record<string, string>;
|
|
65
42
|
/** @description 动态设置网站标题及图标
|
|
66
43
|
* @param title 网站标题
|
|
67
44
|
* @param url 网站图标地址
|
|
68
|
-
* @link
|
|
69
|
-
* @example
|
|
70
|
-
* libJsSetTitleIcon("我的网站", "https://example.com/favicon.ico");
|
|
45
|
+
* @link 使用方法:https://www.npmjs.com/package/lyb-js#LibJsSetTitleIcon-网站标题图标
|
|
71
46
|
*/
|
|
72
47
|
libJsSetTitleIcon: (title: string, url: string) => void;
|
|
73
48
|
/** @description 网站标题交互,当从当前网页切换到其他网页,网站标题自动切换
|
|
74
49
|
* @param backTitle 从其他网页返回时显示的标题
|
|
75
50
|
* @param leaveTitle 从当前网页离开时显示的标题
|
|
76
|
-
*
|
|
77
|
-
* @example
|
|
78
|
-
* libJsTagTitleTip("欢迎回来", "来和妲己玩耍吧!");
|
|
51
|
+
* @link 使用方法:https://www.npmjs.com/package/lyb-js#LibJsTagTitleTip-网站标题交互
|
|
79
52
|
*/
|
|
80
53
|
libJsTagTitleTip: (backTitle: string, leaveTitle: string) => void;
|
|
81
54
|
/** @description 对象转为url参数
|
|
82
55
|
* @param params 对象参数
|
|
83
|
-
* @link
|
|
84
|
-
* @example
|
|
85
|
-
* libJsObjToUrlParams({ name: "John", age: 30, active: true });
|
|
86
|
-
* // "name=John&age=30&active=true"
|
|
56
|
+
* @link 使用方法:https://www.npmjs.com/package/lyb-js#LibJsObjToUrlParams-对象转Url参数
|
|
87
57
|
*/
|
|
88
58
|
libJsObjToUrlParams: (params: Record<string, string | number | boolean>) => string;
|
|
89
59
|
};
|
|
@@ -93,17 +63,11 @@ export declare const Data: {
|
|
|
93
63
|
* @description 将数组拆分成指定数组元素数量的多个数组
|
|
94
64
|
* @param arr 需要拆分的数组
|
|
95
65
|
* @param chunkSize 每个数组的元素数量
|
|
96
|
-
* @link
|
|
97
|
-
* @example
|
|
98
|
-
* const chunks = libJsChunkArray([1, 2, 3, 4, 5, 6], 2);
|
|
99
|
-
* console.log(chunks); //[[1, 2], [3, 4], [5, 6]]
|
|
66
|
+
* @link 使用方法:https://www.npmjs.com/package/lyb-js#LibJsChunkArray-数组拆分
|
|
100
67
|
*/
|
|
101
68
|
libJsChunkArray: <T>(arr: T[], chunkSize: number) => T[][];
|
|
102
69
|
/** @description 递归将JSON字符串深度解析为对象
|
|
103
|
-
* @link
|
|
104
|
-
* @example
|
|
105
|
-
* const obj = libJsDeepJSONParse('{"a": 1, "b": "{\"c\": 2}"}');
|
|
106
|
-
* console.log(obj); //{ a: 1, b: { c: 2 } }
|
|
70
|
+
* @link 使用方法:https://www.npmjs.com/package/lyb-js#LibJsDeepJSONParse-深度解析JSON
|
|
107
71
|
*/
|
|
108
72
|
libJsDeepJSONParse: <T>(data: any) => T;
|
|
109
73
|
/**
|
|
@@ -111,10 +75,7 @@ export declare const Data: {
|
|
|
111
75
|
* @param arr 要分组的数组
|
|
112
76
|
* @param key 分组的键
|
|
113
77
|
* @returns 分组后的对象
|
|
114
|
-
* @link
|
|
115
|
-
* @example
|
|
116
|
-
* const grouped = libJsGroupArrayByKey([{ id: 1, name: 'A' }, { id: 2, name: 'B' }, { id: 1, name: 'C' }], 'id');
|
|
117
|
-
* console.log(grouped); //{ 1: [{ id: 1, name: 'A' }, { id: 1, name: 'C' }], 2: [{ id: 2, name: 'B' }] }
|
|
78
|
+
* @link 使用方法:https://www.npmjs.com/package/lyb-js#LibJsGroupArrayByKey-分类汇总
|
|
118
79
|
*/
|
|
119
80
|
libJsGroupArrayByKey: (arr: any[] | undefined, key: string) => any;
|
|
120
81
|
/**
|
|
@@ -122,36 +83,25 @@ export declare const Data: {
|
|
|
122
83
|
* @param str 要匹配的字符串
|
|
123
84
|
* @param emailList 电子邮件后缀列表
|
|
124
85
|
* @returns 匹配结果数组
|
|
125
|
-
* @link
|
|
126
|
-
* @example
|
|
127
|
-
* const emails = libJsMatchEmail("user", ["@gmail.com", "@yahoo.com"]);
|
|
128
|
-
* console.log(emails); //["user@gmail.com", "user@yahoo.com"]
|
|
86
|
+
* @link 使用方法:https://www.npmjs.com/package/lyb-js#LibJsMatchEmail-匹配E-Mail
|
|
129
87
|
*/
|
|
130
88
|
libJsMatchEmail: (str: string, emailList: string[]) => string[];
|
|
131
89
|
/** @description 数组乱序
|
|
132
90
|
* @param arr 需要乱序的数组
|
|
133
91
|
* @link 了解更多:https://www.npmjs.com/package/lyb-js
|
|
134
|
-
* @
|
|
135
|
-
* const shuffled = libJsShuffleArray([1, 2, 3, 4, 5]);
|
|
136
|
-
* console.log(shuffled); //[3, 5, 2, 1, 4] (结果每次不同)
|
|
92
|
+
* @link 使用方法:https://www.npmjs.com/package/lyb-js#LibJsShuffleArray-数组乱序
|
|
137
93
|
*/
|
|
138
94
|
libJsShuffleArray: <T>(arr: T[]) => T[];
|
|
139
95
|
/** @description 数组元素整体步数移动
|
|
140
96
|
* @param arr 移动的数组
|
|
141
97
|
* @param step 负数为向后移动,正数为向前移动
|
|
142
|
-
* @link
|
|
143
|
-
* @example
|
|
144
|
-
* const moved = libJsStepArray([1, 2, 3, 4, 5], 2);
|
|
145
|
-
* console.log(moved); //[4, 5, 1, 2, 3]
|
|
98
|
+
* @link 使用方法:https://www.npmjs.com/package/lyb-js#LibJsStepArray-数组偏移
|
|
146
99
|
*/
|
|
147
100
|
libJsStepArray: <T>(arr: T[], step: number) => T[];
|
|
148
101
|
/** @description 翻转指定索引后面的数组
|
|
149
102
|
* @param arr 数组
|
|
150
103
|
* @param index 开始索引
|
|
151
|
-
* @link
|
|
152
|
-
* @example
|
|
153
|
-
* libReverseArrayFromIndex([1, 2, 3, 4, 5], 1);
|
|
154
|
-
* // [1, 2, 5, 4, 3]
|
|
104
|
+
* @link 使用方法:https://www.npmjs.com/package/lyb-js#LibReverseArrayFromIndex-数组定位翻转
|
|
155
105
|
*/
|
|
156
106
|
libReverseArrayFromIndex: <T>(arr: T[], index: number) => T[];
|
|
157
107
|
};
|
|
@@ -160,37 +110,19 @@ export declare const File: {
|
|
|
160
110
|
/** @description 下载图片链接
|
|
161
111
|
* @param link 图片链接
|
|
162
112
|
* @param name 图片名称
|
|
163
|
-
* @link
|
|
164
|
-
* @example
|
|
165
|
-
* libJsDownloadImageLink("https://example.com/image.jpg", "downloaded-image.jpg");
|
|
113
|
+
* @link 使用方法:https://www.npmjs.com/package/lyb-js#LibJsDownloadImageLink-图片下载
|
|
166
114
|
*/
|
|
167
115
|
libJsDownloadImageLink: (link: string, name: string) => void;
|
|
168
116
|
/** @description 图片压缩
|
|
169
117
|
* @param obj 压缩参数
|
|
170
|
-
* @link
|
|
171
|
-
* @example
|
|
172
|
-
* //图片压缩使用示例
|
|
173
|
-
* libJsImageOptimizerOptionsParams({
|
|
174
|
-
* file: myFile,
|
|
175
|
-
* ratio: 0.8,
|
|
176
|
-
* width: 800,
|
|
177
|
-
* maxSize: 1024,
|
|
178
|
-
* success: (data, file, url) => {
|
|
179
|
-
* console.log('压缩成功', data, file, url);
|
|
180
|
-
* },
|
|
181
|
-
* fail: (error) => {
|
|
182
|
-
* console.error('压缩失败', error);
|
|
183
|
-
* }
|
|
184
|
-
* });
|
|
118
|
+
* @link 使用方法:https://www.npmjs.com/package/lyb-js#LibJsImageOptimizer-图片压缩
|
|
185
119
|
*/
|
|
186
120
|
libJsImageOptimizer: (obj: import("./File/LibJsImageOptimizer").LibJsImageOptimizerOptionsParams) => void;
|
|
187
121
|
/**
|
|
188
122
|
* @description 保存文件到本地
|
|
189
123
|
* @param data 要保存的数据
|
|
190
124
|
* @param name 文件名
|
|
191
|
-
* @link
|
|
192
|
-
* @example
|
|
193
|
-
* libJsSaveJson("example.json", JSON.stringify({ key: "value" }));
|
|
125
|
+
* @link 使用方法:https://www.npmjs.com/package/lyb-js#LibJsSaveJson-保存文件
|
|
194
126
|
*/
|
|
195
127
|
libJsSaveJson: (name: string, data: BlobPart) => void;
|
|
196
128
|
};
|
|
@@ -200,51 +132,34 @@ export declare const Formatter: {
|
|
|
200
132
|
* @description 格式化字节大小
|
|
201
133
|
* @param bytes 字节数
|
|
202
134
|
* @returns ['大小', '单位', '大小及单位']
|
|
203
|
-
* @link
|
|
204
|
-
* @example
|
|
205
|
-
* const [size, unit, formatted] = libJsFormatterByte(2048);
|
|
206
|
-
* console.log(size, unit, formatted); //2.00 KB 2.00 KB
|
|
135
|
+
* @link 使用方法:https://www.npmjs.com/package/lyb-js#LibJsFormatterByte-字节格式化
|
|
207
136
|
*/
|
|
208
137
|
libJsFormatterByte: (bytes: number) => (string | number)[];
|
|
209
138
|
/**
|
|
210
139
|
* @description 隐藏手机号码中间的四位数字
|
|
211
140
|
* @param mobile 需要处理的手机号码
|
|
212
|
-
* @link
|
|
213
|
-
* @example
|
|
214
|
-
* const masked = libJsMaskPhoneNumber("13812345678");
|
|
215
|
-
* console.log(masked); //138****5678
|
|
141
|
+
* @link 使用方法:https://www.npmjs.com/package/lyb-js#LibJsMaskPhoneNumber-隐藏手机号码
|
|
216
142
|
*/
|
|
217
143
|
libJsMaskPhoneNumber: (mobile: number | string) => string;
|
|
218
144
|
/**
|
|
219
145
|
* @description 数字每三位添加逗号
|
|
220
146
|
* @param num 需要格式化的数字
|
|
221
147
|
* @param reserve 保留小数位数
|
|
222
|
-
* @link
|
|
223
|
-
* @example
|
|
224
|
-
* const formatted = libJsNumComma(1234567.89);
|
|
225
|
-
* console.log(formatted); //1,234,567.89
|
|
148
|
+
* @link 使用方法:https://www.npmjs.com/package/lyb-js#LibJsNumComma-数字逗号
|
|
226
149
|
*/
|
|
227
150
|
libJsNumComma: (num: number, reserve?: number) => string;
|
|
228
151
|
/** @description 将大于1000的数字使用k为单位
|
|
229
152
|
* @param num 数字
|
|
230
153
|
* @param units 单位组,key为单位,value为格式化阈值
|
|
231
154
|
* @returns [数字, 单位]
|
|
232
|
-
* @link
|
|
233
|
-
* @example
|
|
234
|
-
* const [value, unit] = libJsNumberUnit(1500, { K: 1000, M: 1000000 });
|
|
235
|
-
* console.log(value, unit); //1.50 K
|
|
155
|
+
* @link 使用方法:https://www.npmjs.com/package/lyb-js#LibJsNumberUnit-数字单位
|
|
236
156
|
*/
|
|
237
157
|
libJsNumberUnit: (num: number, units: import("./Formatter/LibJsNumberUnit").LibJsNumberUnitParams) => string[];
|
|
238
158
|
/**
|
|
239
159
|
* @description 将秒数格式化为中文时间描述,支持扩展到年和月
|
|
240
160
|
* @param seconds 秒数
|
|
241
161
|
* @returns 格式化后的中文时间
|
|
242
|
-
* @link
|
|
243
|
-
* @example
|
|
244
|
-
* libJsSecondsFormatterChinese(100000); //"1天3小时46分40秒"
|
|
245
|
-
* libJsSecondsFormatterChinese(31536000); //"1年"
|
|
246
|
-
* libJsSecondsFormatterChinese(3600); //"1小时"
|
|
247
|
-
* libJsSecondsFormatterChinese(90); //"1分30秒"
|
|
162
|
+
* @link 使用方法:https://www.npmjs.com/package/lyb-js#LibJsSecondsFormatterChinese-中文时间
|
|
248
163
|
*/
|
|
249
164
|
libJsSecondsFormatterChinese: (seconds: number) => string;
|
|
250
165
|
};
|
|
@@ -254,34 +169,20 @@ export declare const Math: {
|
|
|
254
169
|
* @param expression 表达式字符串
|
|
255
170
|
* @param point 小数点精度
|
|
256
171
|
* @returns 计算结果
|
|
257
|
-
*
|
|
258
|
-
* @link 了解更多:https://www.npmjs.com/package/lyb-js
|
|
259
|
-
* @example
|
|
260
|
-
* const result = libJsCalculateExpression("(1+2)-(3*4)/5");
|
|
261
|
-
* console.log(result); //0.6
|
|
172
|
+
* @link 使用方法:https://www.npmjs.com/package/lyb-js#LibJsCalculateExpression-表达式字符串
|
|
262
173
|
*/
|
|
263
174
|
libJsCalculateExpression: (expression: string, point?: number) => number;
|
|
264
175
|
/**
|
|
265
176
|
* @description 角度和弧度互相转换
|
|
266
177
|
* @param value 角度值或弧度值
|
|
267
178
|
* @param type 角度类型或弧度类型
|
|
268
|
-
* @link
|
|
269
|
-
* @example
|
|
270
|
-
* //角度转弧度
|
|
271
|
-
* libJsConvertAngle(90, "rad"); //返回 1.5708... (π/2)
|
|
272
|
-
*
|
|
273
|
-
* //弧度转角度
|
|
274
|
-
* libJsConvertAngle(Math.PI, "deg"); //返回 180
|
|
179
|
+
* @link 使用方法:https://www.npmjs.com/package/lyb-js#LibJsConvertAngle-角弧度互转
|
|
275
180
|
*/
|
|
276
181
|
libJsConvertAngle: (value: number, type: "rad" | "deg") => number;
|
|
277
182
|
/** @description 计算两点角度
|
|
278
183
|
* @param coord1 起点坐标
|
|
279
184
|
* @param coord2 终点坐标
|
|
280
|
-
* @link
|
|
281
|
-
* @example
|
|
282
|
-
* libJsCoordsAngle({ x: 0, y: 0 }, { x: 1, y: 0 }); //0
|
|
283
|
-
* libJsCoordsAngle({ x: 0, y: 0 }, { x: 1, y: 1 }); //45
|
|
284
|
-
* libJsCoordsAngle({ x: 0, y: 0 }, { x: 0, y: 1 }); //90
|
|
185
|
+
* @link 使用方法:https://www.npmjs.com/package/lyb-js#LibJsCoordsAngle-两点角度
|
|
285
186
|
*/
|
|
286
187
|
libJsCoordsAngle: (coord1: {
|
|
287
188
|
x: number;
|
|
@@ -293,11 +194,7 @@ export declare const Math: {
|
|
|
293
194
|
/** @description 计算两点距离
|
|
294
195
|
* @param coord1 起点坐标
|
|
295
196
|
* @param coord2 终点坐标
|
|
296
|
-
* @link
|
|
297
|
-
* @example
|
|
298
|
-
* libJsCoordsDistance({ x: 0, y: 0 }, { x: 3, y: 4 }); //5
|
|
299
|
-
* libJsCoordsDistance({ x: 1, y: 1 }, { x: 4, y: 5 }); //5
|
|
300
|
-
* libJsCoordsDistance({ x: 0, y: 0 }, { x: 0, y: 0 }); //0
|
|
197
|
+
* @link 使用方法:https://www.npmjs.com/package/lyb-js#LibJsCoordsDistance-两点距离
|
|
301
198
|
*/
|
|
302
199
|
libJsCoordsDistance: (coord1: {
|
|
303
200
|
x: number;
|
|
@@ -310,11 +207,7 @@ export declare const Math: {
|
|
|
310
207
|
* @param num1 第一个数
|
|
311
208
|
* @param num2 第二个数
|
|
312
209
|
* @param operator 运算符,支持加减乘除
|
|
313
|
-
* @link
|
|
314
|
-
* @example
|
|
315
|
-
* libJsDecimal(10, 3, "+"); //13
|
|
316
|
-
* libJsDecimal(10, 3, "-"); //7
|
|
317
|
-
* libJsDecimal(10, 3, "/", 2); //3.33
|
|
210
|
+
* @link 使用方法:https://www.npmjs.com/package/lyb-js#LibJsDecimal-高精度计算
|
|
318
211
|
*/
|
|
319
212
|
libJsDecimal: (num1: number, num2: number, operator: "+" | "-" | "*" | "/", point?: number) => number;
|
|
320
213
|
};
|
|
@@ -325,22 +218,7 @@ export declare const Misc: {
|
|
|
325
218
|
* @param form 表单数据对象
|
|
326
219
|
* @param rules 验证规则数组
|
|
327
220
|
* @returns 验证结果数组,包含未通过验证的项
|
|
328
|
-
* @link
|
|
329
|
-
* @example
|
|
330
|
-
* const form = { username: "john", email: "john@example.com" };
|
|
331
|
-
* const rules = [
|
|
332
|
-
* { key: "username", verify: /^[a-zA-Z0-9]{3,}$/, msg: "用户名不合法", name: "用户名" },
|
|
333
|
-
* { key: "email", verify: /^\S+@\S+\.\S+$/, msg: "邮箱格式不正确", name: "邮箱" },
|
|
334
|
-
* ];
|
|
335
|
-
* libJsRegFormValidate(form, rules);
|
|
336
|
-
* //返回结果: []
|
|
337
|
-
*
|
|
338
|
-
* const invalidForm = { username: "jo", email: "invalid-email" };
|
|
339
|
-
* libJsRegFormValidate(invalidForm, rules);
|
|
340
|
-
* //返回结果: [
|
|
341
|
-
* // { key: "username", msg: "用户名不合法", name: "用户名" },
|
|
342
|
-
* // { key: "email", msg: "邮箱格式不正确", name: "邮箱" }
|
|
343
|
-
* //]
|
|
221
|
+
* @link 使用方法:https://www.npmjs.com/package/lyb-js#LibJsRegFormValidate-表单验证
|
|
344
222
|
*/
|
|
345
223
|
libJsRegFormValidate: (form: Record<string, any>, rules: Array<{
|
|
346
224
|
key: string;
|
|
@@ -353,18 +231,7 @@ export declare const Misc: {
|
|
|
353
231
|
* @param maxRetries 最大重试次数
|
|
354
232
|
* @param retryDelay 重试间隔时间
|
|
355
233
|
* @param params 请求参数
|
|
356
|
-
* @link
|
|
357
|
-
* @example
|
|
358
|
-
* const requestFn = (params: { url: string }) => fetch(params.url).then(res => res.json());
|
|
359
|
-
* const params = { url: "https://api.example.com/data" };
|
|
360
|
-
* libJsRetryRequest({
|
|
361
|
-
* promiseFn: requestFn,
|
|
362
|
-
* params,
|
|
363
|
-
* maxRetries: 5,
|
|
364
|
-
* retryDelay: 1000
|
|
365
|
-
* })
|
|
366
|
-
* .then(data => console.log(data))
|
|
367
|
-
* .catch(err => console.error(err));
|
|
234
|
+
* @link 使用方法:https://www.npmjs.com/package/lyb-js#LibJsRetryRequest-请求重连
|
|
368
235
|
*/
|
|
369
236
|
libJsRetryRequest: <T>({ promiseFn, maxRetries, retryDelay, params, }: {
|
|
370
237
|
promiseFn: (params?: any) => Promise<T>;
|
|
@@ -374,12 +241,7 @@ export declare const Misc: {
|
|
|
374
241
|
onRetry?: () => void;
|
|
375
242
|
}) => Promise<T>;
|
|
376
243
|
/** @description 数字步进器
|
|
377
|
-
* @link
|
|
378
|
-
* @example
|
|
379
|
-
* const stepper = new libNumerStepper(10, (index) => console.log(index));
|
|
380
|
-
* stepper.down("add"); // 索引加1
|
|
381
|
-
* stepper.updateIndex(5); // 更新索引为5
|
|
382
|
-
* stepper.down("sub"); // 索引减1
|
|
244
|
+
* @link 使用方法:https://www.npmjs.com/package/lyb-js#LibNumerStepper-数字步进器
|
|
383
245
|
*/
|
|
384
246
|
libNumerStepper: typeof libNumerStepper;
|
|
385
247
|
};
|
|
@@ -387,40 +249,26 @@ export declare const Misc: {
|
|
|
387
249
|
export declare const Random: {
|
|
388
250
|
/** @description 百分比概率结果
|
|
389
251
|
* @param probability 触发概率,百分比,0-100
|
|
390
|
-
* @link
|
|
391
|
-
* @example
|
|
392
|
-
* libJsProbabilityResult(50); //50% 概率为 true
|
|
393
|
-
* libJsProbabilityResult(80); //80% 概率为 true
|
|
394
|
-
* libJsProbabilityResult(100); //100% 概率为 true
|
|
252
|
+
* @link 使用方法:https://www.npmjs.com/package/lyb-js#LibJsProbabilityResult-概率触发
|
|
395
253
|
*/
|
|
396
254
|
libJsProbabilityResult: (probability: number) => boolean;
|
|
397
255
|
/** @description 随机数
|
|
398
256
|
* @param min 最小值
|
|
399
257
|
* @param max 最大值
|
|
400
258
|
* @param num 保留小数位数
|
|
401
|
-
* @link
|
|
402
|
-
* @example
|
|
403
|
-
* libJsRandom(1, 10); //1 到 10 之间的随机整数
|
|
404
|
-
* libJsRandom(1, 10, 2); //1 到 10 之间保留两位小数的随机数
|
|
405
|
-
* libJsRandom(5, 5, 3); //返回 5.000
|
|
259
|
+
* @link 使用方法:https://www.npmjs.com/package/lyb-js#LibJsRandom-随机数
|
|
406
260
|
*/
|
|
407
261
|
libJsRandom: (min: number, max: number, num?: number) => number;
|
|
408
262
|
/** @description 随机 RGBA 颜色
|
|
409
263
|
* @param alpha 透明度
|
|
410
|
-
* @link
|
|
411
|
-
* @example
|
|
412
|
-
* libJsRandomColor(); //生成随机的 RGBA 颜色,默认透明度 1
|
|
413
|
-
* libJsRandomColor(0.5); //生成随机的 RGBA 颜色,透明度为 0.5
|
|
264
|
+
* @link 使用方法:https://www.npmjs.com/package/lyb-js#LibJsRandomColor-随机色
|
|
414
265
|
*/
|
|
415
266
|
libJsRandomColor: (alpha?: number) => string;
|
|
416
267
|
/** @description 随机生成n个指定范围的随机数数组
|
|
417
268
|
* @param min 最小值
|
|
418
269
|
* @param max 最大值
|
|
419
270
|
* @param count 数组长度
|
|
420
|
-
* @link
|
|
421
|
-
* @example
|
|
422
|
-
* libJsUniqueRandomNumbers(1, 10, 5); //从 1 到 10 中随机生成 5 个唯一数字
|
|
423
|
-
* libJsUniqueRandomNumbers(1, 100, 10); //从 1 到 100 中随机生成 10 个唯一数字
|
|
271
|
+
* @link 使用方法:https://www.npmjs.com/package/lyb-js#LibJsUniqueRandomNumbers-随机数数组
|
|
424
272
|
*/
|
|
425
273
|
libJsUniqueRandomNumbers: (min: number, max: number, count: number) => number[];
|
|
426
274
|
};
|
|
@@ -431,26 +279,18 @@ export declare const Time: {
|
|
|
431
279
|
* @param timestamp 毫秒时间戳
|
|
432
280
|
* @param unit 判断单位
|
|
433
281
|
* @returns 0-同一单位时间 1-新单位时间 -1时间戳大于当前时间
|
|
282
|
+
* @link 使用方法:https://www.npmjs.com/package/lyb-js#LibJsSameTimeCheck-时间比对
|
|
434
283
|
*/
|
|
435
284
|
libJsSameTimeCheck: (timestamp: number, unit: import("dayjs").OpUnitType) => 0 | 1 | -1;
|
|
436
285
|
/** @description 时间差计算
|
|
437
286
|
* @param timestamp 毫秒时间戳
|
|
438
|
-
* @link
|
|
439
|
-
* @example
|
|
440
|
-
* libJsTimeAgotamp(Date.now() - 3600000); //"1 小时前"
|
|
441
|
-
* libJsTimeAgotamp(Date.now() - 86400000); //"1 天前"
|
|
442
|
-
* libJsTimeAgotamp(Date.now() - 31536000000); //"1 年前"
|
|
443
|
-
* libJsTimeAgotamp(Date.now() - 10000); //"刚刚"
|
|
287
|
+
* @link 使用方法:https://www.npmjs.com/package/lyb-js#LibJsTimeAgo-中文时间差
|
|
444
288
|
*/
|
|
445
289
|
libJsTimeAgo: (timestamp: number) => string;
|
|
446
290
|
/**
|
|
447
291
|
* @description 根据当前时间返回问候语
|
|
448
292
|
* @param greet 自定义问候语对象
|
|
449
|
-
* @link
|
|
450
|
-
* @example
|
|
451
|
-
* libJsTimeGreeting(); //根据当前时间返回默认问候语
|
|
452
|
-
* libJsTimeGreeting({ morning: "早安" }); //自定义早上问候语
|
|
453
|
-
* libJsTimeGreeting({ afternoon: "午后好" }); //自定义下午问候语
|
|
293
|
+
* @link 使用方法:https://www.npmjs.com/package/lyb-js#LibJsTimeGreeting-时间问候
|
|
454
294
|
*/
|
|
455
295
|
libJsTimeGreeting: (greet?: import("./Time/LibJsTimeGreeting").LibTimeGreetingParams) => string;
|
|
456
296
|
};
|