lyb-js 1.1.5 → 1.1.7
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 +110 -47
- package/dist/Base/LibJsGetDataType/index.d.ts +1 -5
- package/dist/Base/LibJsGetDataType/index.js +2 -6
- package/dist/Base/LibJsPromiseTimeout/index.d.ts +1 -5
- package/dist/Base/LibJsPromiseTimeout/index.js +12 -15
- package/dist/Browser/LibJsColorConsole/index.d.ts +1 -7
- package/dist/Browser/LibJsColorConsole/index.js +23 -19
- package/dist/Browser/LibJsIsMobile/index.d.ts +1 -4
- package/dist/Browser/LibJsIsMobile/index.js +3 -6
- package/dist/Browser/LibJsIsPad/index.d.ts +1 -4
- package/dist/Browser/LibJsIsPad/index.js +9 -12
- package/dist/Browser/LibJsObjToUrlParams/index.d.ts +1 -4
- package/dist/Browser/LibJsObjToUrlParams/index.js +6 -6
- package/dist/Browser/LibJsPathParams/index.d.ts +1 -4
- package/dist/Browser/LibJsPathParams/index.js +6 -9
- package/dist/Browser/LibJsSetTitleIcon/index.d.ts +1 -3
- package/dist/Browser/LibJsSetTitleIcon/index.js +4 -6
- package/dist/Browser/LibJsTagTitleTip/index.d.ts +1 -3
- package/dist/Browser/LibJsTagTitleTip/index.js +6 -8
- package/dist/Data/LibJsChunkArray/index.d.ts +1 -4
- package/dist/Data/LibJsChunkArray/index.js +4 -7
- package/dist/Data/LibJsDeepJSONParse/index.d.ts +1 -4
- package/dist/Data/LibJsDeepJSONParse/index.js +6 -9
- package/dist/Data/LibJsGroupArrayByKey/index.d.ts +1 -4
- package/dist/Data/LibJsGroupArrayByKey/index.js +4 -6
- package/dist/Data/LibJsMatchEmail/index.d.ts +1 -4
- package/dist/Data/LibJsMatchEmail/index.js +5 -8
- package/dist/Data/LibJsShuffleArray/index.d.ts +1 -4
- package/dist/Data/LibJsShuffleArray/index.js +16 -9
- package/dist/Data/LibJsStepArray/index.d.ts +1 -4
- package/dist/Data/LibJsStepArray/index.js +4 -7
- package/dist/Data/LibReverseArrayFromIndex/index.d.ts +1 -4
- package/dist/Data/LibReverseArrayFromIndex/index.js +13 -7
- package/dist/File/LibJsDownloadImageLink/index.d.ts +1 -3
- package/dist/File/LibJsDownloadImageLink/index.js +6 -8
- package/dist/File/LibJsImageOptimizer/index.d.ts +1 -14
- package/dist/File/LibJsImageOptimizer/index.js +37 -50
- package/dist/File/LibJsSaveJson/index.d.ts +1 -4
- package/dist/File/LibJsSaveJson/index.js +5 -8
- package/dist/Formatter/LibJsFormatterByte/index.d.ts +1 -4
- package/dist/Formatter/LibJsFormatterByte/index.js +7 -10
- package/dist/Formatter/LibJsMaskPhoneNumber/index.d.ts +1 -4
- package/dist/Formatter/LibJsMaskPhoneNumber/index.js +3 -6
- package/dist/Formatter/LibJsNumComma/index.d.ts +1 -4
- package/dist/Formatter/LibJsNumComma/index.js +5 -7
- package/dist/Formatter/LibJsNumberUnit/index.d.ts +6 -9
- package/dist/Formatter/LibJsNumberUnit/index.js +18 -14
- package/dist/Formatter/LibJsSecondsFormatterChinese/index.d.ts +1 -6
- package/dist/Formatter/LibJsSecondsFormatterChinese/index.js +16 -21
- package/dist/Math/LibJsCalculateExpression/index.d.ts +1 -4
- package/dist/Math/LibJsCalculateExpression/index.js +33 -32
- package/dist/Math/LibJsConvertAngle/index.d.ts +1 -7
- package/dist/Math/LibJsConvertAngle/index.js +2 -8
- package/dist/Math/LibJsCoordsAngle/index.d.ts +1 -5
- package/dist/Math/LibJsCoordsAngle/index.js +6 -10
- package/dist/Math/LibJsCoordsDistance/index.d.ts +1 -5
- package/dist/Math/LibJsCoordsDistance/index.js +5 -9
- package/dist/Math/LibJsDecimal/index.d.ts +1 -5
- package/dist/Math/LibJsDecimal/index.js +9 -12
- package/dist/Misc/LibJsRegFormValidate/index.d.ts +1 -16
- package/dist/Misc/LibJsRegFormValidate/index.js +7 -22
- package/dist/Misc/LibJsRetryRequest/index.d.ts +1 -12
- package/dist/Misc/LibJsRetryRequest/index.js +8 -18
- package/dist/Misc/LibNumerStepper/index.d.ts +1 -6
- package/dist/Misc/LibNumerStepper/index.js +28 -35
- package/dist/Random/LibJsProbabilityResult/index.d.ts +1 -5
- package/dist/Random/LibJsProbabilityResult/index.js +4 -6
- package/dist/Random/LibJsRandom/index.d.ts +1 -4
- package/dist/Random/LibJsRandom/index.js +3 -5
- package/dist/Random/LibJsRandomColor/index.d.ts +1 -4
- package/dist/Random/LibJsRandomColor/index.js +7 -9
- package/dist/Random/LibJsUniqueRandomNumbers/index.d.ts +1 -4
- package/dist/Random/LibJsUniqueRandomNumbers/index.js +7 -9
- package/dist/Time/LibJsSameTimeCheck/index.d.ts +1 -5
- package/dist/Time/LibJsSameTimeCheck/index.js +4 -8
- package/dist/Time/LibJsTimeAgo/index.d.ts +1 -6
- package/dist/Time/LibJsTimeAgo/index.js +9 -13
- package/dist/Time/LibJsTimeGreeting/index.d.ts +1 -5
- package/dist/Time/LibJsTimeGreeting/index.js +5 -8
- package/dist/libJs.d.ts +42 -201
- package/dist/libJs.js +95 -256
- package/package.json +1 -1
- package/umd/lyb.js +3 -3
|
@@ -1,59 +1,50 @@
|
|
|
1
1
|
/** @description 数字步进器
|
|
2
|
-
* @link
|
|
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
|
|
2
|
+
* @link 使用方法:https://www.npmjs.com/package/lyb-js#LibNumerStepper-数字步进器
|
|
8
3
|
*/
|
|
9
|
-
|
|
10
|
-
/** 数字变动时触发 */
|
|
11
|
-
_onChange;
|
|
12
|
-
/** 当前按下状态 */
|
|
13
|
-
_isDown = false;
|
|
14
|
-
/** 当前数字索引 */
|
|
15
|
-
_currentIndex = 0;
|
|
16
|
-
/** 定时器ID */
|
|
17
|
-
_timerId;
|
|
18
|
-
/** 计时器ID */
|
|
19
|
-
_intervalId;
|
|
20
|
-
/** 金额数 */
|
|
21
|
-
_numsLength = 0;
|
|
4
|
+
var libNumerStepper = /** @class */ (function () {
|
|
22
5
|
/**
|
|
23
6
|
* @param numsLength 数字长度
|
|
24
7
|
* @param onChange 数字变动时触发
|
|
25
8
|
*/
|
|
26
|
-
|
|
9
|
+
function libNumerStepper(numsLength, onChange) {
|
|
10
|
+
var _this = this;
|
|
11
|
+
/** 当前按下状态 */
|
|
12
|
+
this._isDown = false;
|
|
13
|
+
/** 当前数字索引 */
|
|
14
|
+
this._currentIndex = 0;
|
|
15
|
+
/** 金额数 */
|
|
16
|
+
this._numsLength = 0;
|
|
27
17
|
this._onChange = onChange;
|
|
28
18
|
this._numsLength = numsLength;
|
|
29
|
-
window.addEventListener("pointerup", ()
|
|
30
|
-
|
|
19
|
+
window.addEventListener("pointerup", function () {
|
|
20
|
+
_this._isDown && _this._up();
|
|
31
21
|
});
|
|
32
22
|
}
|
|
33
23
|
/** @description 按下 */
|
|
34
|
-
down(type) {
|
|
24
|
+
libNumerStepper.prototype.down = function (type) {
|
|
25
|
+
var _this = this;
|
|
35
26
|
this._isDown = true;
|
|
36
27
|
this._handleChange(type);
|
|
37
|
-
this._timerId = setTimeout(()
|
|
38
|
-
if (
|
|
39
|
-
|
|
40
|
-
|
|
28
|
+
this._timerId = setTimeout(function () {
|
|
29
|
+
if (_this._isDown) {
|
|
30
|
+
_this._intervalId = setInterval(function () {
|
|
31
|
+
_this._handleChange(type);
|
|
41
32
|
}, 100);
|
|
42
33
|
}
|
|
43
34
|
}, 100);
|
|
44
|
-
}
|
|
35
|
+
};
|
|
45
36
|
/** @description 更新索引 */
|
|
46
|
-
updateIndex(index) {
|
|
37
|
+
libNumerStepper.prototype.updateIndex = function (index) {
|
|
47
38
|
this._currentIndex = index;
|
|
48
|
-
}
|
|
39
|
+
};
|
|
49
40
|
/** @description 抬起 */
|
|
50
|
-
_up() {
|
|
41
|
+
libNumerStepper.prototype._up = function () {
|
|
51
42
|
this._isDown = false;
|
|
52
43
|
clearTimeout(this._timerId);
|
|
53
44
|
clearInterval(this._intervalId);
|
|
54
|
-
}
|
|
45
|
+
};
|
|
55
46
|
/** @description 处理数字变化 */
|
|
56
|
-
_handleChange(type) {
|
|
47
|
+
libNumerStepper.prototype._handleChange = function (type) {
|
|
57
48
|
if (type === "add") {
|
|
58
49
|
if (this._currentIndex < this._numsLength - 1) {
|
|
59
50
|
this._currentIndex++;
|
|
@@ -66,5 +57,7 @@ export class libNumerStepper {
|
|
|
66
57
|
this._onChange(this._currentIndex);
|
|
67
58
|
}
|
|
68
59
|
}
|
|
69
|
-
}
|
|
70
|
-
|
|
60
|
+
};
|
|
61
|
+
return libNumerStepper;
|
|
62
|
+
}());
|
|
63
|
+
export { libNumerStepper };
|
|
@@ -1,9 +1,5 @@
|
|
|
1
1
|
/** @description 百分比概率结果
|
|
2
2
|
* @param probability 触发概率,百分比,0-100
|
|
3
|
-
* @link
|
|
4
|
-
* @example
|
|
5
|
-
* libJsProbabilityResult(50); //50% 概率为 true
|
|
6
|
-
* libJsProbabilityResult(80); //80% 概率为 true
|
|
7
|
-
* libJsProbabilityResult(100); //100% 概率为 true
|
|
3
|
+
* @link 使用方法:https://www.npmjs.com/package/lyb-js#LibJsProbabilityResult-概率触发
|
|
8
4
|
*/
|
|
9
5
|
export declare const libJsProbabilityResult: (probability: number) => boolean;
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
/** @description 百分比概率结果
|
|
2
2
|
* @param probability 触发概率,百分比,0-100
|
|
3
|
-
* @link
|
|
4
|
-
* @example
|
|
5
|
-
* libJsProbabilityResult(50); //50% 概率为 true
|
|
6
|
-
* libJsProbabilityResult(80); //80% 概率为 true
|
|
7
|
-
* libJsProbabilityResult(100); //100% 概率为 true
|
|
3
|
+
* @link 使用方法:https://www.npmjs.com/package/lyb-js#LibJsProbabilityResult-概率触发
|
|
8
4
|
*/
|
|
9
|
-
export
|
|
5
|
+
export var libJsProbabilityResult = function (probability) {
|
|
6
|
+
return Math.random() * 100 < probability;
|
|
7
|
+
};
|
|
@@ -2,9 +2,6 @@
|
|
|
2
2
|
* @param min 最小值
|
|
3
3
|
* @param max 最大值
|
|
4
4
|
* @param num 保留小数位数
|
|
5
|
-
|
|
6
|
-
* @example
|
|
7
|
-
* libJsRandom(1, 10); //1 到 10 之间的随机整数
|
|
8
|
-
* libJsRandom(1, 10, 2); //1 到 10 之间保留两位小数的随机数
|
|
5
|
+
* @link 使用方法:https://www.npmjs.com/package/lyb-js#LibJsRandom-随机数
|
|
9
6
|
*/
|
|
10
7
|
export declare const libJsRandom: (min: number, max: number, num?: number) => number;
|
|
@@ -2,11 +2,9 @@
|
|
|
2
2
|
* @param min 最小值
|
|
3
3
|
* @param max 最大值
|
|
4
4
|
* @param num 保留小数位数
|
|
5
|
-
|
|
6
|
-
* @example
|
|
7
|
-
* libJsRandom(1, 10); //1 到 10 之间的随机整数
|
|
8
|
-
* libJsRandom(1, 10, 2); //1 到 10 之间保留两位小数的随机数
|
|
5
|
+
* @link 使用方法:https://www.npmjs.com/package/lyb-js#LibJsRandom-随机数
|
|
9
6
|
*/
|
|
10
|
-
export
|
|
7
|
+
export var libJsRandom = function (min, max, num) {
|
|
8
|
+
if (num === void 0) { num = 0; }
|
|
11
9
|
return parseFloat((Math.random() * (max - min) + min).toFixed(num));
|
|
12
10
|
};
|
|
@@ -1,8 +1,5 @@
|
|
|
1
1
|
/** @description 随机 RGBA 颜色
|
|
2
2
|
* @param alpha 透明度
|
|
3
|
-
* @link
|
|
4
|
-
* @example
|
|
5
|
-
* libJsRandomColor(); //生成随机的 RGBA 颜色,默认透明度 1
|
|
6
|
-
* libJsRandomColor(0.5); //生成随机的 RGBA 颜色,透明度为 0.5
|
|
3
|
+
* @link 使用方法:https://www.npmjs.com/package/lyb-js#LibJsRandomColor-随机色
|
|
7
4
|
*/
|
|
8
5
|
export declare const libJsRandomColor: (alpha?: number) => string;
|
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
/** @description 随机 RGBA 颜色
|
|
2
2
|
* @param alpha 透明度
|
|
3
|
-
* @link
|
|
4
|
-
* @example
|
|
5
|
-
* libJsRandomColor(); //生成随机的 RGBA 颜色,默认透明度 1
|
|
6
|
-
* libJsRandomColor(0.5); //生成随机的 RGBA 颜色,透明度为 0.5
|
|
3
|
+
* @link 使用方法:https://www.npmjs.com/package/lyb-js#LibJsRandomColor-随机色
|
|
7
4
|
*/
|
|
8
|
-
export
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
5
|
+
export var libJsRandomColor = function (alpha) {
|
|
6
|
+
if (alpha === void 0) { alpha = 1; }
|
|
7
|
+
var r = Math.floor(Math.random() * 256);
|
|
8
|
+
var g = Math.floor(Math.random() * 256);
|
|
9
|
+
var b = Math.floor(Math.random() * 256);
|
|
10
|
+
return "rgba(".concat(r, ", ").concat(g, ", ").concat(b, ", ").concat(alpha, ")");
|
|
13
11
|
};
|
|
@@ -2,9 +2,6 @@
|
|
|
2
2
|
* @param min 最小值
|
|
3
3
|
* @param max 最大值
|
|
4
4
|
* @param count 数组长度
|
|
5
|
-
* @link
|
|
6
|
-
* @example
|
|
7
|
-
* libJsUniqueRandomNumbers(1, 10, 5); //从 1 到 10 中随机生成 5 个唯一数字
|
|
8
|
-
* libJsUniqueRandomNumbers(1, 100, 10); //从 1 到 100 中随机生成 10 个唯一数字
|
|
5
|
+
* @link 使用方法:https://www.npmjs.com/package/lyb-js#LibJsUniqueRandomNumbers-随机数数组
|
|
9
6
|
*/
|
|
10
7
|
export declare const libJsUniqueRandomNumbers: (min: number, max: number, count: number) => number[];
|
|
@@ -2,16 +2,14 @@
|
|
|
2
2
|
* @param min 最小值
|
|
3
3
|
* @param max 最大值
|
|
4
4
|
* @param count 数组长度
|
|
5
|
-
* @link
|
|
6
|
-
* @example
|
|
7
|
-
* libJsUniqueRandomNumbers(1, 10, 5); //从 1 到 10 中随机生成 5 个唯一数字
|
|
8
|
-
* libJsUniqueRandomNumbers(1, 100, 10); //从 1 到 100 中随机生成 10 个唯一数字
|
|
5
|
+
* @link 使用方法:https://www.npmjs.com/package/lyb-js#LibJsUniqueRandomNumbers-随机数数组
|
|
9
6
|
*/
|
|
10
|
-
export
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
7
|
+
export var libJsUniqueRandomNumbers = function (min, max, count) {
|
|
8
|
+
var _a;
|
|
9
|
+
var numbers = Array.from({ length: max - min + 1 }, function (_, i) { return i + min; });
|
|
10
|
+
for (var i = numbers.length - 1; i > 0; i--) {
|
|
11
|
+
var j = Math.floor(Math.random() * (i + 1));
|
|
12
|
+
_a = [numbers[j], numbers[i]], numbers[i] = _a[0], numbers[j] = _a[1];
|
|
15
13
|
}
|
|
16
14
|
return numbers.slice(0, count);
|
|
17
15
|
};
|
|
@@ -4,10 +4,6 @@ import dayjs from "dayjs";
|
|
|
4
4
|
* @param timestamp 毫秒时间戳
|
|
5
5
|
* @param unit 判断单位
|
|
6
6
|
* @returns 0-同一单位时间 1-新单位时间 -1时间戳大于当前时间
|
|
7
|
-
* @link
|
|
8
|
-
* @example
|
|
9
|
-
* const timestamp = 1679872800000; //时间戳
|
|
10
|
-
* const result = libSameTimeCheck(timestamp, 'day'); //判断是否为同一天
|
|
11
|
-
* console.log(result); //0: 同一天, 1: 新的一天, -1: 时间戳大于当前时间
|
|
7
|
+
* @link 使用方法:https://www.npmjs.com/package/lyb-js#LibJsSameTimeCheck-时间比对
|
|
12
8
|
*/
|
|
13
9
|
export declare const libJsSameTimeCheck: (timestamp: number, unit: dayjs.OpUnitType) => 0 | 1 | -1;
|
|
@@ -4,15 +4,11 @@ import dayjs from "dayjs";
|
|
|
4
4
|
* @param timestamp 毫秒时间戳
|
|
5
5
|
* @param unit 判断单位
|
|
6
6
|
* @returns 0-同一单位时间 1-新单位时间 -1时间戳大于当前时间
|
|
7
|
-
* @link
|
|
8
|
-
* @example
|
|
9
|
-
* const timestamp = 1679872800000; //时间戳
|
|
10
|
-
* const result = libSameTimeCheck(timestamp, 'day'); //判断是否为同一天
|
|
11
|
-
* console.log(result); //0: 同一天, 1: 新的一天, -1: 时间戳大于当前时间
|
|
7
|
+
* @link 使用方法:https://www.npmjs.com/package/lyb-js#LibJsSameTimeCheck-时间比对
|
|
12
8
|
*/
|
|
13
|
-
export
|
|
14
|
-
|
|
15
|
-
|
|
9
|
+
export var libJsSameTimeCheck = function (timestamp, unit) {
|
|
10
|
+
var inputTime = dayjs(timestamp).startOf(unit);
|
|
11
|
+
var currentTime = dayjs().startOf(unit);
|
|
16
12
|
if (inputTime.isSame(currentTime)) {
|
|
17
13
|
return 0;
|
|
18
14
|
}
|
|
@@ -1,10 +1,5 @@
|
|
|
1
1
|
/** @description 时间差计算
|
|
2
2
|
* @param timestamp 毫秒时间戳
|
|
3
|
-
* @link
|
|
4
|
-
* @example
|
|
5
|
-
* libJsTimeAgotamp(Date.now() - 3600000); //"1 小时前"
|
|
6
|
-
* libJsTimeAgotamp(Date.now() - 86400000); //"1 天前"
|
|
7
|
-
* libJsTimeAgotamp(Date.now() - 31536000000); //"1 年前"
|
|
8
|
-
* libJsTimeAgotamp(Date.now() - 10000); //"刚刚"
|
|
3
|
+
* @link 使用方法:https://www.npmjs.com/package/lyb-js#LibJsTimeAgo-中文时间差
|
|
9
4
|
*/
|
|
10
5
|
export declare const libJsTimeAgo: (timestamp: number) => string;
|
|
@@ -1,14 +1,9 @@
|
|
|
1
1
|
/** @description 时间差计算
|
|
2
2
|
* @param timestamp 毫秒时间戳
|
|
3
|
-
* @link
|
|
4
|
-
* @example
|
|
5
|
-
* libJsTimeAgotamp(Date.now() - 3600000); //"1 小时前"
|
|
6
|
-
* libJsTimeAgotamp(Date.now() - 86400000); //"1 天前"
|
|
7
|
-
* libJsTimeAgotamp(Date.now() - 31536000000); //"1 年前"
|
|
8
|
-
* libJsTimeAgotamp(Date.now() - 10000); //"刚刚"
|
|
3
|
+
* @link 使用方法:https://www.npmjs.com/package/lyb-js#LibJsTimeAgo-中文时间差
|
|
9
4
|
*/
|
|
10
|
-
export
|
|
11
|
-
|
|
5
|
+
export var libJsTimeAgo = function (timestamp) {
|
|
6
|
+
var timeUnits = [
|
|
12
7
|
{ unit: "年", milliseconds: 365 * 24 * 60 * 60 * 1000 },
|
|
13
8
|
{ unit: "月", milliseconds: 30 * 24 * 60 * 60 * 1000 },
|
|
14
9
|
{ unit: "周", milliseconds: 7 * 24 * 60 * 60 * 1000 },
|
|
@@ -16,12 +11,13 @@ export const libJsTimeAgo = (timestamp) => {
|
|
|
16
11
|
{ unit: "小时", milliseconds: 60 * 60 * 1000 },
|
|
17
12
|
{ unit: "分钟", milliseconds: 60 * 1000 },
|
|
18
13
|
];
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
for (
|
|
14
|
+
var currentTime = Date.now();
|
|
15
|
+
var timeDifference = currentTime - timestamp;
|
|
16
|
+
for (var _i = 0, timeUnits_1 = timeUnits; _i < timeUnits_1.length; _i++) {
|
|
17
|
+
var _a = timeUnits_1[_i], unit = _a.unit, milliseconds = _a.milliseconds;
|
|
22
18
|
if (timeDifference >= milliseconds) {
|
|
23
|
-
|
|
24
|
-
return
|
|
19
|
+
var count = Math.floor(timeDifference / milliseconds);
|
|
20
|
+
return "".concat(count, " ").concat(unit, "\u524D");
|
|
25
21
|
}
|
|
26
22
|
}
|
|
27
23
|
return "刚刚";
|
|
@@ -9,10 +9,6 @@ export interface LibTimeGreetingParams {
|
|
|
9
9
|
/**
|
|
10
10
|
* @description 根据当前时间返回问候语
|
|
11
11
|
* @param greet 自定义问候语对象
|
|
12
|
-
* @link
|
|
13
|
-
* @example
|
|
14
|
-
* libJsTimeGreeting(); //根据当前时间返回默认问候语
|
|
15
|
-
* libJsTimeGreeting({ morning: "早安" }); //自定义早上问候语
|
|
16
|
-
* libJsTimeGreeting({ afternoon: "午后好" }); //自定义下午问候语
|
|
12
|
+
* @link 使用方法:https://www.npmjs.com/package/lyb-js#LibJsTimeGreeting-时间问候
|
|
17
13
|
*/
|
|
18
14
|
export declare const libJsTimeGreeting: (greet?: LibTimeGreetingParams) => string;
|
|
@@ -1,15 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @description 根据当前时间返回问候语
|
|
3
3
|
* @param greet 自定义问候语对象
|
|
4
|
-
* @link
|
|
5
|
-
* @example
|
|
6
|
-
* libJsTimeGreeting(); //根据当前时间返回默认问候语
|
|
7
|
-
* libJsTimeGreeting({ morning: "早安" }); //自定义早上问候语
|
|
8
|
-
* libJsTimeGreeting({ afternoon: "午后好" }); //自定义下午问候语
|
|
4
|
+
* @link 使用方法:https://www.npmjs.com/package/lyb-js#LibJsTimeGreeting-时间问候
|
|
9
5
|
*/
|
|
10
|
-
export
|
|
11
|
-
|
|
12
|
-
|
|
6
|
+
export var libJsTimeGreeting = function (greet) {
|
|
7
|
+
if (greet === void 0) { greet = {}; }
|
|
8
|
+
var _a = greet.midnight, midnight = _a === void 0 ? "午夜好" : _a, _b = greet.morning, morning = _b === void 0 ? "早上好" : _b, _c = greet.forenoon, forenoon = _c === void 0 ? "上午好" : _c, _d = greet.noon, noon = _d === void 0 ? "中午好" : _d, _e = greet.afternoon, afternoon = _e === void 0 ? "下午好" : _e, _f = greet.evening, evening = _f === void 0 ? "晚上好" : _f;
|
|
9
|
+
var now = new Date().getHours();
|
|
13
10
|
return now < 4
|
|
14
11
|
? midnight
|
|
15
12
|
: now < 10
|