@semi-kit/utils 1.4.0 → 1.4.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/lib/_utils/local.mjs +1 -1
- package/lib/date-picker.d.mts +6 -0
- package/lib/date-picker.mjs +1 -0
- package/lib/datetime.d.mts +5 -5
- package/lib/datetime.mjs +1 -1
- package/package.json +9 -3
package/lib/_utils/local.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{getAppProvider}from"@semi-kit/component";let globalMessages={"zh-CN":{pleaseSelect:`请选择`,pleaseInput:`请输入`,ipRule:`IP 地址格式错误`,officePhoneRule:`办公电话格式错误`,mobilePhoneRule:`手机号码格式错误`,emailRule:`邮箱格式错误`,onlyNumbersRule:`只能包含数字`,onlyLetterRule:`只能包含字母`,onlyLowercaseRule:`只能包含小写字母`,onlyUppercaseRule:`只能包含大写字母`,onlyIntRule:`只能包含整数`,onlyPositiveIntRule:`只能包含正整数`,onlyPositiveIntZeroRule:`只能包含 0 及正整数`,onlyNegativeIntRule:`只能包含负整数`,onlyChineseRule:`只能包含中文字符`,onlyNotChineseRule:`只能包含非中文字符`,lengthRule:`长度在 {min} 到 {max} 位字符`,onlyMinLengthRule:`长度最少 {min} 位字符`,onlyMaxLengthRule:`长度最多 {max} 位字符`,sizeRule:`数值需在 {min} 到 {max} 之间`,onlyMinSizeRule:`最小值不得小于 {min}`,onlyMaxSizeRule:`最大值不得超过 {max}`,decimalPlaceRule:`小数位数不得超过 {place}
|
|
1
|
+
import{getAppProvider}from"@semi-kit/component";let globalMessages={"zh-CN":{pleaseSelect:`请选择`,pleaseInput:`请输入`,ipRule:`IP 地址格式错误`,officePhoneRule:`办公电话格式错误`,mobilePhoneRule:`手机号码格式错误`,emailRule:`邮箱格式错误`,onlyNumbersRule:`只能包含数字`,onlyLetterRule:`只能包含字母`,onlyLowercaseRule:`只能包含小写字母`,onlyUppercaseRule:`只能包含大写字母`,onlyIntRule:`只能包含整数`,onlyPositiveIntRule:`只能包含正整数`,onlyPositiveIntZeroRule:`只能包含 0 及正整数`,onlyNegativeIntRule:`只能包含负整数`,onlyChineseRule:`只能包含中文字符`,onlyNotChineseRule:`只能包含非中文字符`,lengthRule:`长度在 {min} 到 {max} 位字符`,onlyMinLengthRule:`长度最少 {min} 位字符`,onlyMaxLengthRule:`长度最多 {max} 位字符`,sizeRule:`数值需在 {min} 到 {max} 之间`,onlyMinSizeRule:`最小值不得小于 {min}`,onlyMaxSizeRule:`最大值不得超过 {max}`,decimalPlaceRule:`小数位数不得超过 {place} 位`,dateYesterday:`昨天`,dateLast7Days:`最近 7 天`,dateLast30Days:`最近 30 天`,dateThisMonth:`本月`,dateLastMonth:`上月`},en:{pleaseSelect:`Please Select `,pleaseInput:`Please Input `,ipRule:`IP address format error`,officePhoneRule:`Office phone format error`,mobilePhoneRule:`Mobile phone format error`,emailRule:`Email format error`,onlyNumbersRule:`Only numbers allowed`,onlyLetterRule:`Only letters allowed`,onlyLowercaseRule:`Only lowercase letters allowed`,onlyUppercaseRule:`Only uppercase letters allowed`,onlyIntRule:`Only integers allowed`,onlyPositiveIntRule:`Only positive integers allowed`,onlyPositiveIntZeroRule:`Only positive integers or zero allowed`,onlyNegativeIntRule:`Only negative integers allowed`,onlyChineseRule:`Only Chinese characters allowed`,onlyNotChineseRule:`Chinese characters not allowed`,lengthRule:`The length ranges from {min} to {max} characters`,onlyMinLengthRule:`The minimum length {min} characters`,onlyMaxLengthRule:`The maximum length {max} characters`,sizeRule:`The values range from {min} to {max}`,onlyMinSizeRule:`The minimum value shall not be less than {min}`,onlyMaxSizeRule:`The maximum value shall not be exceeded {max}`,decimalPlaceRule:`Decimal places must not exceed {place} digits`,dateYesterday:`Yesterday`,dateLast7Days:`Last 7 Days`,dateLast30Days:`Last 30 Days`,dateThisMonth:`This Month`,dateLastMonth:`Last Month`}};function useLocal(){let n=getAppProvider();return(e,r)=>{let i=globalMessages[n.locale?.value]?.[e]||e;return r&&Object.keys(r).forEach(e=>{i=i.replace(RegExp(`\\{${e}\\}`,`g`),String(r[e]))}),i}}export{useLocal};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{useLocal}from"./_utils/local.mjs";import dayjs from"dayjs";const useDefaultShortcuts=()=>{let n=useLocal(),r=dayjs().startOf(`day`),i=r.endOf(`day`);return{[n(`dateYesterday`)]:()=>{let e=r.subtract(1,`day`);return[e.valueOf(),e.endOf(`day`).valueOf()]},[n(`dateLast7Days`)]:()=>[r.subtract(6,`day`).valueOf(),i.valueOf()],[n(`dateLast30Days`)]:()=>[r.subtract(29,`day`).valueOf(),i.valueOf()],[n(`dateThisMonth`)]:()=>[dayjs().startOf(`month`).valueOf(),i.valueOf()],[n(`dateLastMonth`)]:()=>{let e=dayjs().subtract(1,`month`);return[e.startOf(`month`).valueOf(),e.endOf(`month`).valueOf()]}}};export{useDefaultShortcuts};
|
package/lib/datetime.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ConfigType } from "dayjs";
|
|
2
2
|
interface FormatDateRangeParamsType {
|
|
3
3
|
endTimeType?: 'now' | 'full';
|
|
4
4
|
format?: string;
|
|
@@ -11,7 +11,7 @@ interface FormatDateRangeParamsType {
|
|
|
11
11
|
* getDayOfYear(new Date('2024-01-01')) -> 1
|
|
12
12
|
* getDayOfYear(new Date('2024-12-31')) -> 366
|
|
13
13
|
*/
|
|
14
|
-
declare const getDayOfYear: (date?:
|
|
14
|
+
declare const getDayOfYear: (date?: ConfigType) => number | undefined;
|
|
15
15
|
/**
|
|
16
16
|
* 判断给定日期是否是工作日
|
|
17
17
|
* @param date - 日期对象或可转换为日期的值
|
|
@@ -20,7 +20,7 @@ declare const getDayOfYear: (date?: DateLike) => number | undefined;
|
|
|
20
20
|
* isWeekday(new Date('2024-12-05')) -> true
|
|
21
21
|
* isWeekday(new Date('2024-12-07')) -> false
|
|
22
22
|
*/
|
|
23
|
-
declare const isWeekday: (date?:
|
|
23
|
+
declare const isWeekday: (date?: ConfigType) => boolean;
|
|
24
24
|
/**
|
|
25
25
|
* 时间转换为标准时间格式
|
|
26
26
|
* @param time - 时间戳或日期对象, 默认为当前时间
|
|
@@ -30,7 +30,7 @@ declare const isWeekday: (date?: DateLike) => boolean;
|
|
|
30
30
|
* useFormatTime(new Date()) -> '14:25:59'
|
|
31
31
|
* useFormatTime(1638345600000, 'HH:mm') -> '14:25'
|
|
32
32
|
*/
|
|
33
|
-
declare const useFormatTime: (time?:
|
|
33
|
+
declare const useFormatTime: (time?: ConfigType, type?: string) => string;
|
|
34
34
|
/**
|
|
35
35
|
* 时间转换为标准日期格式
|
|
36
36
|
* @param time - 时间戳或日期对象, 默认为当前时间
|
|
@@ -40,7 +40,7 @@ declare const useFormatTime: (time?: DateLike, type?: string) => string;
|
|
|
40
40
|
* useFormatDate(new Date()) -> '2022-11-09'
|
|
41
41
|
* useFormatDate(1638345600000, 'YYYY/MM/DD') -> '2021/12/01'
|
|
42
42
|
*/
|
|
43
|
-
declare const useFormatDate: (time?:
|
|
43
|
+
declare const useFormatDate: (time?: ConfigType, type?: string) => string;
|
|
44
44
|
/**
|
|
45
45
|
* 将日期时间范围转换为请求参数格式
|
|
46
46
|
* @param timestamp - 时间范围数组 [开始时间, 结束时间]
|
package/lib/datetime.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import
|
|
1
|
+
import dayjs from"dayjs";import dayOfYear from"dayjs/plugin/dayOfYear";dayjs.extend(dayOfYear);const getDayOfYear=(r=new Date)=>{if(r)return dayjs(r).dayOfYear()},isWeekday=(r=new Date)=>{let i=dayjs(r).day();return i!==0&&i!==6},useFormatTime=(r=new Date,i=`HH:mm:ss`)=>dayjs(r).format(i),useFormatDate=(r=new Date,i=`YYYY-MM-DD`)=>dayjs(r).format(i),useFormatDateTimeParams=(e,r=`timestamp`,i=`startTime`,a=`endTime`)=>{if(!e)return;let[o,s]=e;return{[r]:void 0,[i]:o,[a]:s}},useFormatDateRange=(r=7,{endTimeType:i,format:a}={endTimeType:`full`,format:`YYYY-MM-DD HH:mm:ss`})=>{let o=dayjs().startOf(`day`).subtract(r-1,`day`),s=i===`full`?dayjs().endOf(`day`):dayjs();return[o.format(a),s.format(a)]};export{getDayOfYear,isWeekday,useFormatDate,useFormatDateRange,useFormatDateTimeParams,useFormatTime};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@semi-kit/utils",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.2",
|
|
4
4
|
"description": "General-purpose tool function library",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -19,6 +19,7 @@
|
|
|
19
19
|
"./_utils/local": "./lib/_utils/local.mjs",
|
|
20
20
|
"./axios": "./lib/axios.mjs",
|
|
21
21
|
"./color": "./lib/color.mjs",
|
|
22
|
+
"./date-picker": "./lib/date-picker.mjs",
|
|
22
23
|
"./datetime": "./lib/datetime.mjs",
|
|
23
24
|
"./device": "./lib/device.mjs",
|
|
24
25
|
"./extra": "./lib/extra.mjs",
|
|
@@ -47,7 +48,8 @@
|
|
|
47
48
|
"axios": "catalog:",
|
|
48
49
|
"naive-ui": "catalog:",
|
|
49
50
|
"es-toolkit": "catalog:",
|
|
50
|
-
"vue": "catalog:"
|
|
51
|
+
"vue": "catalog:",
|
|
52
|
+
"dayjs": "catalog:"
|
|
51
53
|
},
|
|
52
54
|
"peerDependencies": {
|
|
53
55
|
"@vueuse/core": "*",
|
|
@@ -57,9 +59,13 @@
|
|
|
57
59
|
"es-toolkit": "*",
|
|
58
60
|
"@semi-kit/component": "*",
|
|
59
61
|
"naive-ui": "*",
|
|
60
|
-
"vue": "*"
|
|
62
|
+
"vue": "*",
|
|
63
|
+
"dayjs": "*"
|
|
61
64
|
},
|
|
62
65
|
"peerDependenciesMeta": {
|
|
66
|
+
"dayjs": {
|
|
67
|
+
"optional": true
|
|
68
|
+
},
|
|
63
69
|
"vue": {
|
|
64
70
|
"optional": true
|
|
65
71
|
},
|