@magmonium/one 0.4.95 → 0.4.96
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.
|
@@ -1843,10 +1843,11 @@ const requiredValidation = (s, paths) => paths.forEach((path) => {
|
|
|
1843
1843
|
} : null;
|
|
1844
1844
|
});
|
|
1845
1845
|
});
|
|
1846
|
-
const
|
|
1847
|
-
const
|
|
1848
|
-
const
|
|
1849
|
-
const
|
|
1846
|
+
const readLimit = (limit) => typeof limit === "function" ? limit() : limit;
|
|
1847
|
+
const minLengthValidation = (s, paths, len) => paths.forEach((path) => minLength(s[path], () => readLimit(len), { message: () => `min-length?len=${readLimit(len)}` }));
|
|
1848
|
+
const maxLengthValidation = (s, paths, len) => paths.forEach((path) => maxLength(s[path], () => readLimit(len), { message: () => `max-length?len=${readLimit(len)}` }));
|
|
1849
|
+
const minValidation = (s, paths, limit) => paths.forEach((path) => min(s[path], () => readLimit(limit), { message: () => `min-length?len=${readLimit(limit)}` }));
|
|
1850
|
+
const maxValidation = (s, paths, limit) => paths.forEach((path) => max(s[path], () => readLimit(limit), { message: () => `max-length?len=${readLimit(limit)}` }));
|
|
1850
1851
|
const manualValidation = (errorMap) => errorMap.forEach(({ error, path }) => validate(path, () => {
|
|
1851
1852
|
const message = error();
|
|
1852
1853
|
return message ? {
|
|
@@ -1857,15 +1858,17 @@ const manualValidation = (errorMap) => errorMap.forEach(({ error, path }) => val
|
|
|
1857
1858
|
const minAgeValidation = (schemaPath, minAge, dateFormat = "YYYY-MM-DD") => validate(schemaPath, (ctx) => {
|
|
1858
1859
|
const value = ctx.value();
|
|
1859
1860
|
if (!value) return null;
|
|
1861
|
+
const limit = readLimit(minAge);
|
|
1862
|
+
if (limit === void 0) return null;
|
|
1860
1863
|
const birthDate = parseDate(value, dateFormat);
|
|
1861
1864
|
if (!birthDate) return null;
|
|
1862
1865
|
const today = /* @__PURE__ */ new Date();
|
|
1863
1866
|
const age = today.getFullYear() - birthDate.getFullYear();
|
|
1864
1867
|
const monthDiff = today.getMonth() - birthDate.getMonth();
|
|
1865
1868
|
const dayDiff = today.getDate() - birthDate.getDate();
|
|
1866
|
-
return (monthDiff < 0 || monthDiff === 0 && dayDiff < 0 ? age - 1 : age) <
|
|
1869
|
+
return (monthDiff < 0 || monthDiff === 0 && dayDiff < 0 ? age - 1 : age) < limit ? {
|
|
1867
1870
|
kind: "minAge",
|
|
1868
|
-
message: `min-age?age=${
|
|
1871
|
+
message: `min-age?age=${limit}`
|
|
1869
1872
|
} : null;
|
|
1870
1873
|
});
|
|
1871
1874
|
const matchFieldValidation = (schemaPath, matchSchemaPath, fieldLabel) => validate(schemaPath, (ctx) => {
|