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
|
@@ -4,12 +4,12 @@
|
|
|
4
4
|
* @param type 角度类型或弧度类型
|
|
5
5
|
* @example
|
|
6
6
|
* //角度转弧度
|
|
7
|
-
*
|
|
7
|
+
* libJsConvertAngle(90, "rad"); //返回 1.5708... (π/2)
|
|
8
8
|
*
|
|
9
9
|
* //弧度转角度
|
|
10
|
-
*
|
|
10
|
+
* libJsConvertAngle(Math.PI, "deg"); //返回 180
|
|
11
11
|
*/
|
|
12
|
-
export const
|
|
12
|
+
export const libJsConvertAngle = (value, type) => {
|
|
13
13
|
if (type === "rad") {
|
|
14
14
|
return value * (Math.PI / 180);
|
|
15
15
|
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/** @description 计算两点角度
|
|
2
|
+
* @param coord1 起点坐标
|
|
3
|
+
* @param coord2 终点坐标
|
|
4
|
+
* @example
|
|
5
|
+
* libJsCoordsAngle({ x: 0, y: 0 }, { x: 1, y: 0 }); //0
|
|
6
|
+
* libJsCoordsAngle({ x: 0, y: 0 }, { x: 1, y: 1 }); //45
|
|
7
|
+
* libJsCoordsAngle({ x: 0, y: 0 }, { x: 0, y: 1 }); //90
|
|
8
|
+
*/
|
|
9
|
+
export declare const libJsCoordsAngle: (coord1: {
|
|
10
|
+
x: number;
|
|
11
|
+
y: number;
|
|
12
|
+
}, coord2: {
|
|
13
|
+
x: number;
|
|
14
|
+
y: number;
|
|
15
|
+
}) => number;
|
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
* @param coord1 起点坐标
|
|
3
3
|
* @param coord2 终点坐标
|
|
4
4
|
* @example
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
5
|
+
* libJsCoordsAngle({ x: 0, y: 0 }, { x: 1, y: 0 }); //0
|
|
6
|
+
* libJsCoordsAngle({ x: 0, y: 0 }, { x: 1, y: 1 }); //45
|
|
7
|
+
* libJsCoordsAngle({ x: 0, y: 0 }, { x: 0, y: 1 }); //90
|
|
8
8
|
*/
|
|
9
|
-
export const
|
|
9
|
+
export const libJsCoordsAngle = (coord1, coord2) => {
|
|
10
10
|
//计算相对于第一个坐标的水平和垂直距离
|
|
11
11
|
const deltaX = coord2.x - coord1.x;
|
|
12
12
|
const deltaY = coord2.y - coord1.y;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/** @description 计算两点距离
|
|
2
|
+
* @param coord1 起点坐标
|
|
3
|
+
* @param coord2 终点坐标
|
|
4
|
+
* @example
|
|
5
|
+
* libJsCoordsDistance({ x: 0, y: 0 }, { x: 3, y: 4 }); //5
|
|
6
|
+
* libJsCoordsDistance({ x: 1, y: 1 }, { x: 4, y: 5 }); //5
|
|
7
|
+
* libJsCoordsDistance({ x: 0, y: 0 }, { x: 0, y: 0 }); //0
|
|
8
|
+
*/
|
|
9
|
+
export declare const libJsCoordsDistance: (coord1: {
|
|
10
|
+
x: number;
|
|
11
|
+
y: number;
|
|
12
|
+
}, coord2: {
|
|
13
|
+
x: number;
|
|
14
|
+
y: number;
|
|
15
|
+
}) => number;
|
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
* @param coord1 起点坐标
|
|
3
3
|
* @param coord2 终点坐标
|
|
4
4
|
* @example
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
5
|
+
* libJsCoordsDistance({ x: 0, y: 0 }, { x: 3, y: 4 }); //5
|
|
6
|
+
* libJsCoordsDistance({ x: 1, y: 1 }, { x: 4, y: 5 }); //5
|
|
7
|
+
* libJsCoordsDistance({ x: 0, y: 0 }, { x: 0, y: 0 }); //0
|
|
8
8
|
*/
|
|
9
|
-
export const
|
|
9
|
+
export const libJsCoordsDistance = (coord1, coord2) => {
|
|
10
10
|
//计算两个坐标之间的水平和垂直距离
|
|
11
11
|
const deltaX = coord2.x - coord1.x;
|
|
12
12
|
const deltaY = coord2.y - coord1.y;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/** @description 计算两个数的运算结果,并保留指定位数的小数
|
|
2
|
+
* @param num1 第一个数
|
|
3
|
+
* @param num2 第二个数
|
|
4
|
+
* @param operator 运算符,支持加减乘除
|
|
5
|
+
* @example
|
|
6
|
+
* libJsDecimal(10, 3, "+"); //13
|
|
7
|
+
* libJsDecimal(10, 3, "-"); //7
|
|
8
|
+
* libJsDecimal(10, 3, "/", 2); //3.33
|
|
9
|
+
*/
|
|
10
|
+
export declare const libJsDecimal: (num1: number, num2: number, operator: "+" | "-" | "*" | "/", point?: number) => number;
|
|
@@ -4,11 +4,11 @@ import { Decimal } from "decimal.js";
|
|
|
4
4
|
* @param num2 第二个数
|
|
5
5
|
* @param operator 运算符,支持加减乘除
|
|
6
6
|
* @example
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
7
|
+
* libJsDecimal(10, 3, "+"); //13
|
|
8
|
+
* libJsDecimal(10, 3, "-"); //7
|
|
9
|
+
* libJsDecimal(10, 3, "/", 2); //3.33
|
|
10
10
|
*/
|
|
11
|
-
export const
|
|
11
|
+
export const libJsDecimal = (num1, num2, operator, point = 2) => {
|
|
12
12
|
const calc = {
|
|
13
13
|
"+": (a, b) => a.add(b),
|
|
14
14
|
"-": (a, b) => a.sub(b),
|
|
@@ -14,17 +14,17 @@ export type ValidationResult = {
|
|
|
14
14
|
* { key: "username", verify: /^[a-zA-Z0-9]{3,}$/, msg: "用户名不合法", name: "用户名" },
|
|
15
15
|
* { key: "email", verify: /^\S+@\S+\.\S+$/, msg: "邮箱格式不正确", name: "邮箱" },
|
|
16
16
|
* ];
|
|
17
|
-
*
|
|
17
|
+
* libJsRegFormValidate(form, rules);
|
|
18
18
|
* //返回结果: []
|
|
19
19
|
*
|
|
20
20
|
* const invalidForm = { username: "jo", email: "invalid-email" };
|
|
21
|
-
*
|
|
21
|
+
* libJsRegFormValidate(invalidForm, rules);
|
|
22
22
|
* //返回结果: [
|
|
23
23
|
* // { key: "username", msg: "用户名不合法", name: "用户名" },
|
|
24
24
|
* // { key: "email", msg: "邮箱格式不正确", name: "邮箱" }
|
|
25
25
|
* //]
|
|
26
26
|
*/
|
|
27
|
-
export declare const
|
|
27
|
+
export declare const libJsRegFormValidate: (form: Record<string, any>, rules: Array<{
|
|
28
28
|
key: string;
|
|
29
29
|
verify: RegExp | ((value: any) => boolean);
|
|
30
30
|
msg: string;
|
|
@@ -9,17 +9,17 @@
|
|
|
9
9
|
* { key: "username", verify: /^[a-zA-Z0-9]{3,}$/, msg: "用户名不合法", name: "用户名" },
|
|
10
10
|
* { key: "email", verify: /^\S+@\S+\.\S+$/, msg: "邮箱格式不正确", name: "邮箱" },
|
|
11
11
|
* ];
|
|
12
|
-
*
|
|
12
|
+
* libJsRegFormValidate(form, rules);
|
|
13
13
|
* //返回结果: []
|
|
14
14
|
*
|
|
15
15
|
* const invalidForm = { username: "jo", email: "invalid-email" };
|
|
16
|
-
*
|
|
16
|
+
* libJsRegFormValidate(invalidForm, rules);
|
|
17
17
|
* //返回结果: [
|
|
18
18
|
* // { key: "username", msg: "用户名不合法", name: "用户名" },
|
|
19
19
|
* // { key: "email", msg: "邮箱格式不正确", name: "邮箱" }
|
|
20
20
|
* //]
|
|
21
21
|
*/
|
|
22
|
-
export const
|
|
22
|
+
export const libJsRegFormValidate = (form, rules) => {
|
|
23
23
|
return rules.reduce((result, rule) => {
|
|
24
24
|
const { key, verify, msg, name } = rule;
|
|
25
25
|
const value = form[key];
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* @example
|
|
7
7
|
* const requestFn = (params: { url: string }) => fetch(params.url).then(res => res.json());
|
|
8
8
|
* const params = { url: "https://api.example.com/data" };
|
|
9
|
-
*
|
|
9
|
+
* libJsRetryRequest({
|
|
10
10
|
* promiseFn: requestFn,
|
|
11
11
|
* params,
|
|
12
12
|
* maxRetries: 5,
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
* .then(data => console.log(data))
|
|
16
16
|
* .catch(err => console.error(err));
|
|
17
17
|
*/
|
|
18
|
-
export declare const
|
|
18
|
+
export declare const libJsRetryRequest: <T>({ promiseFn, maxRetries, retryDelay, params, }: {
|
|
19
19
|
promiseFn: (params?: any) => Promise<T>;
|
|
20
20
|
params?: any;
|
|
21
21
|
maxRetries?: number;
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* @example
|
|
7
7
|
* const requestFn = (params: { url: string }) => fetch(params.url).then(res => res.json());
|
|
8
8
|
* const params = { url: "https://api.example.com/data" };
|
|
9
|
-
*
|
|
9
|
+
* libJsRetryRequest({
|
|
10
10
|
* promiseFn: requestFn,
|
|
11
11
|
* params,
|
|
12
12
|
* maxRetries: 5,
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
* .then(data => console.log(data))
|
|
16
16
|
* .catch(err => console.error(err));
|
|
17
17
|
*/
|
|
18
|
-
export const
|
|
18
|
+
export const libJsRetryRequest = ({ promiseFn, maxRetries = 3, retryDelay = 2000, params = undefined, }) => {
|
|
19
19
|
return new Promise((resolve, reject) => {
|
|
20
20
|
let count = 0;
|
|
21
21
|
const makeRequest = () => {
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/** @description 百分比概率结果
|
|
2
|
+
* @param probability 触发概率,百分比,0-100
|
|
3
|
+
* @example
|
|
4
|
+
* libJsProbabilityResult(50); //50% 概率为 true
|
|
5
|
+
* libJsProbabilityResult(80); //80% 概率为 true
|
|
6
|
+
* libJsProbabilityResult(100); //100% 概率为 true
|
|
7
|
+
*/
|
|
8
|
+
export declare const libJsProbabilityResult: (probability: number) => boolean;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/** @description 百分比概率结果
|
|
2
|
+
* @param probability 触发概率,百分比,0-100
|
|
3
|
+
* @example
|
|
4
|
+
* libJsProbabilityResult(50); //50% 概率为 true
|
|
5
|
+
* libJsProbabilityResult(80); //80% 概率为 true
|
|
6
|
+
* libJsProbabilityResult(100); //100% 概率为 true
|
|
7
|
+
*/
|
|
8
|
+
export const libJsProbabilityResult = (probability) => Math.random() * 100 < probability;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/** @description 随机获取两个数之间的值,包含两数自身
|
|
2
|
+
* @param min 最小值
|
|
3
|
+
* @param max 最大值
|
|
4
|
+
* @param num 保留小数位数
|
|
5
|
+
* @example
|
|
6
|
+
* libJsRandom(1, 10); //1 到 10 之间的随机整数
|
|
7
|
+
* libJsRandom(1, 10, 2); //1 到 10 之间保留两位小数的随机数
|
|
8
|
+
*/
|
|
9
|
+
export declare const libJsRandom: (min: number, max: number, num?: number) => number;
|
|
@@ -3,9 +3,9 @@
|
|
|
3
3
|
* @param max 最大值
|
|
4
4
|
* @param num 保留小数位数
|
|
5
5
|
* @example
|
|
6
|
-
*
|
|
7
|
-
*
|
|
6
|
+
* libJsRandom(1, 10); //1 到 10 之间的随机整数
|
|
7
|
+
* libJsRandom(1, 10, 2); //1 到 10 之间保留两位小数的随机数
|
|
8
8
|
*/
|
|
9
|
-
export const
|
|
9
|
+
export const libJsRandom = (min, max, num = 0) => {
|
|
10
10
|
return parseFloat((Math.random() * (max - min) + min).toFixed(num));
|
|
11
11
|
};
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/** @description 随机 RGBA 颜色
|
|
2
2
|
* @param alpha 透明度
|
|
3
3
|
* @example
|
|
4
|
-
*
|
|
5
|
-
*
|
|
4
|
+
* libJsRandomColor(); //生成随机的 RGBA 颜色,默认透明度 1
|
|
5
|
+
* libJsRandomColor(0.5); //生成随机的 RGBA 颜色,透明度为 0.5
|
|
6
6
|
*/
|
|
7
|
-
export const
|
|
7
|
+
export const libJsRandomColor = (alpha = 1) => {
|
|
8
8
|
const r = Math.floor(Math.random() * 256);
|
|
9
9
|
const g = Math.floor(Math.random() * 256);
|
|
10
10
|
const b = Math.floor(Math.random() * 256);
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/** @description 随机生成指定个数、指定范围不重复的随机数数组
|
|
2
|
+
* @param min 最小值
|
|
3
|
+
* @param max 最大值
|
|
4
|
+
* @param count 数组长度
|
|
5
|
+
* @example
|
|
6
|
+
* libJsUniqueRandomNumbers(1, 10, 5); //从 1 到 10 中随机生成 5 个唯一数字
|
|
7
|
+
* libJsUniqueRandomNumbers(1, 100, 10); //从 1 到 100 中随机生成 10 个唯一数字
|
|
8
|
+
*/
|
|
9
|
+
export declare const libJsUniqueRandomNumbers: (min: number, max: number, count: number) => number[];
|
|
@@ -3,10 +3,10 @@
|
|
|
3
3
|
* @param max 最大值
|
|
4
4
|
* @param count 数组长度
|
|
5
5
|
* @example
|
|
6
|
-
*
|
|
7
|
-
*
|
|
6
|
+
* libJsUniqueRandomNumbers(1, 10, 5); //从 1 到 10 中随机生成 5 个唯一数字
|
|
7
|
+
* libJsUniqueRandomNumbers(1, 100, 10); //从 1 到 100 中随机生成 10 个唯一数字
|
|
8
8
|
*/
|
|
9
|
-
export const
|
|
9
|
+
export const libJsUniqueRandomNumbers = (min, max, count) => {
|
|
10
10
|
const numbers = Array.from({ length: max - min + 1 }, (_, i) => i + min);
|
|
11
11
|
for (let i = numbers.length - 1; i > 0; i--) {
|
|
12
12
|
const j = Math.floor(Math.random() * (i + 1));
|
|
@@ -9,4 +9,4 @@ import dayjs from "dayjs";
|
|
|
9
9
|
* const result = libSameTimeCheck(timestamp, 'day'); //判断是否为同一天
|
|
10
10
|
* console.log(result); //0: 同一天, 1: 新的一天, -1: 时间戳大于当前时间
|
|
11
11
|
*/
|
|
12
|
-
export declare const
|
|
12
|
+
export declare const libJsSameTimeCheck: (timestamp: number, unit: dayjs.OpUnitType) => 0 | 1 | -1;
|
|
@@ -9,7 +9,7 @@ import dayjs from "dayjs";
|
|
|
9
9
|
* const result = libSameTimeCheck(timestamp, 'day'); //判断是否为同一天
|
|
10
10
|
* console.log(result); //0: 同一天, 1: 新的一天, -1: 时间戳大于当前时间
|
|
11
11
|
*/
|
|
12
|
-
export const
|
|
12
|
+
export const libJsSameTimeCheck = (timestamp, unit) => {
|
|
13
13
|
const inputTime = dayjs(timestamp).startOf(unit);
|
|
14
14
|
const currentTime = dayjs().startOf(unit);
|
|
15
15
|
if (inputTime.isSame(currentTime)) {
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/** @description 时间差计算
|
|
2
|
+
* @param timestamp 毫秒时间戳
|
|
3
|
+
* @example
|
|
4
|
+
* libJsTimeAgotamp(Date.now() - 3600000); //"1 小时前"
|
|
5
|
+
* libJsTimeAgotamp(Date.now() - 86400000); //"1 天前"
|
|
6
|
+
* libJsTimeAgotamp(Date.now() - 31536000000); //"1 年前"
|
|
7
|
+
* libJsTimeAgotamp(Date.now() - 10000); //"刚刚"
|
|
8
|
+
*/
|
|
9
|
+
export declare const libJsTimeAgo: (timestamp: number) => string;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
/** @description 时间差计算
|
|
2
2
|
* @param timestamp 毫秒时间戳
|
|
3
3
|
* @example
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
4
|
+
* libJsTimeAgotamp(Date.now() - 3600000); //"1 小时前"
|
|
5
|
+
* libJsTimeAgotamp(Date.now() - 86400000); //"1 天前"
|
|
6
|
+
* libJsTimeAgotamp(Date.now() - 31536000000); //"1 年前"
|
|
7
|
+
* libJsTimeAgotamp(Date.now() - 10000); //"刚刚"
|
|
8
8
|
*/
|
|
9
|
-
export const
|
|
9
|
+
export const libJsTimeAgo = (timestamp) => {
|
|
10
10
|
const timeUnits = [
|
|
11
11
|
{ unit: "年", milliseconds: 365 * 24 * 60 * 60 * 1000 },
|
|
12
12
|
{ unit: "月", milliseconds: 30 * 24 * 60 * 60 * 1000 },
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export interface LibTimeGreetingParams {
|
|
2
|
+
midnight?: string;
|
|
3
|
+
morning?: string;
|
|
4
|
+
forenoon?: string;
|
|
5
|
+
noon?: string;
|
|
6
|
+
afternoon?: string;
|
|
7
|
+
evening?: string;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* @description 根据当前时间返回问候语
|
|
11
|
+
* @param greet 自定义问候语对象
|
|
12
|
+
* @example
|
|
13
|
+
* libJsTimeGreeting(); //根据当前时间返回默认问候语
|
|
14
|
+
* libJsTimeGreeting({ morning: "早安" }); //自定义早上问候语
|
|
15
|
+
* libJsTimeGreeting({ afternoon: "午后好" }); //自定义下午问候语
|
|
16
|
+
*/
|
|
17
|
+
export declare const libJsTimeGreeting: (greet?: LibTimeGreetingParams) => string;
|
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
* @description 根据当前时间返回问候语
|
|
3
3
|
* @param greet 自定义问候语对象
|
|
4
4
|
* @example
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
5
|
+
* libJsTimeGreeting(); //根据当前时间返回默认问候语
|
|
6
|
+
* libJsTimeGreeting({ morning: "早安" }); //自定义早上问候语
|
|
7
|
+
* libJsTimeGreeting({ afternoon: "午后好" }); //自定义下午问候语
|
|
8
8
|
*/
|
|
9
|
-
export const
|
|
9
|
+
export const libJsTimeGreeting = (greet = {}) => {
|
|
10
10
|
const { midnight = "午夜好", morning = "早上好", forenoon = "上午好", noon = "中午好", afternoon = "下午好", evening = "晚上好", } = greet;
|
|
11
11
|
const now = new Date().getHours();
|
|
12
12
|
return now < 4
|
package/dist/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export * as
|
|
1
|
+
export * as LibJs from "./libJs";
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export * as
|
|
1
|
+
export * as LibJs from "./libJs";
|