lyb-js 1.0.7 → 1.0.9
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 +143 -144
- package/dist/Base/LibJsGetDataType/index.d.ts +10 -0
- package/dist/Base/{LibGetDataType → LibJsGetDataType}/index.js +4 -4
- package/dist/Base/{LibPromiseTimeout → LibJsPromiseTimeout}/index.d.ts +2 -2
- package/dist/Base/{LibPromiseTimeout → LibJsPromiseTimeout}/index.js +2 -2
- package/dist/Browser/LibJsColorConsole/index.d.ts +15 -0
- package/dist/Browser/{LibColorConsole → LibJsColorConsole}/index.js +3 -3
- package/dist/Browser/{LibIsMobile → LibJsIsMobile}/index.d.ts +1 -1
- package/dist/Browser/{LibIsMobile → LibJsIsMobile}/index.js +1 -1
- package/dist/Browser/{LibIsPad → LibJsIsPad}/index.d.ts +2 -2
- package/dist/Browser/{LibIsPad → LibJsIsPad}/index.js +2 -2
- package/dist/Browser/{LibPathParams → LibJsPathParams}/index.d.ts +2 -2
- package/dist/Browser/{LibPathParams → LibJsPathParams}/index.js +2 -2
- package/dist/Browser/LibJsSetTitleIcon/index.d.ts +7 -0
- package/dist/Browser/{LibSetTitleIcon → LibJsSetTitleIcon}/index.js +2 -2
- package/dist/Browser/{LibTagTitleTip → LibJsTagTitleTip}/index.d.ts +3 -3
- package/dist/Browser/{LibTagTitleTip → LibJsTagTitleTip}/index.js +3 -3
- package/dist/Data/{LibChunkArray → LibJsChunkArray}/index.d.ts +2 -2
- package/dist/Data/{LibChunkArray → LibJsChunkArray}/index.js +2 -2
- package/dist/Data/LibJsDeepJSONParse/index.d.ts +6 -0
- package/dist/Data/{LibDeepJSONParse → LibJsDeepJSONParse}/index.js +5 -5
- package/dist/Data/{LibGroupArrayByKey → LibJsGroupArrayByKey}/index.d.ts +2 -2
- package/dist/Data/{LibGroupArrayByKey → LibJsGroupArrayByKey}/index.js +2 -2
- package/dist/Data/{LibMatchEmail → LibJsMatchEmail}/index.d.ts +2 -2
- package/dist/Data/{LibMatchEmail → LibJsMatchEmail}/index.js +2 -2
- package/dist/Data/{LibShuffleArray → LibJsShuffleArray}/index.d.ts +2 -2
- package/dist/Data/{LibShuffleArray → LibJsShuffleArray}/index.js +2 -2
- package/dist/Data/{LibStepArray → LibJsStepArray}/index.d.ts +2 -2
- package/dist/Data/{LibStepArray → LibJsStepArray}/index.js +2 -2
- package/dist/File/LibJsDownloadImageLink/index.d.ts +7 -0
- package/dist/File/{LibDownloadImageLink → LibJsDownloadImageLink}/index.js +2 -2
- package/dist/File/{LibImageOptimizer → LibJsImageOptimizer}/index.d.ts +3 -4
- package/dist/File/{LibImageOptimizer → LibJsImageOptimizer}/index.js +2 -3
- package/dist/File/LibJsSaveJson/index.d.ts +9 -0
- package/dist/File/{LibSaveJson → LibJsSaveJson}/index.js +3 -3
- package/dist/Formatter/{LibFormatterByte → LibJsFormatterByte}/index.d.ts +2 -2
- package/dist/Formatter/{LibFormatterByte → LibJsFormatterByte}/index.js +2 -2
- package/dist/Formatter/{LibMaskPhoneNumber → LibJsMaskPhoneNumber}/index.d.ts +2 -2
- package/dist/Formatter/{LibMaskPhoneNumber → LibJsMaskPhoneNumber}/index.js +2 -2
- package/dist/Formatter/{LibNumComma → LibJsNumComma}/index.d.ts +2 -2
- package/dist/Formatter/{LibNumComma → LibJsNumComma}/index.js +2 -2
- package/dist/Formatter/{LibNumberUnit → LibJsNumberUnit}/index.d.ts +3 -3
- package/dist/Formatter/{LibNumberUnit → LibJsNumberUnit}/index.js +2 -2
- package/dist/Formatter/LibJsSecondsFormatterChinese/index.d.ts +11 -0
- package/dist/Formatter/{LibSecondsFormatterChinese → LibJsSecondsFormatterChinese}/index.js +5 -5
- package/dist/Math/{LibCalculateExpression → LibJsCalculateExpression}/index.d.ts +2 -2
- package/dist/Math/{LibCalculateExpression → LibJsCalculateExpression}/index.js +2 -2
- package/dist/Math/LibJsConvertAngle/index.d.ts +12 -0
- package/dist/Math/{LibConvertAngle → LibJsConvertAngle}/index.js +3 -3
- package/dist/Math/LibJsCoordsAngle/index.d.ts +15 -0
- package/dist/Math/{LibCoordsAngle → LibJsCoordsAngle}/index.js +4 -4
- package/dist/Math/LibJsCoordsDistance/index.d.ts +15 -0
- package/dist/Math/{LibCoordsDistance → LibJsCoordsDistance}/index.js +4 -4
- package/dist/Math/LibJsDecimal/index.d.ts +10 -0
- package/dist/Math/{LibDecimal → LibJsDecimal}/index.js +4 -4
- package/dist/Misc/{LibRegFormValidate → LibJsRegFormValidate}/index.d.ts +3 -3
- package/dist/Misc/{LibRegFormValidate → LibJsRegFormValidate}/index.js +3 -3
- package/dist/Misc/{LibRetryRequest → LibJsRetryRequest}/index.d.ts +2 -2
- package/dist/Misc/{LibRetryRequest → LibJsRetryRequest}/index.js +2 -2
- package/dist/Random/LibJsProbabilityResult/index.d.ts +8 -0
- package/dist/Random/LibJsProbabilityResult/index.js +8 -0
- package/dist/Random/LibJsRandom/index.d.ts +9 -0
- package/dist/Random/{LibRandom → LibJsRandom}/index.js +3 -3
- package/dist/Random/LibJsRandomColor/index.d.ts +7 -0
- package/dist/Random/{LibRandomColor → LibJsRandomColor}/index.js +3 -3
- package/dist/Random/LibJsUniqueRandomNumbers/index.d.ts +9 -0
- package/dist/Random/{LibUniqueRandomNumbers → LibJsUniqueRandomNumbers}/index.js +3 -3
- package/dist/Time/{LibSameTimeCheck → LibJsSameTimeCheck}/index.d.ts +1 -1
- package/dist/Time/{LibSameTimeCheck → LibJsSameTimeCheck}/index.js +1 -1
- package/dist/Time/LibJsTimeAgo/index.d.ts +9 -0
- package/dist/Time/{LibTimeAgo → LibJsTimeAgo}/index.js +5 -5
- package/dist/Time/LibJsTimeGreeting/index.d.ts +17 -0
- package/dist/Time/{LibTimeGreeting → LibJsTimeGreeting}/index.js +4 -4
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/{lib.d.ts → libJs.d.ts} +97 -97
- package/dist/{lib.js → libJs.js} +132 -132
- package/package.json +1 -1
- package/dist/Base/LibGetDataType/index.d.ts +0 -10
- package/dist/Browser/LibColorConsole/index.d.ts +0 -15
- package/dist/Browser/LibSetTitleIcon/index.d.ts +0 -7
- package/dist/Data/LibDeepJSONParse/index.d.ts +0 -6
- package/dist/File/LibDownloadImageLink/index.d.ts +0 -7
- package/dist/File/LibSaveJson/index.d.ts +0 -9
- package/dist/Formatter/LibSecondsFormatterChinese/index.d.ts +0 -11
- package/dist/Math/LibConvertAngle/index.d.ts +0 -12
- package/dist/Math/LibCoordsAngle/index.d.ts +0 -15
- package/dist/Math/LibCoordsDistance/index.d.ts +0 -15
- package/dist/Math/LibDecimal/index.d.ts +0 -10
- package/dist/Random/LibProbabilityResult/index.d.ts +0 -8
- package/dist/Random/LibProbabilityResult/index.js +0 -8
- package/dist/Random/LibRandom/index.d.ts +0 -9
- package/dist/Random/LibRandomColor/index.d.ts +0 -7
- package/dist/Random/LibUniqueRandomNumbers/index.d.ts +0 -9
- package/dist/Time/LibTimeAgo/index.d.ts +0 -9
- package/dist/Time/LibTimeGreeting/index.d.ts +0 -17
package/dist/{lib.js → libJs.js}
RENAMED
|
@@ -1,60 +1,60 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
17
|
-
import {
|
|
18
|
-
import {
|
|
19
|
-
import {
|
|
20
|
-
import {
|
|
21
|
-
import {
|
|
22
|
-
import {
|
|
23
|
-
import {
|
|
24
|
-
import {
|
|
25
|
-
import {
|
|
26
|
-
import {
|
|
27
|
-
import {
|
|
28
|
-
import {
|
|
29
|
-
import {
|
|
30
|
-
import {
|
|
31
|
-
import {
|
|
32
|
-
import {
|
|
33
|
-
import {
|
|
34
|
-
import {
|
|
35
|
-
import {
|
|
36
|
-
import {
|
|
1
|
+
import { libJsGetDataType } from "./Base/LibJsGetDataType";
|
|
2
|
+
import { libJsPromiseTimeout } from "./Base/LibJsPromiseTimeout";
|
|
3
|
+
import { libJsColorConsole } from "./Browser/LibJsColorConsole";
|
|
4
|
+
import { libJsIsMobile } from "./Browser/LibJsIsMobile";
|
|
5
|
+
import { libJsIsPad } from "./Browser/LibJsIsPad";
|
|
6
|
+
import { libJsPathParams } from "./Browser/LibJsPathParams";
|
|
7
|
+
import { libJsSetTitleIcon } from "./Browser/LibJsSetTitleIcon";
|
|
8
|
+
import { libJsTagTitleTip } from "./Browser/LibJsTagTitleTip";
|
|
9
|
+
import { libJsChunkArray } from "./Data/LibJsChunkArray";
|
|
10
|
+
import { libJsDeepJSONParse } from "./Data/LibJsDeepJSONParse";
|
|
11
|
+
import { libJsGroupArrayByKey } from "./Data/LibJsGroupArrayByKey";
|
|
12
|
+
import { libJsMatchEmail } from "./Data/LibJsMatchEmail";
|
|
13
|
+
import { libJsShuffleArray } from "./Data/LibJsShuffleArray";
|
|
14
|
+
import { libJsStepArray } from "./Data/LibJsStepArray";
|
|
15
|
+
import { libJsDownloadImageLink } from "./File/LibJsDownloadImageLink";
|
|
16
|
+
import { libJsImageOptimizer } from "./File/LibJsImageOptimizer";
|
|
17
|
+
import { libJsSaveJson } from "./File/LibJsSaveJson";
|
|
18
|
+
import { libJsSecondsFormatterChinese } from "./Formatter/LibJsSecondsFormatterChinese";
|
|
19
|
+
import { libJsFormatterByte } from "./Formatter/LibJsFormatterByte";
|
|
20
|
+
import { libJsMaskPhoneNumber } from "./Formatter/LibJsMaskPhoneNumber";
|
|
21
|
+
import { libJsNumComma } from "./Formatter/LibJsNumComma";
|
|
22
|
+
import { libJsNumberUnit } from "./Formatter/LibJsNumberUnit";
|
|
23
|
+
import { libJsCalculateExpression } from "./Math/LibJsCalculateExpression";
|
|
24
|
+
import { libJsConvertAngle } from "./Math/LibJsConvertAngle";
|
|
25
|
+
import { libJsCoordsAngle } from "./Math/LibJsCoordsAngle";
|
|
26
|
+
import { libJsCoordsDistance } from "./Math/LibJsCoordsDistance";
|
|
27
|
+
import { libJsDecimal } from "./Math/LibJsDecimal";
|
|
28
|
+
import { libJsRegFormValidate } from "./Misc/LibJsRegFormValidate";
|
|
29
|
+
import { libJsRetryRequest } from "./Misc/LibJsRetryRequest";
|
|
30
|
+
import { libJsProbabilityResult } from "./Random/LibJsProbabilityResult";
|
|
31
|
+
import { libJsRandom } from "./Random/LibJsRandom";
|
|
32
|
+
import { libJsRandomColor } from "./Random/LibJsRandomColor";
|
|
33
|
+
import { libJsUniqueRandomNumbers } from "./Random/LibJsUniqueRandomNumbers";
|
|
34
|
+
import { libJsSameTimeCheck } from "./Time/LibJsSameTimeCheck";
|
|
35
|
+
import { libJsTimeAgo } from "./Time/LibJsTimeAgo";
|
|
36
|
+
import { libJsTimeGreeting } from "./Time/LibJsTimeGreeting";
|
|
37
37
|
/** @description 基础方法 */
|
|
38
38
|
export const Base = {
|
|
39
39
|
/**
|
|
40
40
|
* @description 返回数据类型
|
|
41
41
|
* @param v 需要判断类型的数据
|
|
42
42
|
* @example
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
43
|
+
* libJsGetDataType(123); //"number"
|
|
44
|
+
* libJsGetDataType("hello"); //"string"
|
|
45
|
+
* libJsGetDataType([1, 2, 3]); //"array"
|
|
46
46
|
*/
|
|
47
|
-
|
|
47
|
+
libJsGetDataType,
|
|
48
48
|
/**
|
|
49
49
|
* @description 延时执行,切换到其他页面会暂停
|
|
50
50
|
* @param delay 延时毫秒数
|
|
51
51
|
* @param fn 延时执行函数
|
|
52
52
|
* @example
|
|
53
|
-
*
|
|
53
|
+
* libJsPromiseTimeout(3000, () => {
|
|
54
54
|
* console.log("执行延时函数");
|
|
55
55
|
* });
|
|
56
56
|
*/
|
|
57
|
-
|
|
57
|
+
libJsPromiseTimeout,
|
|
58
58
|
};
|
|
59
59
|
/** @description 浏览器相关方法 */
|
|
60
60
|
export const Browser = {
|
|
@@ -64,44 +64,44 @@ export const Browser = {
|
|
|
64
64
|
* @param logs 信息
|
|
65
65
|
* @example
|
|
66
66
|
* //使用红色打印日志
|
|
67
|
-
*
|
|
67
|
+
* libJsColorConsole("错误提示", "red", [{ label: "错误代码", value: 500 }]);
|
|
68
68
|
*
|
|
69
69
|
* //使用蓝色打印简单日志
|
|
70
|
-
*
|
|
70
|
+
* libJsColorConsole("信息", "blue", "操作成功");
|
|
71
71
|
*/
|
|
72
|
-
|
|
72
|
+
libJsColorConsole,
|
|
73
73
|
/** @description 判断是否为移动设备
|
|
74
74
|
* @example
|
|
75
|
-
* const isMobile =
|
|
75
|
+
* const isMobile = libJsIsMobile();
|
|
76
76
|
* console.log(isMobile); //true 或 false
|
|
77
77
|
*/
|
|
78
|
-
|
|
78
|
+
libJsIsMobile,
|
|
79
79
|
/** @description 判断是否为平板
|
|
80
80
|
* @example
|
|
81
|
-
* const isPad =
|
|
81
|
+
* const isPad = libJsIsPad();
|
|
82
82
|
* console.log(isPad); //true 或 false
|
|
83
83
|
*/
|
|
84
|
-
|
|
84
|
+
libJsIsPad,
|
|
85
85
|
/** @description 获取浏览器地址栏参数
|
|
86
86
|
* @example
|
|
87
|
-
* const params =
|
|
87
|
+
* const params = libJsPathParams();
|
|
88
88
|
* console.log(params); //{ param1: "value1", param2: "value2" }
|
|
89
89
|
*/
|
|
90
|
-
|
|
90
|
+
libJsPathParams,
|
|
91
91
|
/** @description 动态设置网站标题及图标
|
|
92
92
|
* @param title 网站标题
|
|
93
93
|
* @param url 网站图标地址
|
|
94
94
|
* @example
|
|
95
|
-
*
|
|
95
|
+
* libJsSetTitleIcon("我的网站", "https://example.com/favicon.ico");
|
|
96
96
|
*/
|
|
97
|
-
|
|
97
|
+
libJsSetTitleIcon,
|
|
98
98
|
/** @description 网站标题交互,当从当前网页切换到其他网页,网站标题自动切换
|
|
99
99
|
* @param backTitle 从其他网页返回时显示的标题
|
|
100
100
|
* @param leaveTitle 从当前网页离开时显示的标题
|
|
101
101
|
* * @example
|
|
102
|
-
*
|
|
102
|
+
* libJsTagTitleTip("欢迎回来", "来和妲己玩耍吧!");
|
|
103
103
|
*/
|
|
104
|
-
|
|
104
|
+
libJsTagTitleTip,
|
|
105
105
|
};
|
|
106
106
|
/** @description 数据相关方法 */
|
|
107
107
|
export const Data = {
|
|
@@ -110,51 +110,51 @@ export const Data = {
|
|
|
110
110
|
* @param arr 需要拆分的数组
|
|
111
111
|
* @param chunkSize 每个数组的元素数量
|
|
112
112
|
* @example
|
|
113
|
-
* const chunks =
|
|
113
|
+
* const chunks = libJsChunkArray([1, 2, 3, 4, 5, 6], 2);
|
|
114
114
|
* console.log(chunks); //[[1, 2], [3, 4], [5, 6]]
|
|
115
115
|
*/
|
|
116
|
-
|
|
116
|
+
libJsChunkArray,
|
|
117
117
|
/** @description 递归将JSON字符串深度解析为对象
|
|
118
118
|
* @example
|
|
119
|
-
* const obj =
|
|
119
|
+
* const obj = libJsDeepJSONParse('{"a": 1, "b": "{\"c\": 2}"}');
|
|
120
120
|
* console.log(obj); //{ a: 1, b: { c: 2 } }
|
|
121
121
|
*/
|
|
122
|
-
|
|
122
|
+
libJsDeepJSONParse,
|
|
123
123
|
/**
|
|
124
124
|
* @description 分类汇总,将数组对象按照指定键值整理成一个以键值为键名的对象
|
|
125
125
|
* @param arr 要分组的数组
|
|
126
126
|
* @param key 分组的键
|
|
127
127
|
* @returns 分组后的对象
|
|
128
128
|
* @example
|
|
129
|
-
* const grouped =
|
|
129
|
+
* const grouped = libJsGroupArrayByKey([{ id: 1, name: 'A' }, { id: 2, name: 'B' }, { id: 1, name: 'C' }], 'id');
|
|
130
130
|
* console.log(grouped); //{ 1: [{ id: 1, name: 'A' }, { id: 1, name: 'C' }], 2: [{ id: 2, name: 'B' }] }
|
|
131
131
|
*/
|
|
132
|
-
|
|
132
|
+
libJsGroupArrayByKey,
|
|
133
133
|
/**
|
|
134
134
|
* @description 匹配电子邮件,可用于实时输入时,自动补全常用邮箱后缀
|
|
135
135
|
* @param str 要匹配的字符串
|
|
136
136
|
* @param emailList 电子邮件后缀列表
|
|
137
137
|
* @returns 匹配结果数组
|
|
138
138
|
* @example
|
|
139
|
-
* const emails =
|
|
139
|
+
* const emails = libJsMatchEmail("user", ["@gmail.com", "@yahoo.com"]);
|
|
140
140
|
* console.log(emails); //["user@gmail.com", "user@yahoo.com"]
|
|
141
141
|
*/
|
|
142
|
-
|
|
142
|
+
libJsMatchEmail,
|
|
143
143
|
/** @description 数组乱序
|
|
144
144
|
* @param arr 需要乱序的数组
|
|
145
145
|
* @example
|
|
146
|
-
* const shuffled =
|
|
146
|
+
* const shuffled = libJsShuffleArray([1, 2, 3, 4, 5]);
|
|
147
147
|
* console.log(shuffled); //[3, 5, 2, 1, 4] (结果每次不同)
|
|
148
148
|
*/
|
|
149
|
-
|
|
149
|
+
libJsShuffleArray,
|
|
150
150
|
/** @description 数组元素整体步数移动
|
|
151
151
|
* @param arr 移动的数组
|
|
152
152
|
* @param step 负数为向后移动,正数为向前移动
|
|
153
153
|
* @example
|
|
154
|
-
* const moved =
|
|
154
|
+
* const moved = libJsStepArray([1, 2, 3, 4, 5], 2);
|
|
155
155
|
* console.log(moved); //[4, 5, 1, 2, 3]
|
|
156
156
|
*/
|
|
157
|
-
|
|
157
|
+
libJsStepArray,
|
|
158
158
|
};
|
|
159
159
|
/** @description 文件相关方法 */
|
|
160
160
|
export const File = {
|
|
@@ -162,14 +162,14 @@ export const File = {
|
|
|
162
162
|
* @param link 图片链接
|
|
163
163
|
* @param name 图片名称
|
|
164
164
|
* @example
|
|
165
|
-
*
|
|
165
|
+
* libJsDownloadImageLink("https://example.com/image.jpg", "downloaded-image.jpg");
|
|
166
166
|
*/
|
|
167
|
-
|
|
167
|
+
libJsDownloadImageLink,
|
|
168
168
|
/** @description 图片压缩
|
|
169
169
|
* @param obj 压缩参数
|
|
170
170
|
* @example
|
|
171
171
|
* //图片压缩使用示例
|
|
172
|
-
*
|
|
172
|
+
* libJsImageOptimizerOptionsParams({
|
|
173
173
|
* file: myFile,
|
|
174
174
|
* ratio: 0.8,
|
|
175
175
|
* width: 800,
|
|
@@ -182,15 +182,15 @@ export const File = {
|
|
|
182
182
|
* }
|
|
183
183
|
* });
|
|
184
184
|
*/
|
|
185
|
-
|
|
185
|
+
libJsImageOptimizer,
|
|
186
186
|
/**
|
|
187
187
|
* @description 保存文件到本地
|
|
188
188
|
* @param data 要保存的数据
|
|
189
189
|
* @param name 文件名
|
|
190
190
|
* @example
|
|
191
|
-
*
|
|
191
|
+
* libJsSaveJson(JSON.stringify({ key: "value" }), "example.json");
|
|
192
192
|
*/
|
|
193
|
-
|
|
193
|
+
libJsSaveJson,
|
|
194
194
|
};
|
|
195
195
|
/** @description 格式化相关方法 */
|
|
196
196
|
export const Formatter = {
|
|
@@ -199,47 +199,47 @@ export const Formatter = {
|
|
|
199
199
|
* @param bytes 字节数
|
|
200
200
|
* @returns ['大小', '单位', '大小及单位']
|
|
201
201
|
* @example
|
|
202
|
-
* const [size, unit, formatted] =
|
|
202
|
+
* const [size, unit, formatted] = libJsFormatterByte(2048);
|
|
203
203
|
* console.log(size, unit, formatted); //2.00 KB 2.00 KB
|
|
204
204
|
*/
|
|
205
|
-
|
|
205
|
+
libJsFormatterByte,
|
|
206
206
|
/**
|
|
207
207
|
* @description 隐藏手机号码中间的四位数字
|
|
208
208
|
* @param mobile 需要处理的手机号码
|
|
209
209
|
* @example
|
|
210
|
-
* const masked =
|
|
210
|
+
* const masked = libJsMaskPhoneNumber("13812345678");
|
|
211
211
|
* console.log(masked); //138****5678
|
|
212
212
|
*/
|
|
213
|
-
|
|
213
|
+
libJsMaskPhoneNumber,
|
|
214
214
|
/**
|
|
215
215
|
* @description 数字每三位添加逗号
|
|
216
216
|
* @param num 需要格式化的数字
|
|
217
217
|
* @param reserve 保留小数位数
|
|
218
218
|
* @example
|
|
219
|
-
* const formatted =
|
|
219
|
+
* const formatted = libJsNumComma(1234567.89);
|
|
220
220
|
* console.log(formatted); //1,234,567.89
|
|
221
221
|
*/
|
|
222
|
-
|
|
222
|
+
libJsNumComma,
|
|
223
223
|
/** @description 将大于1000的数字使用k为单位
|
|
224
224
|
* @param num 数字
|
|
225
225
|
* @param units 单位组,key为单位,value为格式化阈值
|
|
226
226
|
* @returns [数字, 单位]
|
|
227
227
|
* @example
|
|
228
|
-
* const [value, unit] =
|
|
228
|
+
* const [value, unit] = libJsNumberUnit(1500, { K: 1000, M: 1000000 });
|
|
229
229
|
* console.log(value, unit); //1.50 K
|
|
230
230
|
*/
|
|
231
|
-
|
|
231
|
+
libJsNumberUnit,
|
|
232
232
|
/**
|
|
233
233
|
* @description 将秒数格式化为中文时间描述,支持扩展到年和月
|
|
234
234
|
* @param seconds 秒数
|
|
235
235
|
* @returns 格式化后的中文时间
|
|
236
236
|
* @example
|
|
237
|
-
*
|
|
238
|
-
*
|
|
239
|
-
*
|
|
240
|
-
*
|
|
237
|
+
* libJsSecondsFormatterChinese(100000); //"1天3小时46分40秒"
|
|
238
|
+
* libJsSecondsFormatterChinese(31536000); //"1年"
|
|
239
|
+
* libJsSecondsFormatterChinese(3600); //"1小时"
|
|
240
|
+
* libJsSecondsFormatterChinese(90); //"1分30秒"
|
|
241
241
|
*/
|
|
242
|
-
|
|
242
|
+
libJsSecondsFormatterChinese,
|
|
243
243
|
};
|
|
244
244
|
/** @description 数学相关方法 */
|
|
245
245
|
export const Math = {
|
|
@@ -249,50 +249,50 @@ export const Math = {
|
|
|
249
249
|
* @returns 计算结果
|
|
250
250
|
*
|
|
251
251
|
* @example
|
|
252
|
-
* const result =
|
|
252
|
+
* const result = libJsCalculateExpression("(1+2)-(3*4)/5");
|
|
253
253
|
* console.log(result); //0.6
|
|
254
254
|
*/
|
|
255
|
-
|
|
255
|
+
libJsCalculateExpression,
|
|
256
256
|
/**
|
|
257
257
|
* @description 角度和弧度互相转换
|
|
258
258
|
* @param value 角度值或弧度值
|
|
259
259
|
* @param type 角度类型或弧度类型
|
|
260
260
|
* @example
|
|
261
261
|
* //角度转弧度
|
|
262
|
-
*
|
|
262
|
+
* libJsConvertAngle(90, "rad"); //返回 1.5708... (π/2)
|
|
263
263
|
*
|
|
264
264
|
* //弧度转角度
|
|
265
|
-
*
|
|
265
|
+
* libJsConvertAngle(Math.PI, "deg"); //返回 180
|
|
266
266
|
*/
|
|
267
|
-
|
|
267
|
+
libJsConvertAngle,
|
|
268
268
|
/** @description 计算两点角度
|
|
269
269
|
* @param coord1 起点坐标
|
|
270
270
|
* @param coord2 终点坐标
|
|
271
271
|
* @example
|
|
272
|
-
*
|
|
273
|
-
*
|
|
274
|
-
*
|
|
272
|
+
* libJsCoordsAngle({ x: 0, y: 0 }, { x: 1, y: 0 }); //0
|
|
273
|
+
* libJsCoordsAngle({ x: 0, y: 0 }, { x: 1, y: 1 }); //45
|
|
274
|
+
* libJsCoordsAngle({ x: 0, y: 0 }, { x: 0, y: 1 }); //90
|
|
275
275
|
*/
|
|
276
|
-
|
|
276
|
+
libJsCoordsAngle,
|
|
277
277
|
/** @description 计算两点距离
|
|
278
278
|
* @param coord1 起点坐标
|
|
279
279
|
* @param coord2 终点坐标
|
|
280
280
|
* @example
|
|
281
|
-
*
|
|
282
|
-
*
|
|
283
|
-
*
|
|
281
|
+
* libJsCoordsDistance({ x: 0, y: 0 }, { x: 3, y: 4 }); //5
|
|
282
|
+
* libJsCoordsDistance({ x: 1, y: 1 }, { x: 4, y: 5 }); //5
|
|
283
|
+
* libJsCoordsDistance({ x: 0, y: 0 }, { x: 0, y: 0 }); //0
|
|
284
284
|
*/
|
|
285
|
-
|
|
285
|
+
libJsCoordsDistance,
|
|
286
286
|
/** @description 计算两个数的运算结果,并保留指定位数的小数
|
|
287
287
|
* @param num1 第一个数
|
|
288
288
|
* @param num2 第二个数
|
|
289
289
|
* @param operator 运算符,支持加减乘除
|
|
290
290
|
* @example
|
|
291
|
-
*
|
|
292
|
-
*
|
|
293
|
-
*
|
|
291
|
+
* libJsDecimal(10, 3, "+"); //13
|
|
292
|
+
* libJsDecimal(10, 3, "-"); //7
|
|
293
|
+
* libJsDecimal(10, 3, "/", 2); //3.33
|
|
294
294
|
*/
|
|
295
|
-
|
|
295
|
+
libJsDecimal,
|
|
296
296
|
};
|
|
297
297
|
/** @description 杂项相关方法 */
|
|
298
298
|
export const Misc = {
|
|
@@ -307,17 +307,17 @@ export const Misc = {
|
|
|
307
307
|
* { key: "username", verify: /^[a-zA-Z0-9]{3,}$/, msg: "用户名不合法", name: "用户名" },
|
|
308
308
|
* { key: "email", verify: /^\S+@\S+\.\S+$/, msg: "邮箱格式不正确", name: "邮箱" },
|
|
309
309
|
* ];
|
|
310
|
-
*
|
|
310
|
+
* libJsRegFormValidate(form, rules);
|
|
311
311
|
* //返回结果: []
|
|
312
312
|
*
|
|
313
313
|
* const invalidForm = { username: "jo", email: "invalid-email" };
|
|
314
|
-
*
|
|
314
|
+
* libJsRegFormValidate(invalidForm, rules);
|
|
315
315
|
* //返回结果: [
|
|
316
316
|
* // { key: "username", msg: "用户名不合法", name: "用户名" },
|
|
317
317
|
* // { key: "email", msg: "邮箱格式不正确", name: "邮箱" }
|
|
318
318
|
* //]
|
|
319
319
|
*/
|
|
320
|
-
|
|
320
|
+
libJsRegFormValidate,
|
|
321
321
|
/** @description 请求失败重连
|
|
322
322
|
* @param promiseFn 请求函数
|
|
323
323
|
* @param maxRetries 最大重试次数
|
|
@@ -326,7 +326,7 @@ export const Misc = {
|
|
|
326
326
|
* @example
|
|
327
327
|
* const requestFn = (params: { url: string }) => fetch(params.url).then(res => res.json());
|
|
328
328
|
* const params = { url: "https://api.example.com/data" };
|
|
329
|
-
*
|
|
329
|
+
* libJsRetryRequest({
|
|
330
330
|
* promiseFn: requestFn,
|
|
331
331
|
* params,
|
|
332
332
|
* maxRetries: 5,
|
|
@@ -335,44 +335,44 @@ export const Misc = {
|
|
|
335
335
|
* .then(data => console.log(data))
|
|
336
336
|
* .catch(err => console.error(err));
|
|
337
337
|
*/
|
|
338
|
-
|
|
338
|
+
libJsRetryRequest,
|
|
339
339
|
};
|
|
340
340
|
/** @description 随机相关方法 */
|
|
341
341
|
export const Random = {
|
|
342
342
|
/** @description 百分比概率结果
|
|
343
343
|
* @param probability 触发概率,百分比,0-100
|
|
344
344
|
* @example
|
|
345
|
-
*
|
|
346
|
-
*
|
|
347
|
-
*
|
|
345
|
+
* libJsProbabilityResult(50); //50% 概率为 true
|
|
346
|
+
* libJsProbabilityResult(80); //80% 概率为 true
|
|
347
|
+
* libJsProbabilityResult(100); //100% 概率为 true
|
|
348
348
|
*/
|
|
349
|
-
|
|
349
|
+
libJsProbabilityResult,
|
|
350
350
|
/** @description 随机数
|
|
351
351
|
* @param min 最小值
|
|
352
352
|
* @param max 最大值
|
|
353
353
|
* @param num 保留小数位数
|
|
354
354
|
* @example
|
|
355
|
-
*
|
|
356
|
-
*
|
|
357
|
-
*
|
|
355
|
+
* libJsRandom(1, 10); //1 到 10 之间的随机整数
|
|
356
|
+
* libJsRandom(1, 10, 2); //1 到 10 之间保留两位小数的随机数
|
|
357
|
+
* libJsRandom(5, 5, 3); //返回 5.000
|
|
358
358
|
*/
|
|
359
|
-
|
|
359
|
+
libJsRandom,
|
|
360
360
|
/** @description 随机 RGBA 颜色
|
|
361
361
|
* @param alpha 透明度
|
|
362
362
|
* @example
|
|
363
|
-
*
|
|
364
|
-
*
|
|
363
|
+
* libJsRandomColor(); //生成随机的 RGBA 颜色,默认透明度 1
|
|
364
|
+
* libJsRandomColor(0.5); //生成随机的 RGBA 颜色,透明度为 0.5
|
|
365
365
|
*/
|
|
366
|
-
|
|
366
|
+
libJsRandomColor,
|
|
367
367
|
/** @description 随机生成n个指定范围的随机数数组
|
|
368
368
|
* @param min 最小值
|
|
369
369
|
* @param max 最大值
|
|
370
370
|
* @param count 数组长度
|
|
371
371
|
* @example
|
|
372
|
-
*
|
|
373
|
-
*
|
|
372
|
+
* libJsUniqueRandomNumbers(1, 10, 5); //从 1 到 10 中随机生成 5 个唯一数字
|
|
373
|
+
* libJsUniqueRandomNumbers(1, 100, 10); //从 1 到 100 中随机生成 10 个唯一数字
|
|
374
374
|
*/
|
|
375
|
-
|
|
375
|
+
libJsUniqueRandomNumbers,
|
|
376
376
|
};
|
|
377
377
|
/** @description 时间相关方法 */
|
|
378
378
|
export const Time = {
|
|
@@ -382,23 +382,23 @@ export const Time = {
|
|
|
382
382
|
* @param unit 判断单位
|
|
383
383
|
* @returns 0-同一单位时间 1-新单位时间 -1时间戳大于当前时间
|
|
384
384
|
*/
|
|
385
|
-
|
|
385
|
+
libJsSameTimeCheck,
|
|
386
386
|
/** @description 时间差计算
|
|
387
387
|
* @param timestamp 毫秒时间戳
|
|
388
388
|
* @example
|
|
389
|
-
*
|
|
390
|
-
*
|
|
391
|
-
*
|
|
392
|
-
*
|
|
389
|
+
* libJsTimeAgotamp(Date.now() - 3600000); //"1 小时前"
|
|
390
|
+
* libJsTimeAgotamp(Date.now() - 86400000); //"1 天前"
|
|
391
|
+
* libJsTimeAgotamp(Date.now() - 31536000000); //"1 年前"
|
|
392
|
+
* libJsTimeAgotamp(Date.now() - 10000); //"刚刚"
|
|
393
393
|
*/
|
|
394
|
-
|
|
394
|
+
libJsTimeAgo,
|
|
395
395
|
/**
|
|
396
396
|
* @description 根据当前时间返回问候语
|
|
397
397
|
* @param greet 自定义问候语对象
|
|
398
398
|
* @example
|
|
399
|
-
*
|
|
400
|
-
*
|
|
401
|
-
*
|
|
399
|
+
* libJsTimeGreeting(); //根据当前时间返回默认问候语
|
|
400
|
+
* libJsTimeGreeting({ morning: "早安" }); //自定义早上问候语
|
|
401
|
+
* libJsTimeGreeting({ afternoon: "午后好" }); //自定义下午问候语
|
|
402
402
|
*/
|
|
403
|
-
|
|
403
|
+
libJsTimeGreeting,
|
|
404
404
|
};
|
package/package.json
CHANGED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
export type LibGetDataTypeReturnType = "string" | "number" | "boolean" | "array" | "function" | "object";
|
|
2
|
-
/**
|
|
3
|
-
* @description 返回数据类型
|
|
4
|
-
* @param v 需要判断类型的数据
|
|
5
|
-
* @example
|
|
6
|
-
* libGetDataType(123); //"number"
|
|
7
|
-
* libGetDataType("hello"); //"string"
|
|
8
|
-
* libGetDataType([1, 2, 3]); //"array"
|
|
9
|
-
*/
|
|
10
|
-
export declare const libGetDataType: (v: any) => LibGetDataTypeReturnType;
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
/** @description console颜色打印
|
|
2
|
-
* @param title 标题
|
|
3
|
-
* @param color 颜色
|
|
4
|
-
* @param logs 信息
|
|
5
|
-
* @example
|
|
6
|
-
* //使用红色打印日志
|
|
7
|
-
* libColorConsole("错误提示", "red", [{ label: "错误代码", value: 500 }]);
|
|
8
|
-
*
|
|
9
|
-
* //使用蓝色打印简单日志
|
|
10
|
-
* libColorConsole("信息", "blue", "操作成功");
|
|
11
|
-
*/
|
|
12
|
-
export declare const libColorConsole: (title: string, color: "red" | "orange" | "yellow" | "green" | "blue" | "purple", logs?: {
|
|
13
|
-
label: string;
|
|
14
|
-
value: any;
|
|
15
|
-
}[] | any) => void;
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @description 保存文件到本地
|
|
3
|
-
* @param data 要保存的数据
|
|
4
|
-
* @param name 文件名
|
|
5
|
-
* @example
|
|
6
|
-
* libSaveJson(JSON.stringify({ key: "value" }), "example.json");
|
|
7
|
-
* libSaveJson("Hellow World!", "example.txt");
|
|
8
|
-
*/
|
|
9
|
-
export declare const libSaveJson: (data: BlobPart, name: string) => void;
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @description 将秒数格式化为中文时间描述,支持扩展到年
|
|
3
|
-
* @param seconds 秒数
|
|
4
|
-
* @returns 格式化后的中文时间
|
|
5
|
-
* @example
|
|
6
|
-
* libSecondsFormatterChinese(100000); //"1天3小时46分40秒"
|
|
7
|
-
* libSecondsFormatterChinese(31536000); //"1年"
|
|
8
|
-
* libSecondsFormatterChinese(3600); //"1小时"
|
|
9
|
-
* libSecondsFormatterChinese(90); //"1分30秒"
|
|
10
|
-
*/
|
|
11
|
-
export declare const libSecondsFormatterChinese: (seconds: number) => string;
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @description 角度和弧度互相转换
|
|
3
|
-
* @param value 角度值或弧度值
|
|
4
|
-
* @param type 角度类型或弧度类型
|
|
5
|
-
* @example
|
|
6
|
-
* //角度转弧度
|
|
7
|
-
* libConvertAngle(90, "rad"); //返回 1.5708... (π/2)
|
|
8
|
-
*
|
|
9
|
-
* //弧度转角度
|
|
10
|
-
* libConvertAngle(Math.PI, "deg"); //返回 180
|
|
11
|
-
*/
|
|
12
|
-
export declare const libConvertAngle: (value: number, type: "rad" | "deg") => number;
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
/** @description 计算两点角度
|
|
2
|
-
* @param coord1 起点坐标
|
|
3
|
-
* @param coord2 终点坐标
|
|
4
|
-
* @example
|
|
5
|
-
* libCoordsAngle({ x: 0, y: 0 }, { x: 1, y: 0 }); //0
|
|
6
|
-
* libCoordsAngle({ x: 0, y: 0 }, { x: 1, y: 1 }); //45
|
|
7
|
-
* libCoordsAngle({ x: 0, y: 0 }, { x: 0, y: 1 }); //90
|
|
8
|
-
*/
|
|
9
|
-
export declare const libCoordsAngle: (coord1: {
|
|
10
|
-
x: number;
|
|
11
|
-
y: number;
|
|
12
|
-
}, coord2: {
|
|
13
|
-
x: number;
|
|
14
|
-
y: number;
|
|
15
|
-
}) => number;
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
/** @description 计算两点距离
|
|
2
|
-
* @param coord1 起点坐标
|
|
3
|
-
* @param coord2 终点坐标
|
|
4
|
-
* @example
|
|
5
|
-
* libCoordsDistance({ x: 0, y: 0 }, { x: 3, y: 4 }); //5
|
|
6
|
-
* libCoordsDistance({ x: 1, y: 1 }, { x: 4, y: 5 }); //5
|
|
7
|
-
* libCoordsDistance({ x: 0, y: 0 }, { x: 0, y: 0 }); //0
|
|
8
|
-
*/
|
|
9
|
-
export declare const libCoordsDistance: (coord1: {
|
|
10
|
-
x: number;
|
|
11
|
-
y: number;
|
|
12
|
-
}, coord2: {
|
|
13
|
-
x: number;
|
|
14
|
-
y: number;
|
|
15
|
-
}) => number;
|