@formkit/tempo 1.1.2 → 1.3.0
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/bundle.d.ts +1 -7
- package/dist/bundle.mjs +20 -6
- package/dist/bundle.mjs.map +1 -1
- package/dist/common.mjs +3 -2
- package/dist/common.mjs.map +1 -1
- package/dist/index.cjs +20 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -7
- package/dist/parse.d.ts +1 -7
- package/dist/parse.mjs +17 -4
- package/dist/parse.mjs.map +1 -1
- package/package.json +1 -1
package/dist/bundle.d.ts
CHANGED
|
@@ -410,13 +410,7 @@ declare function offset(utcTime?: MaybeDateInput, tzA?: string, tzB?: string, ti
|
|
|
410
410
|
|
|
411
411
|
declare function parse(options: ParseOptions): Date | never;
|
|
412
412
|
declare function parse(dateStr: string, format?: Format, locale?: string): Date | never;
|
|
413
|
-
|
|
414
|
-
* Given a string date and corresponding format parts, fill the parts with the
|
|
415
|
-
* data from the string.
|
|
416
|
-
* @param dateStr - A string to parse.
|
|
417
|
-
* @param formatParts - The expected parts of the given string.
|
|
418
|
-
*/
|
|
419
|
-
declare function parseParts(dateStr: string, formatParts: Part[]): FilledPart[];
|
|
413
|
+
declare function parseParts(dateStr: string, formatParts: Part[], strict?: boolean): FilledPart[];
|
|
420
414
|
|
|
421
415
|
/**
|
|
422
416
|
* Given a format string, produce an array of matching "parts", each part
|
package/dist/bundle.mjs
CHANGED
|
@@ -383,8 +383,9 @@ function isNumeric(part) {
|
|
|
383
383
|
}
|
|
384
384
|
function validate(parts2) {
|
|
385
385
|
let lastPart = void 0;
|
|
386
|
-
|
|
387
|
-
|
|
386
|
+
const knownWidth = (p) => !p || p.partName === "literal" || p.token in fixedLength;
|
|
387
|
+
for (const [i, part] of parts2.entries()) {
|
|
388
|
+
if (part.partName === "literal" && !isNaN(parseFloat(part.partValue)) && !(knownWidth(parts2[i - 1]) && knownWidth(parts2[i + 1]))) {
|
|
388
389
|
throw new Error(`Numbers in format (${part.partValue}).`);
|
|
389
390
|
}
|
|
390
391
|
if (lastPart && lastPart.partName !== "literal" && part.partName !== "literal") {
|
|
@@ -905,11 +906,16 @@ function parse(dateStrOrOptions, format2 = "ISO8601", locale = "device") {
|
|
|
905
906
|
};
|
|
906
907
|
if (format2 === "ISO8601") return date(dateStr);
|
|
907
908
|
const genitive = styles.includes(format2) || typeof format2 === "object";
|
|
908
|
-
const
|
|
909
|
+
const allParts = parts(format2, locale);
|
|
910
|
+
const formatParts = validate(allParts.filter(partFilter));
|
|
909
911
|
if (!formatParts.length) throw new Error("parse() requires a pattern.");
|
|
910
912
|
let parsedParts;
|
|
911
913
|
try {
|
|
912
|
-
parsedParts = parseParts(
|
|
914
|
+
parsedParts = parseParts(
|
|
915
|
+
dateStr,
|
|
916
|
+
formatParts,
|
|
917
|
+
formatParts.length === allParts.length
|
|
918
|
+
);
|
|
913
919
|
} catch {
|
|
914
920
|
return invalid();
|
|
915
921
|
}
|
|
@@ -996,7 +1002,10 @@ function parse(dateStrOrOptions, format2 = "ISO8601", locale = "device") {
|
|
|
996
1002
|
if (isFinite(+d)) return d;
|
|
997
1003
|
return invalid();
|
|
998
1004
|
}
|
|
999
|
-
function
|
|
1005
|
+
function normalizeLiteral(literal) {
|
|
1006
|
+
return literal.normalize("NFKC").replace(/\s/g, " ").toLowerCase();
|
|
1007
|
+
}
|
|
1008
|
+
function parseParts(dateStr, formatParts, strict = false) {
|
|
1000
1009
|
let i = 0;
|
|
1001
1010
|
const advance = (parts2) => [
|
|
1002
1011
|
parts2[i++],
|
|
@@ -1039,9 +1048,14 @@ function parseParts(dateStr, formatParts) {
|
|
|
1039
1048
|
} else {
|
|
1040
1049
|
len = dateStr.length;
|
|
1041
1050
|
}
|
|
1042
|
-
|
|
1051
|
+
const value = dateStr.substring(pos, pos + len);
|
|
1052
|
+
if (strict && current.partName === "literal" && normalizeLiteral(value) !== normalizeLiteral(current.partValue)) {
|
|
1053
|
+
throw new Error();
|
|
1054
|
+
}
|
|
1055
|
+
parsed.push({ ...current, value });
|
|
1043
1056
|
pos += len;
|
|
1044
1057
|
} while (n);
|
|
1058
|
+
if (strict && pos < dateStr.length) throw new Error();
|
|
1045
1059
|
return parsed;
|
|
1046
1060
|
}
|
|
1047
1061
|
|