lyb-js 1.0.3 → 1.0.4

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.
Files changed (90) hide show
  1. package/README.md +102 -1
  2. package/package.json +1 -1
  3. package/dist/Base/LibGetDataType/index.d.ts +0 -10
  4. package/dist/Base/LibGetDataType/index.js +0 -15
  5. package/dist/Base/LibJsGetDataType/index.d.ts +0 -7
  6. package/dist/Base/LibJsGetDataType/index.js +0 -11
  7. package/dist/Base/LibPromiseTimeout/index.d.ts +0 -10
  8. package/dist/Base/LibPromiseTimeout/index.js +0 -40
  9. package/dist/Browser/LibColorConsole/index.d.ts +0 -15
  10. package/dist/Browser/LibColorConsole/index.js +0 -38
  11. package/dist/Browser/LibIsMobile/index.d.ts +0 -6
  12. package/dist/Browser/LibIsMobile/index.js +0 -9
  13. package/dist/Browser/LibIsPad/index.d.ts +0 -6
  14. package/dist/Browser/LibIsPad/index.js +0 -15
  15. package/dist/Browser/LibPathParams/index.d.ts +0 -6
  16. package/dist/Browser/LibPathParams/index.js +0 -16
  17. package/dist/Browser/LibSetTitleIcon/index.d.ts +0 -7
  18. package/dist/Browser/LibSetTitleIcon/index.js +0 -14
  19. package/dist/Browser/LibTagTitleTip/index.d.ts +0 -7
  20. package/dist/Browser/LibTagTitleTip/index.js +0 -24
  21. package/dist/Data/LibChunkArray/index.d.ts +0 -9
  22. package/dist/Data/LibChunkArray/index.js +0 -15
  23. package/dist/Data/LibDeepJSONParse/index.d.ts +0 -6
  24. package/dist/Data/LibDeepJSONParse/index.js +0 -32
  25. package/dist/Data/LibGroupArrayByKey/index.d.ts +0 -10
  26. package/dist/Data/LibGroupArrayByKey/index.js +0 -20
  27. package/dist/Data/LibMatchEmail/index.d.ts +0 -10
  28. package/dist/Data/LibMatchEmail/index.js +0 -16
  29. package/dist/Data/LibSearch/index.d.ts +0 -8
  30. package/dist/Data/LibSearch/index.js +0 -45
  31. package/dist/Data/LibShuffleArray/index.d.ts +0 -7
  32. package/dist/Data/LibShuffleArray/index.js +0 -14
  33. package/dist/Data/LibStepArray/index.d.ts +0 -8
  34. package/dist/Data/LibStepArray/index.js +0 -14
  35. package/dist/File/LibDownloadImageLink/index.d.ts +0 -7
  36. package/dist/File/LibDownloadImageLink/index.js +0 -17
  37. package/dist/File/LibFileSize/index.d.ts +0 -5
  38. package/dist/File/LibFileSize/index.js +0 -11
  39. package/dist/File/LibImageOptimizer/index.d.ts +0 -32
  40. package/dist/File/LibImageOptimizer/index.js +0 -83
  41. package/dist/File/LibImageOptimizerOptions/index.d.ts +0 -18
  42. package/dist/File/LibImageOptimizerOptions/index.js +0 -69
  43. package/dist/File/LibSaveExcel/index.d.ts +0 -11
  44. package/dist/File/LibSaveExcel/index.js +0 -17
  45. package/dist/File/LibSaveJson/index.d.ts +0 -9
  46. package/dist/File/LibSaveJson/index.js +0 -17
  47. package/dist/Formatter/LibFormatterByte/index.d.ts +0 -9
  48. package/dist/Formatter/LibFormatterByte/index.js +0 -17
  49. package/dist/Formatter/LibMaskPhoneNumber/index.d.ts +0 -8
  50. package/dist/Formatter/LibMaskPhoneNumber/index.js +0 -11
  51. package/dist/Formatter/LibNumComma/index.d.ts +0 -9
  52. package/dist/Formatter/LibNumComma/index.js +0 -13
  53. package/dist/Formatter/LibNumberUnit/index.d.ts +0 -12
  54. package/dist/Formatter/LibNumberUnit/index.js +0 -23
  55. package/dist/Formatter/LibSecondsFormatterChinese/index.d.ts +0 -11
  56. package/dist/Formatter/LibSecondsFormatterChinese/index.js +0 -42
  57. package/dist/Math/LibCalculateExpression/index.d.ts +0 -9
  58. package/dist/Math/LibCalculateExpression/index.js +0 -107
  59. package/dist/Math/LibConvertAngle/index.d.ts +0 -12
  60. package/dist/Math/LibConvertAngle/index.js +0 -22
  61. package/dist/Math/LibCoordsAngle/index.d.ts +0 -15
  62. package/dist/Math/LibCoordsAngle/index.js +0 -24
  63. package/dist/Math/LibCoordsDistance/index.d.ts +0 -15
  64. package/dist/Math/LibCoordsDistance/index.js +0 -16
  65. package/dist/Math/LibDecimal/index.d.ts +0 -10
  66. package/dist/Math/LibDecimal/index.js +0 -25
  67. package/dist/Misc/LibRegFormValidate/index.d.ts +0 -32
  68. package/dist/Misc/LibRegFormValidate/index.js +0 -34
  69. package/dist/Misc/LibRetryRequest/index.d.ts +0 -24
  70. package/dist/Misc/LibRetryRequest/index.js +0 -37
  71. package/dist/Random/LibProbabilityResult/index.d.ts +0 -8
  72. package/dist/Random/LibProbabilityResult/index.js +0 -8
  73. package/dist/Random/LibRandom/index.d.ts +0 -9
  74. package/dist/Random/LibRandom/index.js +0 -11
  75. package/dist/Random/LibRandomColor/index.d.ts +0 -7
  76. package/dist/Random/LibRandomColor/index.js +0 -12
  77. package/dist/Random/LibUniqueRandomNumbers/index.d.ts +0 -9
  78. package/dist/Random/LibUniqueRandomNumbers/index.js +0 -16
  79. package/dist/Time/LibSameTimeCheck/index.d.ts +0 -12
  80. package/dist/Time/LibSameTimeCheck/index.js +0 -24
  81. package/dist/Time/LibSecondsFormatterChinese/index.d.ts +0 -11
  82. package/dist/Time/LibSecondsFormatterChinese/index.js +0 -42
  83. package/dist/Time/LibTimeAgo/index.d.ts +0 -9
  84. package/dist/Time/LibTimeAgo/index.js +0 -27
  85. package/dist/Time/LibTimeGreeting/index.d.ts +0 -17
  86. package/dist/Time/LibTimeGreeting/index.js +0 -23
  87. package/dist/index.d.ts +0 -1
  88. package/dist/index.js +0 -1
  89. package/dist/lib.d.ts +0 -394
  90. package/dist/lib.js +0 -404
