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