zmdms-utils 0.0.22 → 0.0.24
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/dist/es/parseTime.js +25 -10
- package/dist/es/src/parseTimeTest.js +34 -9
- package/package.json +1 -1
- package/src/parseTime.ts +25 -10
- package/src/parseTimeTest.js +34 -9
package/dist/es/parseTime.js
CHANGED
|
@@ -30,6 +30,7 @@ function parseTime(config) {
|
|
|
30
30
|
// 浅拷贝一下
|
|
31
31
|
var newParams_1 = Object.assign({}, params);
|
|
32
32
|
fromKeys.forEach(function (fromKey, index) {
|
|
33
|
+
var _a, _b;
|
|
33
34
|
var toKey = toKeys[index];
|
|
34
35
|
var endTypeItem = Array.isArray(endType) ? endType[index] : endType;
|
|
35
36
|
// 1. 从一个键 转成 一个键
|
|
@@ -39,8 +40,10 @@ function parseTime(config) {
|
|
|
39
40
|
index: index,
|
|
40
41
|
endType: endTypeItem,
|
|
41
42
|
});
|
|
42
|
-
|
|
43
|
-
|
|
43
|
+
if (fromKey !== toKey) {
|
|
44
|
+
// 删除原有key
|
|
45
|
+
Reflect.deleteProperty(newParams_1, fromKey);
|
|
46
|
+
}
|
|
44
47
|
}
|
|
45
48
|
// 2. 从一个键 转成 两个键
|
|
46
49
|
if (typeof fromKey === "string" && typeof toKey === "object") {
|
|
@@ -53,16 +56,18 @@ function parseTime(config) {
|
|
|
53
56
|
endEndType = endTypeItem[1];
|
|
54
57
|
}
|
|
55
58
|
newParams_1[toKey1] = getParseResult({
|
|
56
|
-
value: newParams_1[fromKey],
|
|
59
|
+
value: (_a = newParams_1[fromKey]) === null || _a === void 0 ? void 0 : _a[0],
|
|
57
60
|
index: index,
|
|
58
61
|
endType: startEndType,
|
|
59
62
|
});
|
|
60
63
|
newParams_1[toKey2] = getParseResult({
|
|
61
|
-
value: newParams_1[fromKey],
|
|
64
|
+
value: (_b = newParams_1[fromKey]) === null || _b === void 0 ? void 0 : _b[1],
|
|
62
65
|
index: index,
|
|
63
66
|
endType: endEndType,
|
|
64
67
|
});
|
|
65
|
-
|
|
68
|
+
if (fromKey !== toKey1 && fromKey !== toKey2) {
|
|
69
|
+
Reflect.deleteProperty(newParams_1, fromKey);
|
|
70
|
+
}
|
|
66
71
|
}
|
|
67
72
|
// 3. 从两个键 转成 一个键
|
|
68
73
|
if (typeof fromKey === "object" && typeof toKey === "string") {
|
|
@@ -86,8 +91,12 @@ function parseTime(config) {
|
|
|
86
91
|
endType: endEndType,
|
|
87
92
|
}),
|
|
88
93
|
];
|
|
89
|
-
|
|
90
|
-
|
|
94
|
+
if (fromKey1 !== toKey) {
|
|
95
|
+
Reflect.deleteProperty(newParams_1, fromKey1);
|
|
96
|
+
}
|
|
97
|
+
if (fromtKey2 !== toKey) {
|
|
98
|
+
Reflect.deleteProperty(newParams_1, fromtKey2);
|
|
99
|
+
}
|
|
91
100
|
}
|
|
92
101
|
// 4. 从两个键 转成 两个键
|
|
93
102
|
if (typeof fromKey === "object" && typeof toKey === "object") {
|
|
@@ -110,8 +119,14 @@ function parseTime(config) {
|
|
|
110
119
|
index: index,
|
|
111
120
|
endType: endEndType,
|
|
112
121
|
});
|
|
113
|
-
|
|
114
|
-
|
|
122
|
+
if (fromKey1 !== toKey1) {
|
|
123
|
+
// 删除原有key
|
|
124
|
+
Reflect.deleteProperty(newParams_1, fromKey1);
|
|
125
|
+
}
|
|
126
|
+
if (fromtKey2 !== toKey2) {
|
|
127
|
+
// 删除原有key
|
|
128
|
+
Reflect.deleteProperty(newParams_1, fromtKey2);
|
|
129
|
+
}
|
|
115
130
|
}
|
|
116
131
|
});
|
|
117
132
|
return newParams_1;
|
|
@@ -120,7 +135,7 @@ function parseTime(config) {
|
|
|
120
135
|
function parseByResult(option) {
|
|
121
136
|
var _a = option.format, format = _a === void 0 ? defaultFormat : _a, _b = option.type, type = _b === void 0 ? "string" : _b;
|
|
122
137
|
return function (option) {
|
|
123
|
-
var value = option.value, _a = option.index, index = _a === void 0 ? 0 : _a, endType = option.endType;
|
|
138
|
+
var value = option.value, _a = option.index, index = _a === void 0 ? 0 : _a, endType = option.endType; option.formatType;
|
|
124
139
|
if (!value) {
|
|
125
140
|
return undefined;
|
|
126
141
|
}
|
|
@@ -37,8 +37,10 @@ function parseTime(config) {
|
|
|
37
37
|
index,
|
|
38
38
|
endType: endTypeItem,
|
|
39
39
|
});
|
|
40
|
-
|
|
41
|
-
|
|
40
|
+
if (fromKey !== toKey) {
|
|
41
|
+
// 删除原有key
|
|
42
|
+
Reflect.deleteProperty(newParams, fromKey);
|
|
43
|
+
}
|
|
42
44
|
}
|
|
43
45
|
// 2. 从一个键 转成 两个键
|
|
44
46
|
if (typeof fromKey === "string" && typeof toKey === "object") {
|
|
@@ -51,16 +53,18 @@ function parseTime(config) {
|
|
|
51
53
|
endEndType = endTypeItem[1];
|
|
52
54
|
}
|
|
53
55
|
newParams[toKey1] = getParseResult({
|
|
54
|
-
value: newParams[fromKey],
|
|
56
|
+
value: newParams[fromKey]?.[0],
|
|
55
57
|
index,
|
|
56
58
|
endType: startEndType,
|
|
57
59
|
});
|
|
58
60
|
newParams[toKey2] = getParseResult({
|
|
59
|
-
value: newParams[fromKey],
|
|
61
|
+
value: newParams[fromKey]?.[1],
|
|
60
62
|
index,
|
|
61
63
|
endType: endEndType,
|
|
62
64
|
});
|
|
63
|
-
|
|
65
|
+
if (fromKey !== toKey1 && fromKey !== toKey2) {
|
|
66
|
+
Reflect.deleteProperty(newParams, fromKey);
|
|
67
|
+
}
|
|
64
68
|
}
|
|
65
69
|
// 3. 从两个键 转成 一个键
|
|
66
70
|
if (typeof fromKey === "object" && typeof toKey === "string") {
|
|
@@ -84,8 +88,12 @@ function parseTime(config) {
|
|
|
84
88
|
endType: endEndType,
|
|
85
89
|
}),
|
|
86
90
|
];
|
|
87
|
-
|
|
88
|
-
|
|
91
|
+
if (fromKey1 !== toKey) {
|
|
92
|
+
Reflect.deleteProperty(newParams, fromKey1);
|
|
93
|
+
}
|
|
94
|
+
if (fromtKey2 !== toKey) {
|
|
95
|
+
Reflect.deleteProperty(newParams, fromtKey2);
|
|
96
|
+
}
|
|
89
97
|
}
|
|
90
98
|
// 4. 从两个键 转成 两个键
|
|
91
99
|
if (typeof fromKey === "object" && typeof toKey === "object") {
|
|
@@ -108,8 +116,14 @@ function parseTime(config) {
|
|
|
108
116
|
index,
|
|
109
117
|
endType: endEndType,
|
|
110
118
|
});
|
|
111
|
-
|
|
112
|
-
|
|
119
|
+
if (fromKey1 !== toKey1) {
|
|
120
|
+
// 删除原有key
|
|
121
|
+
Reflect.deleteProperty(newParams, fromKey1);
|
|
122
|
+
}
|
|
123
|
+
if (fromtKey2 !== toKey2) {
|
|
124
|
+
// 删除原有key
|
|
125
|
+
Reflect.deleteProperty(newParams, fromtKey2);
|
|
126
|
+
}
|
|
113
127
|
}
|
|
114
128
|
});
|
|
115
129
|
|
|
@@ -227,4 +241,15 @@ console.log(
|
|
|
227
241
|
["startOf", "startOf"],
|
|
228
242
|
],
|
|
229
243
|
})
|
|
244
|
+
);
|
|
245
|
+
console.log(
|
|
246
|
+
parseTime({
|
|
247
|
+
params: {
|
|
248
|
+
time: [dayjs(), dayjs()],
|
|
249
|
+
timea: dayjs(),
|
|
250
|
+
},
|
|
251
|
+
fromKeys: ["time", "timea"],
|
|
252
|
+
toKeys: [["time1", "time2"], "timea"],
|
|
253
|
+
format: ["YYYY-MM-DD", "YYYY-MM-DD HH:mm:ss"],
|
|
254
|
+
})
|
|
230
255
|
);
|
package/package.json
CHANGED
package/src/parseTime.ts
CHANGED
|
@@ -66,8 +66,10 @@ export default function parseTime(config: IConfig) {
|
|
|
66
66
|
index,
|
|
67
67
|
endType: endTypeItem,
|
|
68
68
|
});
|
|
69
|
-
|
|
70
|
-
|
|
69
|
+
if (fromKey !== toKey) {
|
|
70
|
+
// 删除原有key
|
|
71
|
+
Reflect.deleteProperty(newParams, fromKey);
|
|
72
|
+
}
|
|
71
73
|
}
|
|
72
74
|
// 2. 从一个键 转成 两个键
|
|
73
75
|
if (typeof fromKey === "string" && typeof toKey === "object") {
|
|
@@ -80,16 +82,18 @@ export default function parseTime(config: IConfig) {
|
|
|
80
82
|
endEndType = endTypeItem[1];
|
|
81
83
|
}
|
|
82
84
|
newParams[toKey1] = getParseResult({
|
|
83
|
-
value: newParams[fromKey],
|
|
85
|
+
value: newParams[fromKey]?.[0],
|
|
84
86
|
index,
|
|
85
87
|
endType: startEndType,
|
|
86
88
|
});
|
|
87
89
|
newParams[toKey2] = getParseResult({
|
|
88
|
-
value: newParams[fromKey],
|
|
90
|
+
value: newParams[fromKey]?.[1],
|
|
89
91
|
index,
|
|
90
92
|
endType: endEndType,
|
|
91
93
|
});
|
|
92
|
-
|
|
94
|
+
if (fromKey !== toKey1 && fromKey !== toKey2) {
|
|
95
|
+
Reflect.deleteProperty(newParams, fromKey);
|
|
96
|
+
}
|
|
93
97
|
}
|
|
94
98
|
// 3. 从两个键 转成 一个键
|
|
95
99
|
if (typeof fromKey === "object" && typeof toKey === "string") {
|
|
@@ -113,8 +117,12 @@ export default function parseTime(config: IConfig) {
|
|
|
113
117
|
endType: endEndType,
|
|
114
118
|
}),
|
|
115
119
|
];
|
|
116
|
-
|
|
117
|
-
|
|
120
|
+
if (fromKey1 !== toKey) {
|
|
121
|
+
Reflect.deleteProperty(newParams, fromKey1);
|
|
122
|
+
}
|
|
123
|
+
if (fromtKey2 !== toKey) {
|
|
124
|
+
Reflect.deleteProperty(newParams, fromtKey2);
|
|
125
|
+
}
|
|
118
126
|
}
|
|
119
127
|
// 4. 从两个键 转成 两个键
|
|
120
128
|
if (typeof fromKey === "object" && typeof toKey === "object") {
|
|
@@ -137,8 +145,14 @@ export default function parseTime(config: IConfig) {
|
|
|
137
145
|
index,
|
|
138
146
|
endType: endEndType,
|
|
139
147
|
});
|
|
140
|
-
|
|
141
|
-
|
|
148
|
+
if (fromKey1 !== toKey1) {
|
|
149
|
+
// 删除原有key
|
|
150
|
+
Reflect.deleteProperty(newParams, fromKey1);
|
|
151
|
+
}
|
|
152
|
+
if (fromtKey2 !== toKey2) {
|
|
153
|
+
// 删除原有key
|
|
154
|
+
Reflect.deleteProperty(newParams, fromtKey2);
|
|
155
|
+
}
|
|
142
156
|
}
|
|
143
157
|
});
|
|
144
158
|
|
|
@@ -154,12 +168,13 @@ interface IResultProps {
|
|
|
154
168
|
value?: any;
|
|
155
169
|
index?: number;
|
|
156
170
|
endType?: IEndType | IEndType[];
|
|
171
|
+
formatType?: string;
|
|
157
172
|
}
|
|
158
173
|
function parseByResult(option: IProps) {
|
|
159
174
|
const { format = defaultFormat, type = "string" } = option;
|
|
160
175
|
|
|
161
176
|
return (option: IResultProps) => {
|
|
162
|
-
const { value, index = 0, endType } = option;
|
|
177
|
+
const { value, index = 0, endType, formatType } = option;
|
|
163
178
|
if (!value) {
|
|
164
179
|
return undefined;
|
|
165
180
|
}
|
package/src/parseTimeTest.js
CHANGED
|
@@ -35,8 +35,10 @@ function parseTime(config) {
|
|
|
35
35
|
index,
|
|
36
36
|
endType: endTypeItem,
|
|
37
37
|
});
|
|
38
|
-
|
|
39
|
-
|
|
38
|
+
if (fromKey !== toKey) {
|
|
39
|
+
// 删除原有key
|
|
40
|
+
Reflect.deleteProperty(newParams, fromKey);
|
|
41
|
+
}
|
|
40
42
|
}
|
|
41
43
|
// 2. 从一个键 转成 两个键
|
|
42
44
|
if (typeof fromKey === "string" && typeof toKey === "object") {
|
|
@@ -49,16 +51,18 @@ function parseTime(config) {
|
|
|
49
51
|
endEndType = endTypeItem[1];
|
|
50
52
|
}
|
|
51
53
|
newParams[toKey1] = getParseResult({
|
|
52
|
-
value: newParams[fromKey],
|
|
54
|
+
value: newParams[fromKey]?.[0],
|
|
53
55
|
index,
|
|
54
56
|
endType: startEndType,
|
|
55
57
|
});
|
|
56
58
|
newParams[toKey2] = getParseResult({
|
|
57
|
-
value: newParams[fromKey],
|
|
59
|
+
value: newParams[fromKey]?.[1],
|
|
58
60
|
index,
|
|
59
61
|
endType: endEndType,
|
|
60
62
|
});
|
|
61
|
-
|
|
63
|
+
if (fromKey !== toKey1 && fromKey !== toKey2) {
|
|
64
|
+
Reflect.deleteProperty(newParams, fromKey);
|
|
65
|
+
}
|
|
62
66
|
}
|
|
63
67
|
// 3. 从两个键 转成 一个键
|
|
64
68
|
if (typeof fromKey === "object" && typeof toKey === "string") {
|
|
@@ -82,8 +86,12 @@ function parseTime(config) {
|
|
|
82
86
|
endType: endEndType,
|
|
83
87
|
}),
|
|
84
88
|
];
|
|
85
|
-
|
|
86
|
-
|
|
89
|
+
if (fromKey1 !== toKey) {
|
|
90
|
+
Reflect.deleteProperty(newParams, fromKey1);
|
|
91
|
+
}
|
|
92
|
+
if (fromtKey2 !== toKey) {
|
|
93
|
+
Reflect.deleteProperty(newParams, fromtKey2);
|
|
94
|
+
}
|
|
87
95
|
}
|
|
88
96
|
// 4. 从两个键 转成 两个键
|
|
89
97
|
if (typeof fromKey === "object" && typeof toKey === "object") {
|
|
@@ -106,8 +114,14 @@ function parseTime(config) {
|
|
|
106
114
|
index,
|
|
107
115
|
endType: endEndType,
|
|
108
116
|
});
|
|
109
|
-
|
|
110
|
-
|
|
117
|
+
if (fromKey1 !== toKey1) {
|
|
118
|
+
// 删除原有key
|
|
119
|
+
Reflect.deleteProperty(newParams, fromKey1);
|
|
120
|
+
}
|
|
121
|
+
if (fromtKey2 !== toKey2) {
|
|
122
|
+
// 删除原有key
|
|
123
|
+
Reflect.deleteProperty(newParams, fromtKey2);
|
|
124
|
+
}
|
|
111
125
|
}
|
|
112
126
|
});
|
|
113
127
|
|
|
@@ -226,3 +240,14 @@ console.log(
|
|
|
226
240
|
],
|
|
227
241
|
})
|
|
228
242
|
);
|
|
243
|
+
console.log(
|
|
244
|
+
parseTime({
|
|
245
|
+
params: {
|
|
246
|
+
time: [dayjs(), dayjs()],
|
|
247
|
+
timea: dayjs(),
|
|
248
|
+
},
|
|
249
|
+
fromKeys: ["time", "timea"],
|
|
250
|
+
toKeys: [["time1", "time2"], "timea"],
|
|
251
|
+
format: ["YYYY-MM-DD", "YYYY-MM-DD HH:mm:ss"],
|
|
252
|
+
})
|
|
253
|
+
);
|