zmdms-utils 0.0.23 → 0.0.25
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/common.js +17 -2
- package/dist/es/parseTime.js +10 -9
- package/dist/es/src/parseTimeTest.js +13 -2
- package/package.json +1 -1
- package/src/common.ts +16 -0
- package/src/parseTime.ts +12 -13
- package/src/parseTimeTest.js +13 -2
package/dist/es/common.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { __assign } from './_virtual/_tslib.js';
|
|
1
2
|
import mitt from './node_modules/mitt/dist/mitt.js';
|
|
2
3
|
|
|
3
|
-
// 基础函数
|
|
4
4
|
/**
|
|
5
5
|
* 同步阻断
|
|
6
6
|
* @param time 秒
|
|
@@ -210,5 +210,20 @@ function isImageExtension(extension) {
|
|
|
210
210
|
function isNonEmpty(number) {
|
|
211
211
|
return number !== null && number !== undefined;
|
|
212
212
|
}
|
|
213
|
+
/**
|
|
214
|
+
* 遍历一个对象,将值是数组的项,用逗号拼接起来
|
|
215
|
+
*/
|
|
216
|
+
function parseJoin(params) {
|
|
217
|
+
if (params) {
|
|
218
|
+
var newParams = __assign({}, params);
|
|
219
|
+
for (var key in newParams) {
|
|
220
|
+
if (Array.isArray(newParams[key])) {
|
|
221
|
+
newParams[key] = newParams[key].join(",");
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
return newParams;
|
|
225
|
+
}
|
|
226
|
+
return params;
|
|
227
|
+
}
|
|
213
228
|
|
|
214
|
-
export { addThousedSeparator, copyToClipboard, dangerouslyXss, delay, emitter, getFileExtension, isImageExtension, isNonEmpty, parseQueryParams, specialString, unescapeString };
|
|
229
|
+
export { addThousedSeparator, copyToClipboard, dangerouslyXss, delay, emitter, getFileExtension, isImageExtension, isNonEmpty, parseJoin, parseQueryParams, specialString, unescapeString };
|
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. 从一个键 转成 一个键
|
|
@@ -55,12 +56,12 @@ function parseTime(config) {
|
|
|
55
56
|
endEndType = endTypeItem[1];
|
|
56
57
|
}
|
|
57
58
|
newParams_1[toKey1] = getParseResult({
|
|
58
|
-
value: newParams_1[fromKey],
|
|
59
|
+
value: (_a = newParams_1[fromKey]) === null || _a === void 0 ? void 0 : _a[0],
|
|
59
60
|
index: index,
|
|
60
61
|
endType: startEndType,
|
|
61
62
|
});
|
|
62
63
|
newParams_1[toKey2] = getParseResult({
|
|
63
|
-
value: newParams_1[fromKey],
|
|
64
|
+
value: (_b = newParams_1[fromKey]) === null || _b === void 0 ? void 0 : _b[1],
|
|
64
65
|
index: index,
|
|
65
66
|
endType: endEndType,
|
|
66
67
|
});
|
|
@@ -134,7 +135,7 @@ function parseTime(config) {
|
|
|
134
135
|
function parseByResult(option) {
|
|
135
136
|
var _a = option.format, format = _a === void 0 ? defaultFormat : _a, _b = option.type, type = _b === void 0 ? "string" : _b;
|
|
136
137
|
return function (option) {
|
|
137
|
-
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;
|
|
138
139
|
if (!value) {
|
|
139
140
|
return undefined;
|
|
140
141
|
}
|
|
@@ -144,14 +145,14 @@ function parseByResult(option) {
|
|
|
144
145
|
if (parseType === "string") {
|
|
145
146
|
var dayjsValue = dayjs.isDayjs(value) ? value : dayjs(value);
|
|
146
147
|
if (parseEndType === "startOf") {
|
|
147
|
-
return dayjsValue
|
|
148
|
-
|
|
149
|
-
|
|
148
|
+
return dayjsValue.startOf("day").format(
|
|
149
|
+
// parseFormat.length === 10 ? `${parseFormat} HH:mm:ss` : parseFormat
|
|
150
|
+
parseFormat);
|
|
150
151
|
}
|
|
151
152
|
if (parseEndType === "endOf") {
|
|
152
|
-
return dayjsValue
|
|
153
|
-
|
|
154
|
-
|
|
153
|
+
return dayjsValue.endOf("day").format(
|
|
154
|
+
// parseFormat.length === 10 ? `${parseFormat} HH:mm:ss` : parseFormat
|
|
155
|
+
parseFormat);
|
|
155
156
|
}
|
|
156
157
|
return dayjsValue.format(parseFormat);
|
|
157
158
|
}
|
|
@@ -53,12 +53,12 @@ function parseTime(config) {
|
|
|
53
53
|
endEndType = endTypeItem[1];
|
|
54
54
|
}
|
|
55
55
|
newParams[toKey1] = getParseResult({
|
|
56
|
-
value: newParams[fromKey],
|
|
56
|
+
value: newParams[fromKey]?.[0],
|
|
57
57
|
index,
|
|
58
58
|
endType: startEndType,
|
|
59
59
|
});
|
|
60
60
|
newParams[toKey2] = getParseResult({
|
|
61
|
-
value: newParams[fromKey],
|
|
61
|
+
value: newParams[fromKey]?.[1],
|
|
62
62
|
index,
|
|
63
63
|
endType: endEndType,
|
|
64
64
|
});
|
|
@@ -241,4 +241,15 @@ console.log(
|
|
|
241
241
|
["startOf", "startOf"],
|
|
242
242
|
],
|
|
243
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
|
+
})
|
|
244
255
|
);
|
package/package.json
CHANGED
package/src/common.ts
CHANGED
|
@@ -220,3 +220,19 @@ export function isImageExtension(extension: string): boolean {
|
|
|
220
220
|
export function isNonEmpty(number: any) {
|
|
221
221
|
return number !== null && number !== undefined;
|
|
222
222
|
}
|
|
223
|
+
|
|
224
|
+
/**
|
|
225
|
+
* 遍历一个对象,将值是数组的项,用逗号拼接起来
|
|
226
|
+
*/
|
|
227
|
+
export function parseJoin(params?: any) {
|
|
228
|
+
if (params) {
|
|
229
|
+
let newParams: any = { ...params };
|
|
230
|
+
for (let key in newParams) {
|
|
231
|
+
if (Array.isArray(newParams[key])) {
|
|
232
|
+
newParams[key] = newParams[key].join(",");
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
return newParams;
|
|
236
|
+
}
|
|
237
|
+
return params;
|
|
238
|
+
}
|
package/src/parseTime.ts
CHANGED
|
@@ -82,12 +82,12 @@ export default function parseTime(config: IConfig) {
|
|
|
82
82
|
endEndType = endTypeItem[1];
|
|
83
83
|
}
|
|
84
84
|
newParams[toKey1] = getParseResult({
|
|
85
|
-
value: newParams[fromKey],
|
|
85
|
+
value: newParams[fromKey]?.[0],
|
|
86
86
|
index,
|
|
87
87
|
endType: startEndType,
|
|
88
88
|
});
|
|
89
89
|
newParams[toKey2] = getParseResult({
|
|
90
|
-
value: newParams[fromKey],
|
|
90
|
+
value: newParams[fromKey]?.[1],
|
|
91
91
|
index,
|
|
92
92
|
endType: endEndType,
|
|
93
93
|
});
|
|
@@ -168,12 +168,13 @@ interface IResultProps {
|
|
|
168
168
|
value?: any;
|
|
169
169
|
index?: number;
|
|
170
170
|
endType?: IEndType | IEndType[];
|
|
171
|
+
formatType?: string;
|
|
171
172
|
}
|
|
172
173
|
function parseByResult(option: IProps) {
|
|
173
174
|
const { format = defaultFormat, type = "string" } = option;
|
|
174
175
|
|
|
175
176
|
return (option: IResultProps) => {
|
|
176
|
-
const { value, index = 0, endType } = option;
|
|
177
|
+
const { value, index = 0, endType, formatType } = option;
|
|
177
178
|
if (!value) {
|
|
178
179
|
return undefined;
|
|
179
180
|
}
|
|
@@ -183,18 +184,16 @@ function parseByResult(option: IProps) {
|
|
|
183
184
|
if (parseType === "string") {
|
|
184
185
|
const dayjsValue = dayjs.isDayjs(value) ? value : dayjs(value);
|
|
185
186
|
if (parseEndType === "startOf") {
|
|
186
|
-
return dayjsValue
|
|
187
|
-
.
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
);
|
|
187
|
+
return dayjsValue.startOf("day").format(
|
|
188
|
+
// parseFormat.length === 10 ? `${parseFormat} HH:mm:ss` : parseFormat
|
|
189
|
+
parseFormat
|
|
190
|
+
);
|
|
191
191
|
}
|
|
192
192
|
if (parseEndType === "endOf") {
|
|
193
|
-
return dayjsValue
|
|
194
|
-
.
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
);
|
|
193
|
+
return dayjsValue.endOf("day").format(
|
|
194
|
+
// parseFormat.length === 10 ? `${parseFormat} HH:mm:ss` : parseFormat
|
|
195
|
+
parseFormat
|
|
196
|
+
);
|
|
198
197
|
}
|
|
199
198
|
return dayjsValue.format(parseFormat);
|
|
200
199
|
} else {
|
package/src/parseTimeTest.js
CHANGED
|
@@ -51,12 +51,12 @@ function parseTime(config) {
|
|
|
51
51
|
endEndType = endTypeItem[1];
|
|
52
52
|
}
|
|
53
53
|
newParams[toKey1] = getParseResult({
|
|
54
|
-
value: newParams[fromKey],
|
|
54
|
+
value: newParams[fromKey]?.[0],
|
|
55
55
|
index,
|
|
56
56
|
endType: startEndType,
|
|
57
57
|
});
|
|
58
58
|
newParams[toKey2] = getParseResult({
|
|
59
|
-
value: newParams[fromKey],
|
|
59
|
+
value: newParams[fromKey]?.[1],
|
|
60
60
|
index,
|
|
61
61
|
endType: endEndType,
|
|
62
62
|
});
|
|
@@ -240,3 +240,14 @@ console.log(
|
|
|
240
240
|
],
|
|
241
241
|
})
|
|
242
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
|
+
);
|