@fileverse-dev/fortune-core 1.3.5-hyper-2 → 1.3.6-right
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 +10 -6
- package/es/modules/format.js +29 -38
- package/es/modules/selection.js +192 -6
- 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 +10 -6
- package/lib/modules/format.js +28 -37
- package/lib/modules/selection.js +192 -6
- 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/lib/modules/selection.js
CHANGED
|
@@ -1576,6 +1576,8 @@ function deleteSelectedCellText(ctx) {
|
|
|
1576
1576
|
var cell = d[r][c];
|
|
1577
1577
|
delete cell.m;
|
|
1578
1578
|
delete cell.v;
|
|
1579
|
+
delete cell.fc;
|
|
1580
|
+
delete cell.un;
|
|
1579
1581
|
if (cell.f != null) {
|
|
1580
1582
|
delete cell.f;
|
|
1581
1583
|
(0, _formula.delFunctionGroup)(ctx, r, c, ctx.currentSheetId);
|
|
@@ -1648,7 +1650,8 @@ function deleteSelectedCellFormat(ctx) {
|
|
|
1648
1650
|
return "success";
|
|
1649
1651
|
}
|
|
1650
1652
|
function fillRightData(ctx) {
|
|
1651
|
-
var _a, _b;
|
|
1653
|
+
var _a, _b, _c, _d;
|
|
1654
|
+
var _e, _f, _g;
|
|
1652
1655
|
var allowEdit = (0, _utils.isAllowEdit)(ctx);
|
|
1653
1656
|
if (allowEdit === false) {
|
|
1654
1657
|
return "allowEdit";
|
|
@@ -1676,18 +1679,109 @@ function fillRightData(ctx) {
|
|
|
1676
1679
|
var r2 = selection[s].row[1];
|
|
1677
1680
|
var c1 = selection[s].column[0];
|
|
1678
1681
|
var c2 = selection[s].column[1];
|
|
1682
|
+
var sheetIndex = (0, _utils.getSheetIndex)(ctx, ctx.currentSheetId);
|
|
1683
|
+
var file = sheetIndex != null ? ctx.luckysheetfile[sheetIndex] : null;
|
|
1684
|
+
var dataVerification = file === null || file === void 0 ? void 0 : file.dataVerification;
|
|
1685
|
+
var hyperlink = file === null || file === void 0 ? void 0 : file.hyperlink;
|
|
1686
|
+
var cdformat = file === null || file === void 0 ? void 0 : file.luckysheet_conditionformat_save;
|
|
1679
1687
|
var isSingleCell = r1 === r2 && c1 === c2;
|
|
1680
1688
|
if (isSingleCell) {
|
|
1681
1689
|
if (c1 - 1 >= 0 && d[r1]) {
|
|
1690
|
+
var srcRow = r1;
|
|
1691
|
+
var srcCol = c1 - 1;
|
|
1682
1692
|
var prev = d[r1][c1 - 1];
|
|
1683
1693
|
d[r1][c1] = prev != null ? __assign({}, prev) : {};
|
|
1694
|
+
if (file != null) {
|
|
1695
|
+
var srcKey = "".concat(srcRow, "_").concat(srcCol);
|
|
1696
|
+
var tgtKey = "".concat(r1, "_").concat(c1);
|
|
1697
|
+
if (dataVerification != null) {
|
|
1698
|
+
var dv = dataVerification[srcKey];
|
|
1699
|
+
if (dv != null) {
|
|
1700
|
+
console.log("[fillRightData] dataVerification copy from", {
|
|
1701
|
+
row: srcRow,
|
|
1702
|
+
col: srcCol
|
|
1703
|
+
}, "→", {
|
|
1704
|
+
row: r1,
|
|
1705
|
+
col: c1
|
|
1706
|
+
}, dv);
|
|
1707
|
+
file.dataVerification = __assign(__assign({}, file.dataVerification || {}), (_a = {}, _a[tgtKey] = _lodash.default.cloneDeep(dv), _a));
|
|
1708
|
+
}
|
|
1709
|
+
}
|
|
1710
|
+
if (hyperlink != null && hyperlink[srcKey] != null) {
|
|
1711
|
+
file.hyperlink = __assign(__assign({}, file.hyperlink || {}), (_b = {}, _b[tgtKey] = _lodash.default.cloneDeep(hyperlink[srcKey]), _b));
|
|
1712
|
+
var tgtCell = d[r1][c1];
|
|
1713
|
+
if (tgtCell != null) tgtCell.hl = {
|
|
1714
|
+
r: r1,
|
|
1715
|
+
c: c1,
|
|
1716
|
+
id: ctx.currentSheetId
|
|
1717
|
+
};
|
|
1718
|
+
}
|
|
1719
|
+
if (cdformat != null && cdformat.length > 0) {
|
|
1720
|
+
for (var i = 0; i < cdformat.length; i += 1) {
|
|
1721
|
+
var ranges = cdformat[i].cellrange;
|
|
1722
|
+
if (!ranges) continue;
|
|
1723
|
+
for (var j = 0; j < ranges.length; j += 1) {
|
|
1724
|
+
var cr = ranges[j];
|
|
1725
|
+
if (srcRow >= cr.row[0] && srcRow <= cr.row[1] && srcCol >= cr.column[0] && srcCol <= cr.column[1]) {
|
|
1726
|
+
ranges.push({
|
|
1727
|
+
row: [r1, r1],
|
|
1728
|
+
column: [c1, c1]
|
|
1729
|
+
});
|
|
1730
|
+
break;
|
|
1731
|
+
}
|
|
1732
|
+
}
|
|
1733
|
+
}
|
|
1734
|
+
}
|
|
1735
|
+
}
|
|
1684
1736
|
}
|
|
1685
1737
|
} else {
|
|
1686
1738
|
for (var r = r1; r <= r2; r += 1) {
|
|
1687
|
-
var sourceCell = (
|
|
1739
|
+
var sourceCell = (_e = d[r]) === null || _e === void 0 ? void 0 : _e[c1];
|
|
1688
1740
|
for (var c = c1 + 1; c <= c2; c += 1) {
|
|
1689
1741
|
if (d[r]) {
|
|
1690
|
-
d[r][c] = sourceCell != null ? __assign({}, sourceCell) : (
|
|
1742
|
+
d[r][c] = sourceCell != null ? __assign({}, sourceCell) : (_f = d[r][c]) !== null && _f !== void 0 ? _f : {};
|
|
1743
|
+
}
|
|
1744
|
+
if (file != null) {
|
|
1745
|
+
var srcKey = "".concat(r, "_").concat(c1);
|
|
1746
|
+
var tgtKey = "".concat(r, "_").concat(c);
|
|
1747
|
+
if (dataVerification != null) {
|
|
1748
|
+
var dv = dataVerification[srcKey];
|
|
1749
|
+
if (dv != null) {
|
|
1750
|
+
console.log("[fillRightData] dataVerification copy from", {
|
|
1751
|
+
row: r,
|
|
1752
|
+
col: c1
|
|
1753
|
+
}, "→", {
|
|
1754
|
+
row: r,
|
|
1755
|
+
col: c
|
|
1756
|
+
}, dv);
|
|
1757
|
+
file.dataVerification = __assign(__assign({}, file.dataVerification || {}), (_c = {}, _c[tgtKey] = _lodash.default.cloneDeep(dv), _c));
|
|
1758
|
+
}
|
|
1759
|
+
}
|
|
1760
|
+
if (hyperlink != null && hyperlink[srcKey] != null) {
|
|
1761
|
+
file.hyperlink = __assign(__assign({}, file.hyperlink || {}), (_d = {}, _d[tgtKey] = _lodash.default.cloneDeep(hyperlink[srcKey]), _d));
|
|
1762
|
+
var tgtCell = (_g = d[r]) === null || _g === void 0 ? void 0 : _g[c];
|
|
1763
|
+
if (tgtCell != null) tgtCell.hl = {
|
|
1764
|
+
r: r,
|
|
1765
|
+
c: c,
|
|
1766
|
+
id: ctx.currentSheetId
|
|
1767
|
+
};
|
|
1768
|
+
}
|
|
1769
|
+
if (cdformat != null && cdformat.length > 0) {
|
|
1770
|
+
for (var i = 0; i < cdformat.length; i += 1) {
|
|
1771
|
+
var ranges = cdformat[i].cellrange;
|
|
1772
|
+
if (!ranges) continue;
|
|
1773
|
+
for (var j = 0; j < ranges.length; j += 1) {
|
|
1774
|
+
var cr = ranges[j];
|
|
1775
|
+
if (r >= cr.row[0] && r <= cr.row[1] && c1 >= cr.column[0] && c1 <= cr.column[1]) {
|
|
1776
|
+
ranges.push({
|
|
1777
|
+
row: [r, r],
|
|
1778
|
+
column: [c, c]
|
|
1779
|
+
});
|
|
1780
|
+
break;
|
|
1781
|
+
}
|
|
1782
|
+
}
|
|
1783
|
+
}
|
|
1784
|
+
}
|
|
1691
1785
|
}
|
|
1692
1786
|
}
|
|
1693
1787
|
}
|
|
@@ -1697,7 +1791,8 @@ function fillRightData(ctx) {
|
|
|
1697
1791
|
return "success";
|
|
1698
1792
|
}
|
|
1699
1793
|
function fillDownData(ctx) {
|
|
1700
|
-
var _a, _b;
|
|
1794
|
+
var _a, _b, _c, _d;
|
|
1795
|
+
var _e, _f, _g;
|
|
1701
1796
|
var allowEdit = (0, _utils.isAllowEdit)(ctx);
|
|
1702
1797
|
if (allowEdit === false) {
|
|
1703
1798
|
return "allowEdit";
|
|
@@ -1725,19 +1820,110 @@ function fillDownData(ctx) {
|
|
|
1725
1820
|
var r2 = selection[s].row[1];
|
|
1726
1821
|
var c1 = selection[s].column[0];
|
|
1727
1822
|
var c2 = selection[s].column[1];
|
|
1823
|
+
var sheetIndex = (0, _utils.getSheetIndex)(ctx, ctx.currentSheetId);
|
|
1824
|
+
var file = sheetIndex != null ? ctx.luckysheetfile[sheetIndex] : null;
|
|
1825
|
+
var dataVerification = file === null || file === void 0 ? void 0 : file.dataVerification;
|
|
1826
|
+
var hyperlink = file === null || file === void 0 ? void 0 : file.hyperlink;
|
|
1827
|
+
var cdformat = file === null || file === void 0 ? void 0 : file.luckysheet_conditionformat_save;
|
|
1728
1828
|
var isSingleCell = r1 === r2 && c1 === c2;
|
|
1729
1829
|
if (isSingleCell) {
|
|
1730
1830
|
if (r1 - 1 >= 0 && d[r1 - 1]) {
|
|
1831
|
+
var srcRow = r1 - 1;
|
|
1832
|
+
var srcCol = c1;
|
|
1731
1833
|
var prev = d[r1 - 1][c1];
|
|
1732
1834
|
if (!d[r1]) d[r1] = [];
|
|
1733
1835
|
d[r1][c1] = prev != null ? __assign({}, prev) : {};
|
|
1836
|
+
if (file != null) {
|
|
1837
|
+
var srcKey = "".concat(srcRow, "_").concat(srcCol);
|
|
1838
|
+
var tgtKey = "".concat(r1, "_").concat(c1);
|
|
1839
|
+
if (dataVerification != null) {
|
|
1840
|
+
var dv = dataVerification[srcKey];
|
|
1841
|
+
if (dv != null) {
|
|
1842
|
+
console.log("[fillDownData] dataVerification copy from", {
|
|
1843
|
+
row: srcRow,
|
|
1844
|
+
col: srcCol
|
|
1845
|
+
}, "→", {
|
|
1846
|
+
row: r1,
|
|
1847
|
+
col: c1
|
|
1848
|
+
}, dv);
|
|
1849
|
+
file.dataVerification = __assign(__assign({}, file.dataVerification || {}), (_a = {}, _a[tgtKey] = _lodash.default.cloneDeep(dv), _a));
|
|
1850
|
+
}
|
|
1851
|
+
}
|
|
1852
|
+
if (hyperlink != null && hyperlink[srcKey] != null) {
|
|
1853
|
+
file.hyperlink = __assign(__assign({}, file.hyperlink || {}), (_b = {}, _b[tgtKey] = _lodash.default.cloneDeep(hyperlink[srcKey]), _b));
|
|
1854
|
+
var tgtCell = d[r1][c1];
|
|
1855
|
+
if (tgtCell != null) tgtCell.hl = {
|
|
1856
|
+
r: r1,
|
|
1857
|
+
c: c1,
|
|
1858
|
+
id: ctx.currentSheetId
|
|
1859
|
+
};
|
|
1860
|
+
}
|
|
1861
|
+
if (cdformat != null && cdformat.length > 0) {
|
|
1862
|
+
for (var i = 0; i < cdformat.length; i += 1) {
|
|
1863
|
+
var ranges = cdformat[i].cellrange;
|
|
1864
|
+
if (!ranges) continue;
|
|
1865
|
+
for (var j = 0; j < ranges.length; j += 1) {
|
|
1866
|
+
var cr = ranges[j];
|
|
1867
|
+
if (srcRow >= cr.row[0] && srcRow <= cr.row[1] && srcCol >= cr.column[0] && srcCol <= cr.column[1]) {
|
|
1868
|
+
ranges.push({
|
|
1869
|
+
row: [r1, r1],
|
|
1870
|
+
column: [c1, c1]
|
|
1871
|
+
});
|
|
1872
|
+
break;
|
|
1873
|
+
}
|
|
1874
|
+
}
|
|
1875
|
+
}
|
|
1876
|
+
}
|
|
1877
|
+
}
|
|
1734
1878
|
}
|
|
1735
1879
|
} else {
|
|
1736
1880
|
for (var c = c1; c <= c2; c += 1) {
|
|
1737
|
-
var sourceCell = (
|
|
1881
|
+
var sourceCell = (_e = d[r1]) === null || _e === void 0 ? void 0 : _e[c];
|
|
1738
1882
|
for (var r = r1 + 1; r <= r2; r += 1) {
|
|
1739
1883
|
if (!d[r]) d[r] = [];
|
|
1740
|
-
d[r][c] = sourceCell != null ? __assign({}, sourceCell) : (
|
|
1884
|
+
d[r][c] = sourceCell != null ? __assign({}, sourceCell) : (_f = d[r][c]) !== null && _f !== void 0 ? _f : {};
|
|
1885
|
+
if (file != null) {
|
|
1886
|
+
var srcKey = "".concat(r1, "_").concat(c);
|
|
1887
|
+
var tgtKey = "".concat(r, "_").concat(c);
|
|
1888
|
+
if (dataVerification != null) {
|
|
1889
|
+
var dv = dataVerification[srcKey];
|
|
1890
|
+
if (dv != null) {
|
|
1891
|
+
console.log("[fillDownData] dataVerification copy from", {
|
|
1892
|
+
row: r1,
|
|
1893
|
+
col: c
|
|
1894
|
+
}, "→", {
|
|
1895
|
+
row: r,
|
|
1896
|
+
col: c
|
|
1897
|
+
}, dv);
|
|
1898
|
+
file.dataVerification = __assign(__assign({}, file.dataVerification || {}), (_c = {}, _c[tgtKey] = _lodash.default.cloneDeep(dv), _c));
|
|
1899
|
+
}
|
|
1900
|
+
}
|
|
1901
|
+
if (hyperlink != null && hyperlink[srcKey] != null) {
|
|
1902
|
+
file.hyperlink = __assign(__assign({}, file.hyperlink || {}), (_d = {}, _d[tgtKey] = _lodash.default.cloneDeep(hyperlink[srcKey]), _d));
|
|
1903
|
+
var tgtCell = (_g = d[r]) === null || _g === void 0 ? void 0 : _g[c];
|
|
1904
|
+
if (tgtCell != null) tgtCell.hl = {
|
|
1905
|
+
r: r,
|
|
1906
|
+
c: c,
|
|
1907
|
+
id: ctx.currentSheetId
|
|
1908
|
+
};
|
|
1909
|
+
}
|
|
1910
|
+
if (cdformat != null && cdformat.length > 0) {
|
|
1911
|
+
for (var i = 0; i < cdformat.length; i += 1) {
|
|
1912
|
+
var ranges = cdformat[i].cellrange;
|
|
1913
|
+
if (!ranges) continue;
|
|
1914
|
+
for (var j = 0; j < ranges.length; j += 1) {
|
|
1915
|
+
var cr = ranges[j];
|
|
1916
|
+
if (r1 >= cr.row[0] && r1 <= cr.row[1] && c >= cr.column[0] && c <= cr.column[1]) {
|
|
1917
|
+
ranges.push({
|
|
1918
|
+
row: [r, r],
|
|
1919
|
+
column: [c, c]
|
|
1920
|
+
});
|
|
1921
|
+
break;
|
|
1922
|
+
}
|
|
1923
|
+
}
|
|
1924
|
+
}
|
|
1925
|
+
}
|
|
1926
|
+
}
|
|
1741
1927
|
}
|
|
1742
1928
|
}
|
|
1743
1929
|
}
|
package/lib/modules/ssf.js
CHANGED
|
@@ -1370,7 +1370,7 @@ var make_ssf = function make_ssf(SSF) {
|
|
|
1370
1370
|
if (typeof n !== "number" || !Number.isFinite(n)) return null;
|
|
1371
1371
|
if (!Number.isInteger(n)) return null;
|
|
1372
1372
|
if (n < 0) return null;
|
|
1373
|
-
var minSec =
|
|
1373
|
+
var minSec = 100000; // Excel serial numbers max ~73050 for year 2100; avoids collision
|
|
1374
1374
|
var maxSec = 4102444800; // ~2100-01-01
|
|
1375
1375
|
var minMs = minSec * 1000;
|
|
1376
1376
|
var maxMs = maxSec * 1000;
|
package/lib/modules/toolbar.js
CHANGED
|
@@ -36,8 +36,8 @@ var _context = require("../context");
|
|
|
36
36
|
var _utils = require("../utils");
|
|
37
37
|
var _cell = require("./cell");
|
|
38
38
|
var _color = require("./color");
|
|
39
|
-
var _format = require("./format");
|
|
40
39
|
var _cursor = require("./cursor");
|
|
40
|
+
var _format = require("./format");
|
|
41
41
|
var _formula2 = require("./formula");
|
|
42
42
|
var _inlineString = require("./inline-string");
|
|
43
43
|
var _location = require("./location");
|
|
@@ -67,21 +67,42 @@ function updateFormatCell(ctx, d, attr, foucsStatus, row_st, row_ed, col_st, col
|
|
|
67
67
|
} else {
|
|
68
68
|
value = cell;
|
|
69
69
|
}
|
|
70
|
+
var type = "n";
|
|
71
|
+
if ((0, _format.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) {
|
|
72
|
+
type = "d";
|
|
73
|
+
} else if (foucsStatus === "@" || foucsStatus === 49) {
|
|
74
|
+
type = "s";
|
|
75
|
+
}
|
|
70
76
|
if (_lodash.default.isNil(value)) {
|
|
77
|
+
if (!_lodash.default.isNil(d[r])) {
|
|
78
|
+
if (_lodash.default.isNil(d[r][c])) {
|
|
79
|
+
d[r][c] = {
|
|
80
|
+
ct: {
|
|
81
|
+
fa: foucsStatus,
|
|
82
|
+
t: type
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
} else if (_lodash.default.isPlainObject(d[r][c])) {
|
|
86
|
+
if (_lodash.default.isNil(d[r][c].ct)) d[r][c].ct = {};
|
|
87
|
+
d[r][c].ct.fa = foucsStatus;
|
|
88
|
+
d[r][c].ct.t = type;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
71
91
|
continue;
|
|
72
92
|
}
|
|
73
93
|
if (foucsStatus !== "@" && (0, _validation.isRealNum)(value)) {
|
|
74
94
|
value = Number(value);
|
|
95
|
+
} else if (type === "d" && typeof value === "string") {
|
|
96
|
+
var dateInfo = (0, _validation.detectDateFormat)(value);
|
|
97
|
+
if (dateInfo) {
|
|
98
|
+
var dateObj = new Date(dateInfo.year, dateInfo.month - 1, dateInfo.day, dateInfo.hours, dateInfo.minutes, dateInfo.seconds);
|
|
99
|
+
value = (0, _format.datenum_local)(dateObj);
|
|
100
|
+
}
|
|
75
101
|
}
|
|
76
|
-
|
|
77
|
-
var type = "n";
|
|
78
|
-
if ((0, _format.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) {
|
|
79
|
-
type = "d";
|
|
80
|
-
} else if (foucsStatus === "@" || foucsStatus === 49) {
|
|
81
|
-
type = "s";
|
|
82
|
-
} else if (foucsStatus === "General" || foucsStatus === 0) {
|
|
102
|
+
if (foucsStatus === "General" || foucsStatus === 0) {
|
|
83
103
|
type = (0, _validation.isRealNum)(value) ? "n" : "g";
|
|
84
104
|
}
|
|
105
|
+
var mask = (0, _format.update)(foucsStatus, value);
|
|
85
106
|
if (cell && _lodash.default.isPlainObject(cell)) {
|
|
86
107
|
cell.m = "".concat(mask);
|
|
87
108
|
if (_lodash.default.isNil(cell.ct)) {
|
|
@@ -89,7 +110,7 @@ function updateFormatCell(ctx, d, attr, foucsStatus, row_st, row_ed, col_st, col
|
|
|
89
110
|
}
|
|
90
111
|
cell.ct.fa = foucsStatus;
|
|
91
112
|
cell.ct.t = type;
|
|
92
|
-
cell.v = String(value);
|
|
113
|
+
cell.v = typeof value === "number" ? value : String(value);
|
|
93
114
|
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);
|
|
94
115
|
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);
|
|
95
116
|
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);
|
|
@@ -102,7 +123,7 @@ function updateFormatCell(ctx, d, attr, foucsStatus, row_st, row_ed, col_st, col
|
|
|
102
123
|
fa: foucsStatus,
|
|
103
124
|
t: type
|
|
104
125
|
},
|
|
105
|
-
v: value,
|
|
126
|
+
v: typeof value === "number" ? value : value,
|
|
106
127
|
m: mask
|
|
107
128
|
};
|
|
108
129
|
}
|
|
@@ -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;
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
+
exports.detectDateFormat = detectDateFormat;
|
|
6
7
|
exports.detectErrorFromValue = detectErrorFromValue;
|
|
7
8
|
exports.diff = diff;
|
|
8
9
|
exports.errorMessagesFromValue = exports.error = void 0;
|
|
@@ -56,33 +57,296 @@ function isRealNum(val) {
|
|
|
56
57
|
}
|
|
57
58
|
return !Number.isNaN(Number(val));
|
|
58
59
|
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
60
|
+
var MONTH_NAME_MAP = {
|
|
61
|
+
january: 1,
|
|
62
|
+
february: 2,
|
|
63
|
+
march: 3,
|
|
64
|
+
april: 4,
|
|
65
|
+
may: 5,
|
|
66
|
+
june: 6,
|
|
67
|
+
july: 7,
|
|
68
|
+
august: 8,
|
|
69
|
+
september: 9,
|
|
70
|
+
october: 10,
|
|
71
|
+
november: 11,
|
|
72
|
+
december: 12,
|
|
73
|
+
jan: 1,
|
|
74
|
+
feb: 2,
|
|
75
|
+
mar: 3,
|
|
76
|
+
apr: 4,
|
|
77
|
+
jun: 6,
|
|
78
|
+
jul: 7,
|
|
79
|
+
aug: 8,
|
|
80
|
+
sep: 9,
|
|
81
|
+
oct: 10,
|
|
82
|
+
nov: 11,
|
|
83
|
+
dec: 12
|
|
84
|
+
};
|
|
85
|
+
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";
|
|
86
|
+
var MONTH_ABBR_RE = "jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec";
|
|
87
|
+
function isValidDateParts(year, month, day) {
|
|
88
|
+
if (year < 1900) return false;
|
|
89
|
+
if (month < 1 || month > 12) return false;
|
|
90
|
+
if (day < 1 || day > 31) return false;
|
|
91
|
+
if (month === 2) {
|
|
92
|
+
var isLeap = new Date(year, 1, 29).getDate() === 29;
|
|
93
|
+
if (isLeap && day > 29) return false;
|
|
94
|
+
if (!isLeap && day > 28) return false;
|
|
64
95
|
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
96
|
+
if ([4, 6, 9, 11].includes(month) && day > 30) return false;
|
|
97
|
+
return true;
|
|
98
|
+
}
|
|
99
|
+
function detectDateFormat(str) {
|
|
100
|
+
if (!str || str.toString().length < 5) return null;
|
|
101
|
+
var s = str.toString().trim();
|
|
102
|
+
var m;
|
|
103
|
+
m = /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2})(?::(\d{2}))?$/.exec(s);
|
|
104
|
+
if (m) {
|
|
105
|
+
var y = +m[1];
|
|
106
|
+
var mo = +m[2];
|
|
107
|
+
var d = +m[3];
|
|
108
|
+
var h = +m[4];
|
|
109
|
+
var mi = +m[5];
|
|
110
|
+
var sec = m[6] != null ? +m[6] : 0;
|
|
111
|
+
if (isValidDateParts(y, mo, d)) {
|
|
112
|
+
return {
|
|
113
|
+
year: y,
|
|
114
|
+
month: mo,
|
|
115
|
+
day: d,
|
|
116
|
+
hours: h,
|
|
117
|
+
minutes: mi,
|
|
118
|
+
seconds: sec,
|
|
119
|
+
formatType: "yyyy-MM-ddTHH:mm"
|
|
120
|
+
};
|
|
121
|
+
}
|
|
70
122
|
}
|
|
71
|
-
|
|
72
|
-
|
|
123
|
+
m = /^(\d{4})-(\d{1,2})-(\d{1,2})(?:\s(\d{1,2}):(\d{2})(?::(\d{2}))?)?$/.exec(s);
|
|
124
|
+
if (m) {
|
|
125
|
+
var y = +m[1];
|
|
126
|
+
var mo = +m[2];
|
|
127
|
+
var d = +m[3];
|
|
128
|
+
if (isValidDateParts(y, mo, d)) {
|
|
129
|
+
var h = m[4] != null ? +m[4] : 0;
|
|
130
|
+
var mi = m[5] != null ? +m[5] : 0;
|
|
131
|
+
var sec = m[6] != null ? +m[6] : 0;
|
|
132
|
+
return {
|
|
133
|
+
year: y,
|
|
134
|
+
month: mo,
|
|
135
|
+
day: d,
|
|
136
|
+
hours: h,
|
|
137
|
+
minutes: mi,
|
|
138
|
+
seconds: sec,
|
|
139
|
+
formatType: m[4] != null ? "yyyy-MM-dd HH:mm" : "yyyy-MM-dd"
|
|
140
|
+
};
|
|
141
|
+
}
|
|
73
142
|
}
|
|
74
|
-
|
|
75
|
-
|
|
143
|
+
m = /^(\d{4})\/(\d{1,2})\/(\d{1,2})(?:\s(\d{1,2}):(\d{2})(?::(\d{2}))?)?$/.exec(s);
|
|
144
|
+
if (m) {
|
|
145
|
+
var y = +m[1];
|
|
146
|
+
var mo = +m[2];
|
|
147
|
+
var d = +m[3];
|
|
148
|
+
if (isValidDateParts(y, mo, d)) {
|
|
149
|
+
var h = m[4] != null ? +m[4] : 0;
|
|
150
|
+
var mi = m[5] != null ? +m[5] : 0;
|
|
151
|
+
var sec = m[6] != null ? +m[6] : 0;
|
|
152
|
+
return {
|
|
153
|
+
year: y,
|
|
154
|
+
month: mo,
|
|
155
|
+
day: d,
|
|
156
|
+
hours: h,
|
|
157
|
+
minutes: mi,
|
|
158
|
+
seconds: sec,
|
|
159
|
+
formatType: m[4] != null ? "yyyy/MM/dd HH:mm" : "yyyy/MM/dd"
|
|
160
|
+
};
|
|
161
|
+
}
|
|
76
162
|
}
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
163
|
+
m = /^(\d{4})\.(\d{1,2})\.(\d{1,2})$/.exec(s);
|
|
164
|
+
if (m) {
|
|
165
|
+
var y = +m[1];
|
|
166
|
+
var mo = +m[2];
|
|
167
|
+
var d = +m[3];
|
|
168
|
+
if (isValidDateParts(y, mo, d)) {
|
|
169
|
+
return {
|
|
170
|
+
year: y,
|
|
171
|
+
month: mo,
|
|
172
|
+
day: d,
|
|
173
|
+
hours: 0,
|
|
174
|
+
minutes: 0,
|
|
175
|
+
seconds: 0,
|
|
176
|
+
formatType: "yyyy.MM.dd"
|
|
177
|
+
};
|
|
80
178
|
}
|
|
81
|
-
|
|
82
|
-
|
|
179
|
+
}
|
|
180
|
+
m = /^(\d{1,2})\/(\d{1,2})\/(\d{4})\s(\d{1,2}):(\d{2})\s?(AM|PM)$/i.exec(s);
|
|
181
|
+
if (m) {
|
|
182
|
+
var p1 = +m[1];
|
|
183
|
+
var p2 = +m[2];
|
|
184
|
+
var y = +m[3];
|
|
185
|
+
var h = +m[4];
|
|
186
|
+
var mi = +m[5];
|
|
187
|
+
var ampm = m[6].toUpperCase();
|
|
188
|
+
if (p1 <= 12 && isValidDateParts(y, p1, p2)) {
|
|
189
|
+
var actualH = h;
|
|
190
|
+
if (ampm === "PM" && h !== 12) actualH = h + 12;
|
|
191
|
+
if (ampm === "AM" && h === 12) actualH = 0;
|
|
192
|
+
return {
|
|
193
|
+
year: y,
|
|
194
|
+
month: p1,
|
|
195
|
+
day: p2,
|
|
196
|
+
hours: actualH,
|
|
197
|
+
minutes: mi,
|
|
198
|
+
seconds: 0,
|
|
199
|
+
formatType: "MM/dd/yyyy h:mm AM/PM"
|
|
200
|
+
};
|
|
83
201
|
}
|
|
84
202
|
}
|
|
85
|
-
|
|
203
|
+
m = /^(\d{1,2})\/(\d{1,2})\/(\d{4})$/.exec(s);
|
|
204
|
+
if (m) {
|
|
205
|
+
var p1 = +m[1];
|
|
206
|
+
var p2 = +m[2];
|
|
207
|
+
var y = +m[3];
|
|
208
|
+
if (p1 > 12 && isValidDateParts(y, p2, p1)) {
|
|
209
|
+
return {
|
|
210
|
+
year: y,
|
|
211
|
+
month: p2,
|
|
212
|
+
day: p1,
|
|
213
|
+
hours: 0,
|
|
214
|
+
minutes: 0,
|
|
215
|
+
seconds: 0,
|
|
216
|
+
formatType: "dd/MM/yyyy"
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
if (p2 > 12 && p1 <= 12 && isValidDateParts(y, p1, p2)) {
|
|
220
|
+
var formatType = m[1].length === 1 ? "M/d/yyyy" : "MM/dd/yyyy";
|
|
221
|
+
return {
|
|
222
|
+
year: y,
|
|
223
|
+
month: p1,
|
|
224
|
+
day: p2,
|
|
225
|
+
hours: 0,
|
|
226
|
+
minutes: 0,
|
|
227
|
+
seconds: 0,
|
|
228
|
+
formatType: formatType
|
|
229
|
+
};
|
|
230
|
+
}
|
|
231
|
+
if (p1 <= 12 && p2 <= 31 && isValidDateParts(y, p1, p2)) {
|
|
232
|
+
var formatType = m[1].length === 1 ? "M/d/yyyy" : "MM/dd/yyyy";
|
|
233
|
+
return {
|
|
234
|
+
year: y,
|
|
235
|
+
month: p1,
|
|
236
|
+
day: p2,
|
|
237
|
+
hours: 0,
|
|
238
|
+
minutes: 0,
|
|
239
|
+
seconds: 0,
|
|
240
|
+
formatType: formatType
|
|
241
|
+
};
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
m = /^(\d{2})\/(\d{2})\/(\d{2})$/.exec(s);
|
|
245
|
+
if (m) {
|
|
246
|
+
var p1 = +m[1];
|
|
247
|
+
var p2 = +m[2];
|
|
248
|
+
var y = 2000 + +m[3];
|
|
249
|
+
if (p1 <= 12 && p2 <= 31 && isValidDateParts(y, p1, p2)) {
|
|
250
|
+
return {
|
|
251
|
+
year: y,
|
|
252
|
+
month: p1,
|
|
253
|
+
day: p2,
|
|
254
|
+
hours: 0,
|
|
255
|
+
minutes: 0,
|
|
256
|
+
seconds: 0,
|
|
257
|
+
formatType: "MM/dd/yy"
|
|
258
|
+
};
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
m = /^(\d{1,2})-(\d{1,2})-(\d{4})$/.exec(s);
|
|
262
|
+
if (m) {
|
|
263
|
+
var p1 = +m[1];
|
|
264
|
+
var p2 = +m[2];
|
|
265
|
+
var y = +m[3];
|
|
266
|
+
if (p1 > 12 && isValidDateParts(y, p2, p1)) {
|
|
267
|
+
return {
|
|
268
|
+
year: y,
|
|
269
|
+
month: p2,
|
|
270
|
+
day: p1,
|
|
271
|
+
hours: 0,
|
|
272
|
+
minutes: 0,
|
|
273
|
+
seconds: 0,
|
|
274
|
+
formatType: "dd-MM-yyyy"
|
|
275
|
+
};
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
m = /^(\d{1,2})\.(\d{1,2})\.(\d{4})$/.exec(s);
|
|
279
|
+
if (m) {
|
|
280
|
+
var p1 = +m[1];
|
|
281
|
+
var p2 = +m[2];
|
|
282
|
+
var y = +m[3];
|
|
283
|
+
if (p1 > 12 && isValidDateParts(y, p2, p1)) {
|
|
284
|
+
return {
|
|
285
|
+
year: y,
|
|
286
|
+
month: p2,
|
|
287
|
+
day: p1,
|
|
288
|
+
hours: 0,
|
|
289
|
+
minutes: 0,
|
|
290
|
+
seconds: 0,
|
|
291
|
+
formatType: "dd.MM.yyyy"
|
|
292
|
+
};
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
m = new RegExp("^(".concat(MONTH_NAMES_RE, ")\\s+(\\d{1,2}),?\\s+(\\d{4})$"), "i").exec(s);
|
|
296
|
+
if (m) {
|
|
297
|
+
var mo = MONTH_NAME_MAP[m[1].toLowerCase()];
|
|
298
|
+
var d = +m[2];
|
|
299
|
+
var y = +m[3];
|
|
300
|
+
if (mo && isValidDateParts(y, mo, d)) {
|
|
301
|
+
return {
|
|
302
|
+
year: y,
|
|
303
|
+
month: mo,
|
|
304
|
+
day: d,
|
|
305
|
+
hours: 0,
|
|
306
|
+
minutes: 0,
|
|
307
|
+
seconds: 0,
|
|
308
|
+
formatType: "named"
|
|
309
|
+
};
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
m = new RegExp("^(\\d{1,2})\\s+(".concat(MONTH_NAMES_RE, ")\\s+(\\d{4})$"), "i").exec(s);
|
|
313
|
+
if (m) {
|
|
314
|
+
var d = +m[1];
|
|
315
|
+
var mo = MONTH_NAME_MAP[m[2].toLowerCase()];
|
|
316
|
+
var y = +m[3];
|
|
317
|
+
if (mo && isValidDateParts(y, mo, d)) {
|
|
318
|
+
return {
|
|
319
|
+
year: y,
|
|
320
|
+
month: mo,
|
|
321
|
+
day: d,
|
|
322
|
+
hours: 0,
|
|
323
|
+
minutes: 0,
|
|
324
|
+
seconds: 0,
|
|
325
|
+
formatType: "named"
|
|
326
|
+
};
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
m = new RegExp("^(".concat(MONTH_ABBR_RE, ")-(\\d{1,2})-(\\d{4})$"), "i").exec(s);
|
|
330
|
+
if (m) {
|
|
331
|
+
var mo = MONTH_NAME_MAP[m[1].toLowerCase()];
|
|
332
|
+
var d = +m[2];
|
|
333
|
+
var y = +m[3];
|
|
334
|
+
if (mo && isValidDateParts(y, mo, d)) {
|
|
335
|
+
return {
|
|
336
|
+
year: y,
|
|
337
|
+
month: mo,
|
|
338
|
+
day: d,
|
|
339
|
+
hours: 0,
|
|
340
|
+
minutes: 0,
|
|
341
|
+
seconds: 0,
|
|
342
|
+
formatType: "named"
|
|
343
|
+
};
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
return null;
|
|
347
|
+
}
|
|
348
|
+
function checkDateTime(str) {
|
|
349
|
+
return detectDateFormat(str) !== null;
|
|
86
350
|
}
|
|
87
351
|
function isdatetime(s) {
|
|
88
352
|
if (s === null || s.toString().length < 5) {
|