@fe-free/tool 1.0.2 → 1.1.1

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/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
1
  # @fe-free/tool
2
2
 
3
+ ## 1.1.1
4
+
5
+ ## 1.1.0
6
+
7
+ ### Minor Changes
8
+
9
+ - feat: 优化 date
10
+
11
+ ## 1.0.3
12
+
3
13
  ## 1.0.2
4
14
 
5
15
  ### Patch Changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fe-free/tool",
3
- "version": "1.0.2",
3
+ "version": "1.1.1",
4
4
  "description": "",
5
5
  "main": "./src/index.ts",
6
6
  "author": "",
package/src/date.ts ADDED
@@ -0,0 +1,31 @@
1
+ import dayjs from 'dayjs';
2
+ import { isNumber, isString } from 'lodash-es';
3
+
4
+ const maxDateSeconds = Math.abs(+dayjs().add(100, 'year') / 1000);
5
+
6
+ function getDayjs(text: string | number) {
7
+ // 字符串时间戳
8
+ if (isString(text) && /^\d+$/.test(text as string)) {
9
+ const timestamp = parseInt(text as string);
10
+
11
+ // 自动判断 s ms
12
+ if (timestamp > maxDateSeconds) {
13
+ return dayjs(timestamp);
14
+ }
15
+
16
+ return dayjs(timestamp * 1000);
17
+ }
18
+
19
+ if (isNumber(text)) {
20
+ if (text > maxDateSeconds) {
21
+ return dayjs(text);
22
+ }
23
+
24
+ return dayjs(text * 1000);
25
+ }
26
+
27
+ // 其他都可以 dayjs
28
+ return dayjs(text);
29
+ }
30
+
31
+ export { getDayjs };
package/src/index.ts CHANGED
@@ -1 +1,3 @@
1
1
  export { pinyin, pinyinFilter, pinyinMatch, pinyinMatchWithoutFirstLetter } from './pinyin';
2
+
3
+ export { getDayjs } from './date';