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
package/README.md
CHANGED
|
@@ -8,7 +8,15 @@
|
|
|
8
8
|
|
|
9
9
|
## 起步
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
**通过 `CDN ` 使用 `LibJs`**
|
|
12
|
+
|
|
13
|
+
> 你可以借助 script 标签直接通过 CDN 来使用 LibJs:
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
<script src="https://unpkg.com/lyb-js@1.1.1/dist/Lib.js"></script>
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
|
|
12
20
|
|
|
13
21
|
```ts
|
|
14
22
|
import { LibJs } from "lib-js-utils";
|
|
@@ -61,6 +69,8 @@ libJsCalculateExpression("(1+2)-(3*4)/5"); //0.6
|
|
|
61
69
|
|
|
62
70
|
\- [LibJsTagTitleTip-网站标题交互](#LibJsTagTitleTip-网站标题交互)
|
|
63
71
|
|
|
72
|
+
\- [LibJsObjToUrlParams-对象转Url参数](#LibJsObjToUrlParams-对象转Url参数)
|
|
73
|
+
|
|
64
74
|
|
|
65
75
|
### Data-数据
|
|
66
76
|
|
|
@@ -76,6 +86,8 @@ libJsCalculateExpression("(1+2)-(3*4)/5"); //0.6
|
|
|
76
86
|
|
|
77
87
|
\- [LibJsStepArray-数组偏移](#LibJsStepArray-数组偏移)
|
|
78
88
|
|
|
89
|
+
\- [LibReverseArrayFromIndex-数组定位翻转](#LibReverseArrayFromIndex-数组定位翻转)
|
|
90
|
+
|
|
79
91
|
|
|
80
92
|
### File-文件
|
|
81
93
|
|
|
@@ -117,6 +129,8 @@ libJsCalculateExpression("(1+2)-(3*4)/5"); //0.6
|
|
|
117
129
|
|
|
118
130
|
\- [LibJsRetryRequest-请求重连](#LibJsRetryRequest-请求重连)
|
|
119
131
|
|
|
132
|
+
\- [LibNumerStepper-数字步进器](#LibNumerStepper-数字步进器)
|
|
133
|
+
|
|
120
134
|
|
|
121
135
|
### Random-随机
|
|
122
136
|
|
|
@@ -217,6 +231,15 @@ libJsSetTitleIcon("我的网站", "https://example.com/favicon.ico");
|
|
|
217
231
|
libJsTagTitleTip("欢迎回来", "来和妲己玩耍吧!");
|
|
218
232
|
```
|
|
219
233
|
|
|
234
|
+
### LibJsObjToUrlParams-对象转Url参数
|
|
235
|
+
|
|
236
|
+
> 将对象转为地址栏参数
|
|
237
|
+
|
|
238
|
+
```js
|
|
239
|
+
libJsObjToParams({ name: "John", age: 30, active: true });
|
|
240
|
+
// "name=John&age=30&active=true"
|
|
241
|
+
```
|
|
242
|
+
|
|
220
243
|
## Data-数据
|
|
221
244
|
|
|
222
245
|
### LibJsChunkArray-数组拆分
|
|
@@ -273,6 +296,15 @@ const moved = libJsStepArray([1, 2, 3, 4, 5], 2);
|
|
|
273
296
|
console.log(moved); //[4, 5, 1, 2, 3]
|
|
274
297
|
```
|
|
275
298
|
|
|
299
|
+
### LibReverseArrayFromIndex-数组定位翻转
|
|
300
|
+
|
|
301
|
+
> 翻转指定索引后面的数组
|
|
302
|
+
|
|
303
|
+
```ts
|
|
304
|
+
libReverseArrayFromIndex([1, 2, 3, 4, 5], 1);
|
|
305
|
+
// [1, 2, 5, 4, 3]
|
|
306
|
+
```
|
|
307
|
+
|
|
276
308
|
## File-文件
|
|
277
309
|
|
|
278
310
|
### LibJsDownloadImageLink-图片下载
|
|
@@ -308,8 +340,8 @@ libJsImageOptimizerOptionsParams({
|
|
|
308
340
|
> 保存`JSON`文件到本地,也支持保存纯文本的`txt`文件
|
|
309
341
|
|
|
310
342
|
```ts
|
|
311
|
-
libJsSaveJson(JSON.stringify({ key: "value" })
|
|
312
|
-
libJsSaveJson("Hellow World!"
|
|
343
|
+
libJsSaveJson("example.json", JSON.stringify({ key: "value" }));
|
|
344
|
+
libJsSaveJson("example.txt", "Hellow World!");
|
|
313
345
|
```
|
|
314
346
|
|
|
315
347
|
## Formatter-格式化
|
|
@@ -417,7 +449,7 @@ libJsDecimal(10, 3, "-"); //7
|
|
|
417
449
|
libJsDecimal(10, 3, "/", 2); //3.33
|
|
418
450
|
```
|
|
419
451
|
|
|
420
|
-
## Misc
|
|
452
|
+
## Misc-杂项
|
|
421
453
|
|
|
422
454
|
### LibJsRegFormValidate-表单验证
|
|
423
455
|
|
|
@@ -457,6 +489,17 @@ libJsRetryRequest({
|
|
|
457
489
|
.catch(err => console.error(err));
|
|
458
490
|
```
|
|
459
491
|
|
|
492
|
+
### LibNumerStepper-数字步进器
|
|
493
|
+
|
|
494
|
+
> 通过调用方法来增加和减少数字索引
|
|
495
|
+
|
|
496
|
+
```ts
|
|
497
|
+
const stepper = new libNumerStepper(10, (index) => console.log(index));
|
|
498
|
+
stepper.down("add"); // 索引加1
|
|
499
|
+
stepper.updateIndex(5); // 更新索引为5
|
|
500
|
+
stepper.down("sub"); // 索引减1
|
|
501
|
+
```
|
|
502
|
+
|
|
460
503
|
## Random-随机
|
|
461
504
|
|
|
462
505
|
### LibJsProbabilityResult-概率触发
|
|
@@ -2,6 +2,7 @@ export type LibJsGetDataTypeReturnType = "string" | "number" | "boolean" | "arra
|
|
|
2
2
|
/**
|
|
3
3
|
* @description 返回数据类型
|
|
4
4
|
* @param v 需要判断类型的数据
|
|
5
|
+
* @link 了解更多:https://www.npmjs.com/package/lyb-js
|
|
5
6
|
* @example
|
|
6
7
|
* libJsGetDataType(123); //"number"
|
|
7
8
|
* libJsGetDataType("hello"); //"string"
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/** @description 将对象转为地址栏参数
|
|
2
|
+
* @param params 对象参数
|
|
3
|
+
* @link 了解更多:https://www.npmjs.com/package/lyb-js
|
|
4
|
+
* @example
|
|
5
|
+
* libJsObjToUrlParams({ name: "John", age: 30, active: true });
|
|
6
|
+
* // "name=John&age=30&active=true"
|
|
7
|
+
*/
|
|
8
|
+
export declare const libJsObjToUrlParams: (params: Record<string, string | number | boolean>) => string;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/** @description 将对象转为地址栏参数
|
|
2
|
+
* @param params 对象参数
|
|
3
|
+
* @link 了解更多:https://www.npmjs.com/package/lyb-js
|
|
4
|
+
* @example
|
|
5
|
+
* libJsObjToUrlParams({ name: "John", age: 30, active: true });
|
|
6
|
+
* // "name=John&age=30&active=true"
|
|
7
|
+
*/
|
|
8
|
+
export const libJsObjToUrlParams = (params) => {
|
|
9
|
+
return Object.entries(params)
|
|
10
|
+
.map(([key, value]) => `${key}=${value}`)
|
|
11
|
+
.join("&");
|
|
12
|
+
};
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
* @param arr 要分组的数组
|
|
4
4
|
* @param key 分组的键
|
|
5
5
|
* @returns 分组后的对象
|
|
6
|
+
* @link 了解更多:https://www.npmjs.com/package/lyb-js
|
|
6
7
|
* @example
|
|
7
8
|
* const grouped = libJsGroupArrayByKey([{ id: 1, name: 'A' }, { id: 2, name: 'B' }, { id: 1, name: 'C' }], 'id');
|
|
8
9
|
* console.log(grouped); //{ 1: [{ id: 1, name: 'A' }, { id: 1, name: 'C' }], 2: [{ id: 2, name: 'B' }] }
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
* @param arr 要分组的数组
|
|
4
4
|
* @param key 分组的键
|
|
5
5
|
* @returns 分组后的对象
|
|
6
|
+
* @link 了解更多:https://www.npmjs.com/package/lyb-js
|
|
6
7
|
* @example
|
|
7
8
|
* const grouped = libJsGroupArrayByKey([{ id: 1, name: 'A' }, { id: 2, name: 'B' }, { id: 1, name: 'C' }], 'id');
|
|
8
9
|
* console.log(grouped); //{ 1: [{ id: 1, name: 'A' }, { id: 1, name: 'C' }], 2: [{ id: 2, name: 'B' }] }
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
* @param str 要匹配的字符串
|
|
4
4
|
* @param emailList 电子邮件后缀列表
|
|
5
5
|
* @returns 匹配结果数组
|
|
6
|
+
* @link 了解更多:https://www.npmjs.com/package/lyb-js
|
|
6
7
|
* @example
|
|
7
8
|
* const emails = libJsMatchEmail("user", ["@gmail.com", "@yahoo.com"]);
|
|
8
9
|
* console.log(emails); //["user@gmail.com", "user@yahoo.com"]
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
* @param str 要匹配的字符串
|
|
4
4
|
* @param emailList 电子邮件后缀列表
|
|
5
5
|
* @returns 匹配结果数组
|
|
6
|
+
* @link 了解更多:https://www.npmjs.com/package/lyb-js
|
|
6
7
|
* @example
|
|
7
8
|
* const emails = libJsMatchEmail("user", ["@gmail.com", "@yahoo.com"]);
|
|
8
9
|
* console.log(emails); //["user@gmail.com", "user@yahoo.com"]
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/** @description 翻转指定索引后面的数组
|
|
2
|
+
* @param arr 数组
|
|
3
|
+
* @param index 开始索引
|
|
4
|
+
* @link 了解更多:https://www.npmjs.com/package/lyb-js
|
|
5
|
+
* @example
|
|
6
|
+
* libReverseArrayFromIndex([1, 2, 3, 4, 5], 1);
|
|
7
|
+
* // [1, 2, 5, 4, 3]
|
|
8
|
+
*/
|
|
9
|
+
export declare const libReverseArrayFromIndex: <T>(arr: T[], index: number) => T[];
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/** @description 翻转指定索引后面的数组
|
|
2
|
+
* @param arr 数组
|
|
3
|
+
* @param index 开始索引
|
|
4
|
+
* @link 了解更多:https://www.npmjs.com/package/lyb-js
|
|
5
|
+
* @example
|
|
6
|
+
* libReverseArrayFromIndex([1, 2, 3, 4, 5], 1);
|
|
7
|
+
* // [1, 2, 5, 4, 3]
|
|
8
|
+
*/
|
|
9
|
+
export const libReverseArrayFromIndex = (arr, index) => {
|
|
10
|
+
if (index < 0 || index >= arr.length) {
|
|
11
|
+
throw new Error("Index out of bounds");
|
|
12
|
+
}
|
|
13
|
+
const subArray = arr.slice(index + 1).reverse();
|
|
14
|
+
return [...arr.slice(0, index + 1), ...subArray];
|
|
15
|
+
};
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @description 保存文件到本地
|
|
3
|
-
* @param data 要保存的数据
|
|
4
3
|
* @param name 文件名
|
|
4
|
+
* @param data 要保存的数据
|
|
5
|
+
* @link 了解更多:https://www.npmjs.com/package/lyb-js
|
|
5
6
|
* @example
|
|
6
|
-
* libJsSaveJson(JSON.stringify({ key: "value" })
|
|
7
|
-
* libJsSaveJson("Hellow World!"
|
|
7
|
+
* libJsSaveJson("example.json", JSON.stringify({ key: "value" }));
|
|
8
|
+
* libJsSaveJson("example.txt", "Hellow World!");
|
|
8
9
|
*/
|
|
9
|
-
export declare const libJsSaveJson: (
|
|
10
|
+
export declare const libJsSaveJson: (name: string, data: BlobPart) => void;
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @description 保存文件到本地
|
|
3
|
-
* @param data 要保存的数据
|
|
4
3
|
* @param name 文件名
|
|
4
|
+
* @param data 要保存的数据
|
|
5
|
+
* @link 了解更多:https://www.npmjs.com/package/lyb-js
|
|
5
6
|
* @example
|
|
6
|
-
* libJsSaveJson(JSON.stringify({ key: "value" })
|
|
7
|
-
* libJsSaveJson("Hellow World!"
|
|
7
|
+
* libJsSaveJson("example.json", JSON.stringify({ key: "value" }));
|
|
8
|
+
* libJsSaveJson("example.txt", "Hellow World!");
|
|
8
9
|
*/
|
|
9
|
-
export const libJsSaveJson = (
|
|
10
|
+
export const libJsSaveJson = (name, data) => {
|
|
10
11
|
const urlObject = window.URL || window.webkitURL;
|
|
11
12
|
const exportBlob = new Blob([data]);
|
|
12
13
|
const saveLink = document.createElement("a");
|
|
@@ -5,6 +5,7 @@ export interface LibJsNumberUnitParams {
|
|
|
5
5
|
* @param num 数字
|
|
6
6
|
* @param units 单位组,key为单位,value为格式化阈值
|
|
7
7
|
* @returns [数字, 单位]
|
|
8
|
+
* @link 了解更多:https://www.npmjs.com/package/lyb-js
|
|
8
9
|
* @example
|
|
9
10
|
* const [value, unit] = libJsNumberUnit(1500, { K: 1000, M: 1000000 });
|
|
10
11
|
* console.log(value, unit); //1.50 K
|
|
@@ -3,6 +3,7 @@ import Decimal from "decimal.js";
|
|
|
3
3
|
* @param num 数字
|
|
4
4
|
* @param units 单位组,key为单位,value为格式化阈值
|
|
5
5
|
* @returns [数字, 单位]
|
|
6
|
+
* @link 了解更多:https://www.npmjs.com/package/lyb-js
|
|
6
7
|
* @example
|
|
7
8
|
* const [value, unit] = libJsNumberUnit(1500, { K: 1000, M: 1000000 });
|
|
8
9
|
* console.log(value, unit); //1.50 K
|
|
@@ -5,6 +5,7 @@ dayjs.extend(duration);
|
|
|
5
5
|
* @description 将秒数格式化为中文时间描述,支持扩展到年
|
|
6
6
|
* @param seconds 秒数
|
|
7
7
|
* @returns 格式化后的中文时间
|
|
8
|
+
* @link 了解更多:https://www.npmjs.com/package/lyb-js
|
|
8
9
|
* @example
|
|
9
10
|
* libJsSecondsFormatterChinese(100000); //"1天3小时46分40秒"
|
|
10
11
|
* libJsSecondsFormatterChinese(31536000); //"1年"
|