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