@@ -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;
@@ -1,16 +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 const libCoordsDistance = (coord1, coord2) => {
10
- //计算两个坐标之间的水平和垂直距离
11
- const deltaX = coord2.x - coord1.x;
12
- const deltaY = coord2.y - coord1.y;
13
- //使用勾股定理计算两点之间的距离
14
- const distance = Math.sqrt(deltaX * deltaX + deltaY * deltaY);
15
- return distance;
16
- };
@@ -1,10 +0,0 @@
1
- /** @description 计算两个数的运算结果,并保留指定位数的小数
2
- * @param num1 第一个数
3
- * @param num2 第二个数
4
- * @param operator 运算符,支持加减乘除
5
- * @example
6
- * libDecimal(10, 3, "+"); //13
7
- * libDecimal(10, 3, "-"); //7
8
- * libDecimal(10, 3, "/", 2); //3.33
9
- */
10
- export declare const libDecimal: (num1: number, num2: number, operator: "+" | "-" | "*" | "/", point?: number) => number;
@@ -1,25 +0,0 @@
1
- import { Decimal } from "decimal.js";
2
- /** @description 计算两个数的运算结果,并保留指定位数的小数
3
- * @param num1 第一个数
4
- * @param num2 第二个数
5
- * @param operator 运算符,支持加减乘除
6
- * @example
7
- * libDecimal(10, 3, "+"); //13
8
- * libDecimal(10, 3, "-"); //7
9
- * libDecimal(10, 3, "/", 2); //3.33
10
- */
11
- export const libDecimal = (num1, num2, operator, point = 2) => {
12
- const calc = {
13
- "+": (a, b) => a.add(b),
14
- "-": (a, b) => a.sub(b),
15
- "*": (a, b) => a.mul(b),
16
- "/": (a, b) => {
17
- if (b.eq(0)) {
18
- throw new Error("除数不能为0");
19
- }
20
- return a.div(b);
21
- },
22
- };
23
- const result = calc[operator](new Decimal(num1), new Decimal(num2));
24
- return Number(result.toFixed(point));
25
- };
@@ -1,32 +0,0 @@
1
- export type ValidationResult = {
2
- key: string;
3
- msg: string;
4
- name: string;
5
- };
6
- /**
7
- * @description 通过传递对象数字的方式进行正则或自定义函数进行验证
8
- * @param form 表单数据对象
9
- * @param rules 验证规则数组
10
- * @returns 验证结果数组,包含未通过验证的项
11
- * @example
12
- * const form = { username: "john", email: "john@example.com" };
13
- * const rules = [
14
- * { key: "username", verify: /^[a-zA-Z0-9]{3,}$/, msg: "用户名不合法", name: "用户名" },
15
- * { key: "email", verify: /^\S+@\S+\.\S+$/, msg: "邮箱格式不正确", name: "邮箱" },
16
- * ];
17
- * libRegFormValidate(form, rules);
18
- * //返回结果: []
19
- *
20
- * const invalidForm = { username: "jo", email: "invalid-email" };
21
- * libRegFormValidate(invalidForm, rules);
22
- * //返回结果: [
23
- * // { key: "username", msg: "用户名不合法", name: "用户名" },
24
- * // { key: "email", msg: "邮箱格式不正确", name: "邮箱" }
25
- * //]
26
- */
27
- export declare const libRegFormValidate: (form: Record<string, any>, rules: Array<{
28
- key: string;
29
- verify: RegExp | ((value: any) => boolean);
30
- msg: string;
31
- name: string;
32
- }>) => ValidationResult[];
@@ -1,34 +0,0 @@
1
- /**
2
- * @description 通过传递对象数字的方式进行正则或自定义函数进行验证
3
- * @param form 表单数据对象
4
- * @param rules 验证规则数组
5
- * @returns 验证结果数组,包含未通过验证的项
6
- * @example
7
- * const form = { username: "john", email: "john@example.com" };
8
- * const rules = [
9
- * { key: "username", verify: /^[a-zA-Z0-9]{3,}$/, msg: "用户名不合法", name: "用户名" },
10
- * { key: "email", verify: /^\S+@\S+\.\S+$/, msg: "邮箱格式不正确", name: "邮箱" },
11
- * ];
12
- * libRegFormValidate(form, rules);
13
- * //返回结果: []
14
- *
15
- * const invalidForm = { username: "jo", email: "invalid-email" };
16
- * libRegFormValidate(invalidForm, rules);
17
- * //返回结果: [
18
- * // { key: "username", msg: "用户名不合法", name: "用户名" },
19
- * // { key: "email", msg: "邮箱格式不正确", name: "邮箱" }
20
- * //]
21
- */
22
- export const libRegFormValidate = (form, rules) => {
23
- return rules.reduce((result, rule) => {
24
- const { key, verify, msg, name } = rule;
25
- const value = form[key];
26
- if (value === "" || value === undefined || value === null) {
27
- result.push({ key, msg: "必填项", name });
28
- }
29
- else if (typeof verify === "function" ? !verify(value) : !verify.test(value)) {
30
- result.push({ key, msg, name });
31
- }
32
- return result;
33
- }, []);
34
- };
@@ -1,24 +0,0 @@
1
- /** @description 请求失败重连
2
- * @param promiseFn 请求函数
3
- * @param maxRetries 最大重试次数
4
- * @param retryDelay 重试间隔时间
5
- * @param params 请求参数
6
- * @example
7
- * const requestFn = (params: { url: string }) => fetch(params.url).then(res => res.json());
8
- * const params = { url: "https://api.example.com/data" };
9
- * libRetryRequest({
10
- * promiseFn: requestFn,
11
- * params,
12
- * maxRetries: 5,
13
- * retryDelay: 1000
14
- * })
15
- * .then(data => console.log(data))
16
- * .catch(err => console.error(err));
17
- */
18
- export declare const libRetryRequest: <T>({ promiseFn, maxRetries, retryDelay, params, }: {
19
- promiseFn: (params?: any) => Promise<T>;
20
- params?: any;
21
- maxRetries?: number;
22
- retryDelay?: number;
23
- onRetry?: () => void;
24
- }) => Promise<T>;
@@ -1,37 +0,0 @@
1
- /** @description 请求失败重连
2
- * @param promiseFn 请求函数
3
- * @param maxRetries 最大重试次数
4
- * @param retryDelay 重试间隔时间
5
- * @param params 请求参数
6
- * @example
7
- * const requestFn = (params: { url: string }) => fetch(params.url).then(res => res.json());
8
- * const params = { url: "https://api.example.com/data" };
9
- * libRetryRequest({
10
- * promiseFn: requestFn,
11
- * params,
12
- * maxRetries: 5,
13
- * retryDelay: 1000
14
- * })
15
- * .then(data => console.log(data))
16
- * .catch(err => console.error(err));
17
- */
18
- export const libRetryRequest = ({ promiseFn, maxRetries = 3, retryDelay = 2000, params = undefined, }) => {
19
- return new Promise((resolve, reject) => {
20
- let count = 0;
21
- const makeRequest = () => {
22
- promiseFn(params)
23
- .then((res) => {
24
- resolve(res);
25
- })
26
- .catch((err) => {
27
- count++;
28
- if (count >= maxRetries) {
29
- reject(err);
30
- return;
31
- }
32
- setTimeout(makeRequest, retryDelay);
33
- });
34
- };
35
- makeRequest();
36
- });
37
- };
@@ -1,8 +0,0 @@
1
- /** @description 百分比概率结果
2
- * @param probability 触发概率,百分比,0-100
3
- * @example
4
- * libProbabilityResult(50); //50% 概率为 true
5
- * libProbabilityResult(80); //80% 概率为 true
6
- * libProbabilityResult(100); //100% 概率为 true
7
- */
8
- export declare const libProbabilityResult: (probability: number) => boolean;
@@ -1,8 +0,0 @@
1
- /** @description 百分比概率结果
2
- * @param probability 触发概率,百分比,0-100
3
- * @example
4
- * libProbabilityResult(50); //50% 概率为 true
5
- * libProbabilityResult(80); //80% 概率为 true
6
- * libProbabilityResult(100); //100% 概率为 true
7
- */
8
- export const libProbabilityResult = (probability) => Math.random() * 100 < probability;
@@ -1,9 +0,0 @@
1
- /** @description 随机获取两个数之间的值,包含两数自身
2
- * @param min 最小值
3
- * @param max 最大值
4
- * @param num 保留小数位数
5
- * @example
6
- * libRandom(1, 10); //1 到 10 之间的随机整数
7
- * libRandom(1, 10, 2); //1 到 10 之间保留两位小数的随机数
8
- */
9
- export declare const libRandom: (min: number, max: number, num?: number) => number;
@@ -1,11 +0,0 @@
1
- /** @description 随机获取两个数之间的值,包含两数自身
2
- * @param min 最小值
3
- * @param max 最大值
4
- * @param num 保留小数位数
5
- * @example
6
- * libRandom(1, 10); //1 到 10 之间的随机整数
7
- * libRandom(1, 10, 2); //1 到 10 之间保留两位小数的随机数
8
- */
9
- export const libRandom = (min, max, num = 0) => {
10
- return parseFloat((Math.random() * (max - min) + min).toFixed(num));
11
- };
@@ -1,7 +0,0 @@
1
- /** @description 随机 RGBA 颜色
2
- * @param alpha 透明度
3
- * @example
4
- * libRandomColor(); //生成随机的 RGBA 颜色,默认透明度 1
5
- * libRandomColor(0.5); //生成随机的 RGBA 颜色,透明度为 0.5
6
- */
7
- export declare const libRandomColor: (alpha?: number) => string;
@@ -1,12 +0,0 @@
1
- /** @description 随机 RGBA 颜色
2
- * @param alpha 透明度
3
- * @example
4
- * libRandomColor(); //生成随机的 RGBA 颜色,默认透明度 1
5
- * libRandomColor(0.5); //生成随机的 RGBA 颜色,透明度为 0.5
6
- */
7
- export const libRandomColor = (alpha = 1) => {
8
- const r = Math.floor(Math.random() * 256);
9
- const g = Math.floor(Math.random() * 256);
10
- const b = Math.floor(Math.random() * 256);
11
- return `rgba(${r}, ${g}, ${b}, ${alpha})`;
12
- };
@@ -1,9 +0,0 @@
1
- /** @description 随机生成指定个数、指定范围不重复的随机数数组
2
- * @param min 最小值
3
- * @param max 最大值
4
- * @param count 数组长度
5
- * @example
6
- * libUniqueRandomNumbers(1, 10, 5); //从 1 到 10 中随机生成 5 个唯一数字
7
- * libUniqueRandomNumbers(1, 100, 10); //从 1 到 100 中随机生成 10 个唯一数字
8
- */
9
- export declare const libUniqueRandomNumbers: (min: number, max: number, count: number) => number[];
@@ -1,16 +0,0 @@
1
- /** @description 随机生成指定个数、指定范围不重复的随机数数组
2
- * @param min 最小值
3
- * @param max 最大值
4
- * @param count 数组长度
5
- * @example
6
- * libUniqueRandomNumbers(1, 10, 5); //从 1 到 10 中随机生成 5 个唯一数字
7
- * libUniqueRandomNumbers(1, 100, 10); //从 1 到 100 中随机生成 10 个唯一数字
8
- */
9
- export const libUniqueRandomNumbers = (min, max, count) => {
10
- const numbers = Array.from({ length: max - min + 1 }, (_, i) => i + min);
11
- for (let i = numbers.length - 1; i > 0; i--) {
12
- const j = Math.floor(Math.random() * (i + 1));
13
- [numbers[i], numbers[j]] = [numbers[j], numbers[i]];
14
- }
15
- return numbers.slice(0, count);
16
- };
@@ -1,12 +0,0 @@
1
- import dayjs from "dayjs";
2
- /**
3
- * @description 传入时间戳与当前时间判断是否为同一分、同一时、同一天、同一周、同一月、同一年
4
- * @param timestamp 毫秒时间戳
5
- * @param unit 判断单位
6
- * @returns 0-同一单位时间 1-新单位时间 -1时间戳大于当前时间
7
- * @example
8
- * const timestamp = 1679872800000; //时间戳
9
- * const result = libSameTimeCheck(timestamp, 'day'); //判断是否为同一天
10
- * console.log(result); //0: 同一天, 1: 新的一天, -1: 时间戳大于当前时间
11
- */
12
- export declare const libSameTimeCheck: (timestamp: number, unit: dayjs.OpUnitType) => 0 | 1 | -1;
@@ -1,24 +0,0 @@
1
- import dayjs from "dayjs";
2
- /**
3
- * @description 传入时间戳与当前时间判断是否为同一分、同一时、同一天、同一周、同一月、同一年
4
- * @param timestamp 毫秒时间戳
5
- * @param unit 判断单位
6
- * @returns 0-同一单位时间 1-新单位时间 -1时间戳大于当前时间
7
- * @example
8
- * const timestamp = 1679872800000; //时间戳
9
- * const result = libSameTimeCheck(timestamp, 'day'); //判断是否为同一天
10
- * console.log(result); //0: 同一天, 1: 新的一天, -1: 时间戳大于当前时间
11
- */
12
- export const libSameTimeCheck = (timestamp, unit) => {
13
- const inputTime = dayjs(timestamp).startOf(unit);
14
- const currentTime = dayjs().startOf(unit);
15
- if (inputTime.isSame(currentTime)) {
16
- return 0;
17
- }
18
- else if (inputTime.isBefore(currentTime)) {
19
- return 1;
20
- }
21
- else {
22
- return -1;
23
- }
24
- };
@@ -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,42 +0,0 @@
1
- import dayjs from "dayjs";
2
- import duration from "dayjs/plugin/duration";
3
- dayjs.extend(duration);
4
- /**
5
- * @description 将秒数格式化为中文时间描述,支持扩展到年和月。
6
- * @param seconds 秒数
7
- * @returns 格式化后的中文时间
8
- * @example
9
- * libSecondsFormatterChinese(100000); // "1天3小时46分40秒"
10
- * libSecondsFormatterChinese(31536000); // "1年"
11
- * libSecondsFormatterChinese(3600); // "1小时"
12
- * libSecondsFormatterChinese(90); // "1分30秒"
13
- */
14
- export const libSecondsFormatterChinese = (seconds) => {
15
- const duration = dayjs.duration(seconds, "seconds");
16
- const years = Math.floor(duration.asYears());
17
- const months = Math.floor(duration.asMonths() % 12);
18
- const days = Math.floor(duration.asDays() % 30);
19
- const hours = duration.hours();
20
- const minutes = duration.minutes();
21
- const remainingSeconds = duration.seconds();
22
- const timeParts = [];
23
- if (years > 0) {
24
- timeParts.push(`${years}年`);
25
- }
26
- if (months > 0) {
27
- timeParts.push(`${months}月`);
28
- }
29
- if (days > 0) {
30
- timeParts.push(`${days}天`);
31
- }
32
- if (hours > 0) {
33
- timeParts.push(`${hours}小时`);
34
- }
35
- if (minutes > 0) {
36
- timeParts.push(`${minutes}分`);
37
- }
38
- if (timeParts.length === 0 || remainingSeconds > 0) {
39
- timeParts.push(`${remainingSeconds}秒`);
40
- }
41
- return timeParts.join("");
42
- };
@@ -1,9 +0,0 @@
1
- /** @description 时间差计算
2
- * @param timestamp 毫秒时间戳
3
- * @example
4
- * libTimeAgotamp(Date.now() - 3600000); //"1 小时前"
5
- * libTimeAgotamp(Date.now() - 86400000); //"1 天前"
6
- * libTimeAgotamp(Date.now() - 31536000000); //"1 年前"
7
- * libTimeAgotamp(Date.now() - 10000); //"刚刚"
8
- */
9
- export declare const libTimeAgo: (timestamp: number) => string;
@@ -1,27 +0,0 @@
1
- /** @description 时间差计算
2
- * @param timestamp 毫秒时间戳
3
- * @example
4
- * libTimeAgotamp(Date.now() - 3600000); //"1 小时前"
5
- * libTimeAgotamp(Date.now() - 86400000); //"1 天前"
6
- * libTimeAgotamp(Date.now() - 31536000000); //"1 年前"
7
- * libTimeAgotamp(Date.now() - 10000); //"刚刚"
8
- */
9
- export const libTimeAgo = (timestamp) => {
10
- const timeUnits = [
11
- { unit: "年", milliseconds: 365 * 24 * 60 * 60 * 1000 },
12
- { unit: "月", milliseconds: 30 * 24 * 60 * 60 * 1000 },
13
- { unit: "周", milliseconds: 7 * 24 * 60 * 60 * 1000 },
14
- { unit: "天", milliseconds: 24 * 60 * 60 * 1000 },
15
- { unit: "小时", milliseconds: 60 * 60 * 1000 },
16
- { unit: "分钟", milliseconds: 60 * 1000 },
17
- ];
18
- const currentTime = Date.now();
19
- const timeDifference = currentTime - timestamp;
20
- for (const { unit, milliseconds } of timeUnits) {
21
- if (timeDifference >= milliseconds) {
22
- const count = Math.floor(timeDifference / milliseconds);
23
- return `${count} ${unit}前`;
24
- }
25
- }
26
- return "刚刚";
27
- };
@@ -1,17 +0,0 @@
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
- * libTimeGreeting(); //根据当前时间返回默认问候语
14
- * libTimeGreeting({ morning: "早安" }); //自定义早上问候语
15
- * libTimeGreeting({ afternoon: "午后好" }); //自定义下午问候语
16
- */
17
- export declare const libTimeGreeting: (greet?: LibTimeGreetingParams) => string;
@@ -1,23 +0,0 @@
1
- /**
2
- * @description 根据当前时间返回问候语
3
- * @param greet 自定义问候语对象
4
- * @example
5
- * libTimeGreeting(); //根据当前时间返回默认问候语
6
- * libTimeGreeting({ morning: "早安" }); //自定义早上问候语
7
- * libTimeGreeting({ afternoon: "午后好" }); //自定义下午问候语
8
- */
9
- export const libTimeGreeting = (greet = {}) => {
10
- const { midnight = "午夜好", morning = "早上好", forenoon = "上午好", noon = "中午好", afternoon = "下午好", evening = "晚上好", } = greet;
11
- const now = new Date().getHours();
12
- return now < 4
13
- ? midnight
14
- : now < 10
15
- ? morning
16
- : now < 12
17
- ? forenoon
18
- : now < 14
19
- ? noon
20
- : now < 18
21
- ? afternoon
22
- : evening;
23
- };
package/dist/index.d.ts DELETED
@@ -1 +0,0 @@
1
- export * as Lib from "./lib";
package/dist/index.js DELETED
@@ -1 +0,0 @@
1
- export * as Lib from "./lib";