@fileverse-dev/fortune-core 1.3.5-hyper-2 → 1.3.6
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/es/canvas.js +1 -1
- package/es/events/paste.js +30 -13
- package/es/modules/cell.js +8 -6
- package/es/modules/format.js +29 -38
- package/es/modules/ssf.js +1 -1
- package/es/modules/toolbar.js +32 -11
- package/es/modules/validation.d.ts +10 -0
- package/es/modules/validation.js +283 -20
- package/es/paste-table-helpers.js +11 -11
- package/lib/canvas.js +1 -1
- package/lib/events/paste.js +28 -11
- package/lib/modules/cell.js +8 -6
- package/lib/modules/format.js +28 -37
- package/lib/modules/ssf.js +1 -1
- package/lib/modules/toolbar.js +31 -10
- package/lib/modules/validation.d.ts +10 -0
- package/lib/modules/validation.js +284 -20
- package/lib/paste-table-helpers.js +11 -11
- package/package.json +1 -1
package/es/canvas.js
CHANGED
|
@@ -1012,7 +1012,7 @@ var Canvas = function () {
|
|
|
1012
1012
|
renderCtx.clip();
|
|
1013
1013
|
renderCtx.scale(this.sheetCtx.zoomRatio, this.sheetCtx.zoomRatio);
|
|
1014
1014
|
var measureText = getMeasureText(value, renderCtx, this.sheetCtx);
|
|
1015
|
-
var textMetrics = measureText.width +
|
|
1015
|
+
var textMetrics = measureText.width + 18;
|
|
1016
1016
|
var oneLineTextHeight = measureText.actualBoundingBoxDescent + measureText.actualBoundingBoxAscent;
|
|
1017
1017
|
var horizonAlignPos = pos_x + space_width;
|
|
1018
1018
|
if (horizonAlign === 0) {
|
package/es/events/paste.js
CHANGED
|
@@ -34,10 +34,10 @@ import { handlePastedTable } from "../paste-table-helpers";
|
|
|
34
34
|
import { getFlowdata } from "../context";
|
|
35
35
|
import { execfunction } from "../modules/formula";
|
|
36
36
|
import { getdatabyselection } from "../modules/cell";
|
|
37
|
-
import {
|
|
37
|
+
import { update, datenum_local } from "../modules/format";
|
|
38
38
|
import { normalizeSelection, selectionCache } from "../modules/selection";
|
|
39
39
|
import { getSheetIndex, isAllowEdit } from "../utils";
|
|
40
|
-
import { hasPartMC, isRealNum } from "../modules/validation";
|
|
40
|
+
import { hasPartMC, isRealNum, detectDateFormat } from "../modules/validation";
|
|
41
41
|
import { getBorderInfoCompute } from "../modules/border";
|
|
42
42
|
import { expandRowsAndColumns, storeSheetParamALL } from "../modules/sheet";
|
|
43
43
|
import { jfrefreshgrid } from "../modules/refresh";
|
|
@@ -207,14 +207,13 @@ var handleFormulaOnPaste = function handleFormulaOnPaste(ctx, d) {
|
|
|
207
207
|
}
|
|
208
208
|
};
|
|
209
209
|
function pasteHandler(ctx, data, borderInfo) {
|
|
210
|
-
var _a;
|
|
211
|
-
var _b, _c, _d, _e, _f, _g;
|
|
210
|
+
var _a, _b, _c, _d, _e, _f;
|
|
212
211
|
if (ctx.luckysheet_selection_range) {
|
|
213
212
|
ctx.luckysheet_selection_range = [];
|
|
214
213
|
}
|
|
215
214
|
var allowEdit = isAllowEdit(ctx);
|
|
216
215
|
if (!allowEdit || ctx.isFlvReadOnly) return;
|
|
217
|
-
if (((
|
|
216
|
+
if (((_b = (_a = ctx.luckysheet_select_save) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0) !== 1) {
|
|
218
217
|
return;
|
|
219
218
|
}
|
|
220
219
|
if (_typeof(data) === "object") {
|
|
@@ -263,7 +262,7 @@ function pasteHandler(ctx, data, borderInfo) {
|
|
|
263
262
|
currentRowLen = cfg.rowlen[h];
|
|
264
263
|
}
|
|
265
264
|
for (var c = minc; c <= maxc; c += 1) {
|
|
266
|
-
if ((
|
|
265
|
+
if ((_c = x === null || x === void 0 ? void 0 : x[c]) === null || _c === void 0 ? void 0 : _c.mc) {
|
|
267
266
|
if ("rs" in x[c].mc) {
|
|
268
267
|
delete cfg.merge["".concat(x[c].mc.r, "_").concat(x[c].mc.c)];
|
|
269
268
|
}
|
|
@@ -274,7 +273,7 @@ function pasteHandler(ctx, data, borderInfo) {
|
|
|
274
273
|
value = data[h - minh][c - minc];
|
|
275
274
|
}
|
|
276
275
|
x[c] = value;
|
|
277
|
-
if (value != null && ((
|
|
276
|
+
if (value != null && ((_d = x === null || x === void 0 ? void 0 : x[c]) === null || _d === void 0 ? void 0 : _d.mc)) {
|
|
278
277
|
if (x[c].mc.rs != null) {
|
|
279
278
|
x[c].mc.r = h;
|
|
280
279
|
x[c].mc.c = c;
|
|
@@ -301,7 +300,7 @@ function pasteHandler(ctx, data, borderInfo) {
|
|
|
301
300
|
b: borderInfo["".concat(h - minh, "_").concat(c - minc)].b
|
|
302
301
|
}
|
|
303
302
|
};
|
|
304
|
-
(
|
|
303
|
+
(_e = cfg.borderInfo) === null || _e === void 0 ? void 0 : _e.push(bd_obj);
|
|
305
304
|
}
|
|
306
305
|
}
|
|
307
306
|
d[h] = x;
|
|
@@ -333,7 +332,7 @@ function pasteHandler(ctx, data, borderInfo) {
|
|
|
333
332
|
}
|
|
334
333
|
var d = getFlowdata(ctx);
|
|
335
334
|
if (!d) return;
|
|
336
|
-
var last = (
|
|
335
|
+
var last = (_f = ctx.luckysheet_select_save) === null || _f === void 0 ? void 0 : _f[ctx.luckysheet_select_save.length - 1];
|
|
337
336
|
if (!last) return;
|
|
338
337
|
var curR = last.row == null ? 0 : last.row[0];
|
|
339
338
|
var curC = last.column == null ? 0 : last.column[0];
|
|
@@ -374,9 +373,23 @@ function pasteHandler(ctx, data, borderInfo) {
|
|
|
374
373
|
}
|
|
375
374
|
}
|
|
376
375
|
if (originCell) {
|
|
377
|
-
originCell.
|
|
376
|
+
if (originCell.ct && originCell.ct.t === "d" && !isUrl) {
|
|
377
|
+
var df = detectDateFormat(originalValueStr);
|
|
378
|
+
if (df) {
|
|
379
|
+
var dateObj = new Date(df.year, df.month - 1, df.day, df.hours, df.minutes, df.seconds);
|
|
380
|
+
originCell.v = datenum_local(dateObj);
|
|
381
|
+
} else {
|
|
382
|
+
originCell.v = originalValueStr;
|
|
383
|
+
}
|
|
384
|
+
} else {
|
|
385
|
+
originCell.v = isUrl ? originalValueStr : value;
|
|
386
|
+
}
|
|
378
387
|
if (originCell.ct != null && originCell.ct.fa != null) {
|
|
379
|
-
|
|
388
|
+
if (originCell.ct.t === "d" && typeof originCell.v !== "number") {
|
|
389
|
+
originCell.m = String(originCell.v);
|
|
390
|
+
} else {
|
|
391
|
+
originCell.m = update(originCell.ct.fa, originCell.v);
|
|
392
|
+
}
|
|
380
393
|
} else {
|
|
381
394
|
originCell.m = typeof originCell.v === "boolean" ? String(originCell.v) : originCell.v;
|
|
382
395
|
}
|
|
@@ -405,8 +418,12 @@ function pasteHandler(ctx, data, borderInfo) {
|
|
|
405
418
|
t: "s"
|
|
406
419
|
};
|
|
407
420
|
} else {
|
|
408
|
-
|
|
409
|
-
|
|
421
|
+
cell.v = originalValueStr;
|
|
422
|
+
cell.m = originalValueStr;
|
|
423
|
+
cell.ct = {
|
|
424
|
+
fa: "General",
|
|
425
|
+
t: "g"
|
|
426
|
+
};
|
|
410
427
|
if (/^0x?[a-fA-F0-9]+$/.test(value)) {
|
|
411
428
|
cell.m = value;
|
|
412
429
|
cell.ct = {
|
package/es/modules/cell.js
CHANGED
|
@@ -110,7 +110,7 @@ export function getCellValue(r, c, data, attr) {
|
|
|
110
110
|
return retv;
|
|
111
111
|
}
|
|
112
112
|
export function setCellValue(ctx, r, c, d, v) {
|
|
113
|
-
var _a, _b, _c, _d, _e, _f, _g
|
|
113
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
114
114
|
if (ctx.allowEdit === false || ctx.isFlvReadOnly) return;
|
|
115
115
|
if (_.isNil(d)) {
|
|
116
116
|
d = getFlowdata(ctx);
|
|
@@ -276,10 +276,7 @@ export function setCellValue(ctx, r, c, d, v) {
|
|
|
276
276
|
} else if (!_.isNil(cell.ct) && !_.isNil(cell.ct.fa) && cell.ct.fa !== "General") {
|
|
277
277
|
var fa = cell.ct.fa;
|
|
278
278
|
if (isRealNum(vupdate)) {
|
|
279
|
-
if (commaPresent && !fa.includes(",")
|
|
280
|
-
if (fa.includes(",") !== String(vupdate).includes(",")) {
|
|
281
|
-
commaPresent = true;
|
|
282
|
-
}
|
|
279
|
+
if (commaPresent && !fa.includes(",")) {
|
|
283
280
|
fa = getNumberFormat(String(vupdate), commaPresent);
|
|
284
281
|
}
|
|
285
282
|
vupdate = parseFloat(vupdate);
|
|
@@ -289,6 +286,9 @@ export function setCellValue(ctx, r, c, d, v) {
|
|
|
289
286
|
t: "n"
|
|
290
287
|
});
|
|
291
288
|
}
|
|
289
|
+
if (_.isNil(cell.ht)) {
|
|
290
|
+
cell.ht = 2;
|
|
291
|
+
}
|
|
292
292
|
}
|
|
293
293
|
var mask = update(fa, vupdate);
|
|
294
294
|
if (mask === vupdate) {
|
|
@@ -317,7 +317,9 @@ export function setCellValue(ctx, r, c, d, v) {
|
|
|
317
317
|
var strValue = String(vupdate);
|
|
318
318
|
var format = getNumberFormat(strValue, commaPresent);
|
|
319
319
|
cell.m = v.m ? v.m : update(format, cell.v);
|
|
320
|
-
|
|
320
|
+
if (_.isNil(cell.ht)) {
|
|
321
|
+
cell.ht = 2;
|
|
322
|
+
}
|
|
321
323
|
cell.ct = {
|
|
322
324
|
fa: format,
|
|
323
325
|
t: "n"
|
package/es/modules/format.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import numeral from "numeral";
|
|
2
2
|
import _ from "lodash";
|
|
3
|
-
import { isRealNum, valueIsError,
|
|
3
|
+
import { isRealNum, valueIsError, detectDateFormat } from "./validation";
|
|
4
4
|
import SSF from "./ssf";
|
|
5
5
|
import { getCellValue } from "./cell";
|
|
6
6
|
var base1904 = new Date(1900, 2, 1, 0, 0, 0);
|
|
@@ -10,29 +10,6 @@ export function datenum_local(v, date1904) {
|
|
|
10
10
|
if (date1904) epoch -= 1461 * 24 * 60 * 60 * 1000;else if (v >= base1904) epoch += 24 * 60 * 60 * 1000;
|
|
11
11
|
return (epoch - dnthresh_utc) / (24 * 60 * 60 * 1000);
|
|
12
12
|
}
|
|
13
|
-
var good_pd_date = new Date("2017-02-19T19:06:09.000Z");
|
|
14
|
-
if (Number.isNaN(good_pd_date.getFullYear())) good_pd_date = new Date("2/19/17");
|
|
15
|
-
var good_pd = good_pd_date.getFullYear() === 2017;
|
|
16
|
-
function parseDate(str, fixdate) {
|
|
17
|
-
var d = new Date(str);
|
|
18
|
-
if (good_pd) {
|
|
19
|
-
if (!_.isNil(fixdate)) {
|
|
20
|
-
if (fixdate > 0) d.setTime(d.getTime() + d.getTimezoneOffset() * 60 * 1000);else if (fixdate < 0) d.setTime(d.getTime() - d.getTimezoneOffset() * 60 * 1000);
|
|
21
|
-
}
|
|
22
|
-
return d;
|
|
23
|
-
}
|
|
24
|
-
if (str instanceof Date) return str;
|
|
25
|
-
if (good_pd_date.getFullYear() === 1917 && !Number.isNaN(d.getFullYear())) {
|
|
26
|
-
var s = d.getFullYear();
|
|
27
|
-
if (str.indexOf("".concat(s)) > -1) return d;
|
|
28
|
-
d.setFullYear(d.getFullYear() + 100);
|
|
29
|
-
return d;
|
|
30
|
-
}
|
|
31
|
-
var n = str.match(/\d+/g) || ["2017", "2", "19", "0", "0", "0"];
|
|
32
|
-
var out = new Date(+n[0], +n[1] - 1, +n[2], +n[3] || 0, +n[4] || 0, +n[5] || 0);
|
|
33
|
-
if (str.indexOf("Z") > -1) out = new Date(out.getTime() - out.getTimezoneOffset() * 60 * 1000);
|
|
34
|
-
return out;
|
|
35
|
-
}
|
|
36
13
|
export function genarate(value) {
|
|
37
14
|
var m = null;
|
|
38
15
|
var ct = {};
|
|
@@ -256,23 +233,37 @@ export function genarate(value) {
|
|
|
256
233
|
t: "n"
|
|
257
234
|
};
|
|
258
235
|
v = parseFloat(value);
|
|
259
|
-
} else if (
|
|
260
|
-
|
|
261
|
-
if (
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
236
|
+
} else if (typeof value === "string") {
|
|
237
|
+
var df = detectDateFormat(value.toString());
|
|
238
|
+
if (df) {
|
|
239
|
+
var dateObj = new Date(df.year, df.month - 1, df.day, df.hours, df.minutes, df.seconds);
|
|
240
|
+
v = datenum_local(dateObj);
|
|
241
|
+
ct.t = "d";
|
|
242
|
+
var map = {
|
|
243
|
+
"yyyy-MM-dd": "dd/MM/yyyy",
|
|
244
|
+
"yyyy-MM-dd HH:mm": "dd/MM/yyyy",
|
|
245
|
+
"yyyy-MM-ddTHH:mm": "dd/MM/yyyy",
|
|
246
|
+
"yyyy/MM/dd": "dd/MM/yyyy",
|
|
247
|
+
"yyyy/MM/dd HH:mm": "dd/MM/yyyy",
|
|
248
|
+
"yyyy.MM.dd": "yyyy.MM.dd",
|
|
249
|
+
"MM/dd/yyyy h:mm AM/PM": "MM/dd/yyyy h:mm AM/PM",
|
|
250
|
+
"MM/dd/yyyy": "MM/dd/yyyy",
|
|
251
|
+
"M/d/yyyy": "M/d/yyyy",
|
|
252
|
+
"MM/dd/yy": "MM/dd/yy",
|
|
253
|
+
"dd/MM/yyyy": "dd/MM/yyyy",
|
|
254
|
+
"dd-MM-yyyy": "dd/MM/yyyy",
|
|
255
|
+
"dd.MM.yyyy": "dd.MM.yyyy",
|
|
256
|
+
named: "dd/MM/yyyy"
|
|
257
|
+
};
|
|
258
|
+
ct.fa = map[df.formatType] || "dd/MM/yyyy";
|
|
259
|
+
m = SSF.format(ct.fa, v);
|
|
269
260
|
} else {
|
|
270
|
-
|
|
261
|
+
m = value.toString();
|
|
262
|
+
ct.fa = "General";
|
|
263
|
+
ct.t = "g";
|
|
271
264
|
}
|
|
272
|
-
ct.t = "d";
|
|
273
|
-
m = SSF.format(ct.fa, v);
|
|
274
265
|
} else {
|
|
275
|
-
m = value;
|
|
266
|
+
m = value.toString();
|
|
276
267
|
ct.fa = "General";
|
|
277
268
|
ct.t = "g";
|
|
278
269
|
}
|
package/es/modules/ssf.js
CHANGED
|
@@ -1364,7 +1364,7 @@ var make_ssf = function make_ssf(SSF) {
|
|
|
1364
1364
|
if (typeof n !== "number" || !Number.isFinite(n)) return null;
|
|
1365
1365
|
if (!Number.isInteger(n)) return null;
|
|
1366
1366
|
if (n < 0) return null;
|
|
1367
|
-
var minSec =
|
|
1367
|
+
var minSec = 100000; // Excel serial numbers max ~73050 for year 2100; avoids collision
|
|
1368
1368
|
var maxSec = 4102444800; // ~2100-01-01
|
|
1369
1369
|
var minMs = minSec * 1000;
|
|
1370
1370
|
var maxMs = maxSec * 1000;
|
package/es/modules/toolbar.js
CHANGED
|
@@ -4,14 +4,14 @@ import { getFlowdata } from "../context";
|
|
|
4
4
|
import { getSheetIndex, isAllowEdit, getLineCount } from "../utils";
|
|
5
5
|
import { getRangetxt, isAllSelectedCellsInStatus, normalizedAttr, setCellValue } from "./cell";
|
|
6
6
|
import { colors } from "./color";
|
|
7
|
-
import { genarate, is_date, update } from "./format";
|
|
8
7
|
import { getSelectionCharacterOffsets } from "./cursor";
|
|
8
|
+
import { datenum_local, genarate, is_date, update } from "./format";
|
|
9
9
|
import { execfunction, execFunctionGroup, israngeseleciton, rangeSetValue, setCaretPosition, createFormulaRangeSelect } from "./formula";
|
|
10
10
|
import { inlineStyleAffectAttribute, updateInlineStringFormat, updateInlineStringFormatOutside } from "./inline-string";
|
|
11
11
|
import { colLocationByIndex, rowLocationByIndex } from "./location";
|
|
12
12
|
import { normalizeSelection, selectionCopyShow, selectIsOverlap } from "./selection";
|
|
13
13
|
import { sortSelection } from "./sort";
|
|
14
|
-
import { hasPartMC, isdatatypemulti, isRealNull, isRealNum } from "./validation";
|
|
14
|
+
import { detectDateFormat, hasPartMC, isdatatypemulti, isRealNull, isRealNum } from "./validation";
|
|
15
15
|
import { showLinkCard } from "./hyperlink";
|
|
16
16
|
import { cfSplitRange } from "./conditionalFormat";
|
|
17
17
|
import { clearMeasureTextCache, getCellTextInfo } from "./text";
|
|
@@ -34,21 +34,42 @@ export function updateFormatCell(ctx, d, attr, foucsStatus, row_st, row_ed, col_
|
|
|
34
34
|
} else {
|
|
35
35
|
value = cell;
|
|
36
36
|
}
|
|
37
|
+
var type = "n";
|
|
38
|
+
if (is_date(foucsStatus) || foucsStatus === 14 || foucsStatus === 15 || foucsStatus === 16 || foucsStatus === 17 || foucsStatus === 18 || foucsStatus === 19 || foucsStatus === 20 || foucsStatus === 21 || foucsStatus === 22 || foucsStatus === 45 || foucsStatus === 46 || foucsStatus === 47) {
|
|
39
|
+
type = "d";
|
|
40
|
+
} else if (foucsStatus === "@" || foucsStatus === 49) {
|
|
41
|
+
type = "s";
|
|
42
|
+
}
|
|
37
43
|
if (_.isNil(value)) {
|
|
44
|
+
if (!_.isNil(d[r])) {
|
|
45
|
+
if (_.isNil(d[r][c])) {
|
|
46
|
+
d[r][c] = {
|
|
47
|
+
ct: {
|
|
48
|
+
fa: foucsStatus,
|
|
49
|
+
t: type
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
} else if (_.isPlainObject(d[r][c])) {
|
|
53
|
+
if (_.isNil(d[r][c].ct)) d[r][c].ct = {};
|
|
54
|
+
d[r][c].ct.fa = foucsStatus;
|
|
55
|
+
d[r][c].ct.t = type;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
38
58
|
continue;
|
|
39
59
|
}
|
|
40
60
|
if (foucsStatus !== "@" && isRealNum(value)) {
|
|
41
61
|
value = Number(value);
|
|
62
|
+
} else if (type === "d" && typeof value === "string") {
|
|
63
|
+
var dateInfo = detectDateFormat(value);
|
|
64
|
+
if (dateInfo) {
|
|
65
|
+
var dateObj = new Date(dateInfo.year, dateInfo.month - 1, dateInfo.day, dateInfo.hours, dateInfo.minutes, dateInfo.seconds);
|
|
66
|
+
value = datenum_local(dateObj);
|
|
67
|
+
}
|
|
42
68
|
}
|
|
43
|
-
|
|
44
|
-
var type = "n";
|
|
45
|
-
if (is_date(foucsStatus) || foucsStatus === 14 || foucsStatus === 15 || foucsStatus === 16 || foucsStatus === 17 || foucsStatus === 18 || foucsStatus === 19 || foucsStatus === 20 || foucsStatus === 21 || foucsStatus === 22 || foucsStatus === 45 || foucsStatus === 46 || foucsStatus === 47) {
|
|
46
|
-
type = "d";
|
|
47
|
-
} else if (foucsStatus === "@" || foucsStatus === 49) {
|
|
48
|
-
type = "s";
|
|
49
|
-
} else if (foucsStatus === "General" || foucsStatus === 0) {
|
|
69
|
+
if (foucsStatus === "General" || foucsStatus === 0) {
|
|
50
70
|
type = isRealNum(value) ? "n" : "g";
|
|
51
71
|
}
|
|
72
|
+
var mask = update(foucsStatus, value);
|
|
52
73
|
if (cell && _.isPlainObject(cell)) {
|
|
53
74
|
cell.m = "".concat(mask);
|
|
54
75
|
if (_.isNil(cell.ct)) {
|
|
@@ -56,7 +77,7 @@ export function updateFormatCell(ctx, d, attr, foucsStatus, row_st, row_ed, col_
|
|
|
56
77
|
}
|
|
57
78
|
cell.ct.fa = foucsStatus;
|
|
58
79
|
cell.ct.t = type;
|
|
59
|
-
cell.v = String(value);
|
|
80
|
+
cell.v = typeof value === "number" ? value : String(value);
|
|
60
81
|
cell.fc = cell.fc || ((_f = (_e = (_d = cell.ct) === null || _d === void 0 ? void 0 : _d.s) === null || _e === void 0 ? void 0 : _e[0]) === null || _f === void 0 ? void 0 : _f.fc);
|
|
61
82
|
cell.bl = cell.bl || ((_j = (_h = (_g = cell.ct) === null || _g === void 0 ? void 0 : _g.s) === null || _h === void 0 ? void 0 : _h[0]) === null || _j === void 0 ? void 0 : _j.bl);
|
|
62
83
|
cell.it = cell.it || ((_m = (_l = (_k = cell.ct) === null || _k === void 0 ? void 0 : _k.s) === null || _l === void 0 ? void 0 : _l[0]) === null || _m === void 0 ? void 0 : _m.it);
|
|
@@ -69,7 +90,7 @@ export function updateFormatCell(ctx, d, attr, foucsStatus, row_st, row_ed, col_
|
|
|
69
90
|
fa: foucsStatus,
|
|
70
91
|
t: type
|
|
71
92
|
},
|
|
72
|
-
v: value,
|
|
93
|
+
v: typeof value === "number" ? value : value,
|
|
73
94
|
m: mask
|
|
74
95
|
};
|
|
75
96
|
}
|
|
@@ -15,6 +15,16 @@ export declare function valueIsError(value: string): boolean;
|
|
|
15
15
|
export declare function isRealNull(val: any): boolean;
|
|
16
16
|
export declare function isHexValue(str: string): boolean;
|
|
17
17
|
export declare function isRealNum(val: any): boolean;
|
|
18
|
+
export type DateFormatInfo = {
|
|
19
|
+
year: number;
|
|
20
|
+
month: number;
|
|
21
|
+
day: number;
|
|
22
|
+
hours: number;
|
|
23
|
+
minutes: number;
|
|
24
|
+
seconds: number;
|
|
25
|
+
formatType: string;
|
|
26
|
+
};
|
|
27
|
+
export declare function detectDateFormat(str: string): DateFormatInfo | null;
|
|
18
28
|
export declare function isdatetime(s: any): boolean;
|
|
19
29
|
export declare function diff(now: any, then: any): number;
|
|
20
30
|
export declare function isdatatypemulti(s: any): any;
|
package/es/modules/validation.js
CHANGED
|
@@ -39,33 +39,296 @@ export function isRealNum(val) {
|
|
|
39
39
|
}
|
|
40
40
|
return !Number.isNaN(Number(val));
|
|
41
41
|
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
42
|
+
var MONTH_NAME_MAP = {
|
|
43
|
+
january: 1,
|
|
44
|
+
february: 2,
|
|
45
|
+
march: 3,
|
|
46
|
+
april: 4,
|
|
47
|
+
may: 5,
|
|
48
|
+
june: 6,
|
|
49
|
+
july: 7,
|
|
50
|
+
august: 8,
|
|
51
|
+
september: 9,
|
|
52
|
+
october: 10,
|
|
53
|
+
november: 11,
|
|
54
|
+
december: 12,
|
|
55
|
+
jan: 1,
|
|
56
|
+
feb: 2,
|
|
57
|
+
mar: 3,
|
|
58
|
+
apr: 4,
|
|
59
|
+
jun: 6,
|
|
60
|
+
jul: 7,
|
|
61
|
+
aug: 8,
|
|
62
|
+
sep: 9,
|
|
63
|
+
oct: 10,
|
|
64
|
+
nov: 11,
|
|
65
|
+
dec: 12
|
|
66
|
+
};
|
|
67
|
+
var MONTH_NAMES_RE = "january|february|march|april|may|june|july|august|september|october|november|december|jan|feb|mar|apr|jun|jul|aug|sep|oct|nov|dec";
|
|
68
|
+
var MONTH_ABBR_RE = "jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec";
|
|
69
|
+
function isValidDateParts(year, month, day) {
|
|
70
|
+
if (year < 1900) return false;
|
|
71
|
+
if (month < 1 || month > 12) return false;
|
|
72
|
+
if (day < 1 || day > 31) return false;
|
|
73
|
+
if (month === 2) {
|
|
74
|
+
var isLeap = new Date(year, 1, 29).getDate() === 29;
|
|
75
|
+
if (isLeap && day > 29) return false;
|
|
76
|
+
if (!isLeap && day > 28) return false;
|
|
47
77
|
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
78
|
+
if ([4, 6, 9, 11].includes(month) && day > 30) return false;
|
|
79
|
+
return true;
|
|
80
|
+
}
|
|
81
|
+
export function detectDateFormat(str) {
|
|
82
|
+
if (!str || str.toString().length < 5) return null;
|
|
83
|
+
var s = str.toString().trim();
|
|
84
|
+
var m;
|
|
85
|
+
m = /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2})(?::(\d{2}))?$/.exec(s);
|
|
86
|
+
if (m) {
|
|
87
|
+
var y = +m[1];
|
|
88
|
+
var mo = +m[2];
|
|
89
|
+
var d = +m[3];
|
|
90
|
+
var h = +m[4];
|
|
91
|
+
var mi = +m[5];
|
|
92
|
+
var sec = m[6] != null ? +m[6] : 0;
|
|
93
|
+
if (isValidDateParts(y, mo, d)) {
|
|
94
|
+
return {
|
|
95
|
+
year: y,
|
|
96
|
+
month: mo,
|
|
97
|
+
day: d,
|
|
98
|
+
hours: h,
|
|
99
|
+
minutes: mi,
|
|
100
|
+
seconds: sec,
|
|
101
|
+
formatType: "yyyy-MM-ddTHH:mm"
|
|
102
|
+
};
|
|
103
|
+
}
|
|
53
104
|
}
|
|
54
|
-
|
|
55
|
-
|
|
105
|
+
m = /^(\d{4})-(\d{1,2})-(\d{1,2})(?:\s(\d{1,2}):(\d{2})(?::(\d{2}))?)?$/.exec(s);
|
|
106
|
+
if (m) {
|
|
107
|
+
var y = +m[1];
|
|
108
|
+
var mo = +m[2];
|
|
109
|
+
var d = +m[3];
|
|
110
|
+
if (isValidDateParts(y, mo, d)) {
|
|
111
|
+
var h = m[4] != null ? +m[4] : 0;
|
|
112
|
+
var mi = m[5] != null ? +m[5] : 0;
|
|
113
|
+
var sec = m[6] != null ? +m[6] : 0;
|
|
114
|
+
return {
|
|
115
|
+
year: y,
|
|
116
|
+
month: mo,
|
|
117
|
+
day: d,
|
|
118
|
+
hours: h,
|
|
119
|
+
minutes: mi,
|
|
120
|
+
seconds: sec,
|
|
121
|
+
formatType: m[4] != null ? "yyyy-MM-dd HH:mm" : "yyyy-MM-dd"
|
|
122
|
+
};
|
|
123
|
+
}
|
|
56
124
|
}
|
|
57
|
-
|
|
58
|
-
|
|
125
|
+
m = /^(\d{4})\/(\d{1,2})\/(\d{1,2})(?:\s(\d{1,2}):(\d{2})(?::(\d{2}))?)?$/.exec(s);
|
|
126
|
+
if (m) {
|
|
127
|
+
var y = +m[1];
|
|
128
|
+
var mo = +m[2];
|
|
129
|
+
var d = +m[3];
|
|
130
|
+
if (isValidDateParts(y, mo, d)) {
|
|
131
|
+
var h = m[4] != null ? +m[4] : 0;
|
|
132
|
+
var mi = m[5] != null ? +m[5] : 0;
|
|
133
|
+
var sec = m[6] != null ? +m[6] : 0;
|
|
134
|
+
return {
|
|
135
|
+
year: y,
|
|
136
|
+
month: mo,
|
|
137
|
+
day: d,
|
|
138
|
+
hours: h,
|
|
139
|
+
minutes: mi,
|
|
140
|
+
seconds: sec,
|
|
141
|
+
formatType: m[4] != null ? "yyyy/MM/dd HH:mm" : "yyyy/MM/dd"
|
|
142
|
+
};
|
|
143
|
+
}
|
|
59
144
|
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
145
|
+
m = /^(\d{4})\.(\d{1,2})\.(\d{1,2})$/.exec(s);
|
|
146
|
+
if (m) {
|
|
147
|
+
var y = +m[1];
|
|
148
|
+
var mo = +m[2];
|
|
149
|
+
var d = +m[3];
|
|
150
|
+
if (isValidDateParts(y, mo, d)) {
|
|
151
|
+
return {
|
|
152
|
+
year: y,
|
|
153
|
+
month: mo,
|
|
154
|
+
day: d,
|
|
155
|
+
hours: 0,
|
|
156
|
+
minutes: 0,
|
|
157
|
+
seconds: 0,
|
|
158
|
+
formatType: "yyyy.MM.dd"
|
|
159
|
+
};
|
|
63
160
|
}
|
|
64
|
-
|
|
65
|
-
|
|
161
|
+
}
|
|
162
|
+
m = /^(\d{1,2})\/(\d{1,2})\/(\d{4})\s(\d{1,2}):(\d{2})\s?(AM|PM)$/i.exec(s);
|
|
163
|
+
if (m) {
|
|
164
|
+
var p1 = +m[1];
|
|
165
|
+
var p2 = +m[2];
|
|
166
|
+
var y = +m[3];
|
|
167
|
+
var h = +m[4];
|
|
168
|
+
var mi = +m[5];
|
|
169
|
+
var ampm = m[6].toUpperCase();
|
|
170
|
+
if (p1 <= 12 && isValidDateParts(y, p1, p2)) {
|
|
171
|
+
var actualH = h;
|
|
172
|
+
if (ampm === "PM" && h !== 12) actualH = h + 12;
|
|
173
|
+
if (ampm === "AM" && h === 12) actualH = 0;
|
|
174
|
+
return {
|
|
175
|
+
year: y,
|
|
176
|
+
month: p1,
|
|
177
|
+
day: p2,
|
|
178
|
+
hours: actualH,
|
|
179
|
+
minutes: mi,
|
|
180
|
+
seconds: 0,
|
|
181
|
+
formatType: "MM/dd/yyyy h:mm AM/PM"
|
|
182
|
+
};
|
|
66
183
|
}
|
|
67
184
|
}
|
|
68
|
-
|
|
185
|
+
m = /^(\d{1,2})\/(\d{1,2})\/(\d{4})$/.exec(s);
|
|
186
|
+
if (m) {
|
|
187
|
+
var p1 = +m[1];
|
|
188
|
+
var p2 = +m[2];
|
|
189
|
+
var y = +m[3];
|
|
190
|
+
if (p1 > 12 && isValidDateParts(y, p2, p1)) {
|
|
191
|
+
return {
|
|
192
|
+
year: y,
|
|
193
|
+
month: p2,
|
|
194
|
+
day: p1,
|
|
195
|
+
hours: 0,
|
|
196
|
+
minutes: 0,
|
|
197
|
+
seconds: 0,
|
|
198
|
+
formatType: "dd/MM/yyyy"
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
if (p2 > 12 && p1 <= 12 && isValidDateParts(y, p1, p2)) {
|
|
202
|
+
var formatType = m[1].length === 1 ? "M/d/yyyy" : "MM/dd/yyyy";
|
|
203
|
+
return {
|
|
204
|
+
year: y,
|
|
205
|
+
month: p1,
|
|
206
|
+
day: p2,
|
|
207
|
+
hours: 0,
|
|
208
|
+
minutes: 0,
|
|
209
|
+
seconds: 0,
|
|
210
|
+
formatType: formatType
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
if (p1 <= 12 && p2 <= 31 && isValidDateParts(y, p1, p2)) {
|
|
214
|
+
var formatType = m[1].length === 1 ? "M/d/yyyy" : "MM/dd/yyyy";
|
|
215
|
+
return {
|
|
216
|
+
year: y,
|
|
217
|
+
month: p1,
|
|
218
|
+
day: p2,
|
|
219
|
+
hours: 0,
|
|
220
|
+
minutes: 0,
|
|
221
|
+
seconds: 0,
|
|
222
|
+
formatType: formatType
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
m = /^(\d{2})\/(\d{2})\/(\d{2})$/.exec(s);
|
|
227
|
+
if (m) {
|
|
228
|
+
var p1 = +m[1];
|
|
229
|
+
var p2 = +m[2];
|
|
230
|
+
var y = 2000 + +m[3];
|
|
231
|
+
if (p1 <= 12 && p2 <= 31 && isValidDateParts(y, p1, p2)) {
|
|
232
|
+
return {
|
|
233
|
+
year: y,
|
|
234
|
+
month: p1,
|
|
235
|
+
day: p2,
|
|
236
|
+
hours: 0,
|
|
237
|
+
minutes: 0,
|
|
238
|
+
seconds: 0,
|
|
239
|
+
formatType: "MM/dd/yy"
|
|
240
|
+
};
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
m = /^(\d{1,2})-(\d{1,2})-(\d{4})$/.exec(s);
|
|
244
|
+
if (m) {
|
|
245
|
+
var p1 = +m[1];
|
|
246
|
+
var p2 = +m[2];
|
|
247
|
+
var y = +m[3];
|
|
248
|
+
if (p1 > 12 && isValidDateParts(y, p2, p1)) {
|
|
249
|
+
return {
|
|
250
|
+
year: y,
|
|
251
|
+
month: p2,
|
|
252
|
+
day: p1,
|
|
253
|
+
hours: 0,
|
|
254
|
+
minutes: 0,
|
|
255
|
+
seconds: 0,
|
|
256
|
+
formatType: "dd-MM-yyyy"
|
|
257
|
+
};
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
m = /^(\d{1,2})\.(\d{1,2})\.(\d{4})$/.exec(s);
|
|
261
|
+
if (m) {
|
|
262
|
+
var p1 = +m[1];
|
|
263
|
+
var p2 = +m[2];
|
|
264
|
+
var y = +m[3];
|
|
265
|
+
if (p1 > 12 && isValidDateParts(y, p2, p1)) {
|
|
266
|
+
return {
|
|
267
|
+
year: y,
|
|
268
|
+
month: p2,
|
|
269
|
+
day: p1,
|
|
270
|
+
hours: 0,
|
|
271
|
+
minutes: 0,
|
|
272
|
+
seconds: 0,
|
|
273
|
+
formatType: "dd.MM.yyyy"
|
|
274
|
+
};
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
m = new RegExp("^(".concat(MONTH_NAMES_RE, ")\\s+(\\d{1,2}),?\\s+(\\d{4})$"), "i").exec(s);
|
|
278
|
+
if (m) {
|
|
279
|
+
var mo = MONTH_NAME_MAP[m[1].toLowerCase()];
|
|
280
|
+
var d = +m[2];
|
|
281
|
+
var y = +m[3];
|
|
282
|
+
if (mo && isValidDateParts(y, mo, d)) {
|
|
283
|
+
return {
|
|
284
|
+
year: y,
|
|
285
|
+
month: mo,
|
|
286
|
+
day: d,
|
|
287
|
+
hours: 0,
|
|
288
|
+
minutes: 0,
|
|
289
|
+
seconds: 0,
|
|
290
|
+
formatType: "named"
|
|
291
|
+
};
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
m = new RegExp("^(\\d{1,2})\\s+(".concat(MONTH_NAMES_RE, ")\\s+(\\d{4})$"), "i").exec(s);
|
|
295
|
+
if (m) {
|
|
296
|
+
var d = +m[1];
|
|
297
|
+
var mo = MONTH_NAME_MAP[m[2].toLowerCase()];
|
|
298
|
+
var y = +m[3];
|
|
299
|
+
if (mo && isValidDateParts(y, mo, d)) {
|
|
300
|
+
return {
|
|
301
|
+
year: y,
|
|
302
|
+
month: mo,
|
|
303
|
+
day: d,
|
|
304
|
+
hours: 0,
|
|
305
|
+
minutes: 0,
|
|
306
|
+
seconds: 0,
|
|
307
|
+
formatType: "named"
|
|
308
|
+
};
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
m = new RegExp("^(".concat(MONTH_ABBR_RE, ")-(\\d{1,2})-(\\d{4})$"), "i").exec(s);
|
|
312
|
+
if (m) {
|
|
313
|
+
var mo = MONTH_NAME_MAP[m[1].toLowerCase()];
|
|
314
|
+
var d = +m[2];
|
|
315
|
+
var y = +m[3];
|
|
316
|
+
if (mo && isValidDateParts(y, mo, d)) {
|
|
317
|
+
return {
|
|
318
|
+
year: y,
|
|
319
|
+
month: mo,
|
|
320
|
+
day: d,
|
|
321
|
+
hours: 0,
|
|
322
|
+
minutes: 0,
|
|
323
|
+
seconds: 0,
|
|
324
|
+
formatType: "named"
|
|
325
|
+
};
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
return null;
|
|
329
|
+
}
|
|
330
|
+
function checkDateTime(str) {
|
|
331
|
+
return detectDateFormat(str) !== null;
|
|
69
332
|
}
|
|
70
333
|
export function isdatetime(s) {
|
|
71
334
|
if (s === null || s.toString().length < 5) {
|