@ciwergrp/nuxid 1.10.0 → 1.11.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/module.json +1 -1
- package/dist/runtime/helper/date/format.d.ts +2 -29
- package/dist/runtime/helper/date/format.js +1 -29
- package/dist/runtime/helper/date/parse.js +1 -2
- package/docs/.docs/form-validation/create-validation-rules.md +11 -0
- package/docs/.docs/form-validation/quick-start.md +14 -0
- package/docs/.docs/form-validation/rules.md +42 -4
- package/package.json +1 -1
package/dist/module.json
CHANGED
|
@@ -1,33 +1,7 @@
|
|
|
1
1
|
import type { FormatDistanceOptions, FormatDistanceToNowOptions, FormatISOOptions, FormatOptions, FormatRFC3339Options } from 'date-fns';
|
|
2
2
|
import type { DateInput } from './input.js';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
readonly 'YYYY-MM-DD HH:mm': "yyyy-MM-dd HH:mm";
|
|
6
|
-
readonly 'YYYY-MM-DD HH:mm:ss': "yyyy-MM-dd HH:mm:ss";
|
|
7
|
-
readonly 'YYYY-MM-DD HH:mm:ss.SSS': "yyyy-MM-dd HH:mm:ss.SSS";
|
|
8
|
-
readonly 'YYYY-MM-DD HH:mm:ssZ': "yyyy-MM-dd HH:mm:ssXXX";
|
|
9
|
-
readonly 'YYYY-MM-DD HH:mm:ss.SSSZ': "yyyy-MM-dd HH:mm:ss.SSSXXX";
|
|
10
|
-
readonly 'YYYY/MM/DD': "yyyy/MM/dd";
|
|
11
|
-
readonly 'YYYY/MM/DD HH:mm': "yyyy/MM/dd HH:mm";
|
|
12
|
-
readonly 'YYYY/MM/DD HH:mm:ss': "yyyy/MM/dd HH:mm:ss";
|
|
13
|
-
readonly 'DD/MM/YYYY': "dd/MM/yyyy";
|
|
14
|
-
readonly 'MM/DD/YYYY': "MM/dd/yyyy";
|
|
15
|
-
readonly 'DD-MM-YYYY': "dd-MM-yyyy";
|
|
16
|
-
readonly 'MM-DD-YYYY': "MM-dd-yyyy";
|
|
17
|
-
readonly 'YYYY-MM': "yyyy-MM";
|
|
18
|
-
readonly 'YYYY/MM': "yyyy/MM";
|
|
19
|
-
readonly YYYY: "yyyy";
|
|
20
|
-
readonly 'DD MMM YYYY': "dd MMM yyyy";
|
|
21
|
-
readonly 'MMM DD, YYYY': "MMM dd, yyyy";
|
|
22
|
-
readonly 'HH:mm': "HH:mm";
|
|
23
|
-
readonly 'HH:mm:ss': "HH:mm:ss";
|
|
24
|
-
readonly 'HH:mm:ss.SSS': "HH:mm:ss.SSS";
|
|
25
|
-
readonly 'hh:mm A': "hh:mm a";
|
|
26
|
-
readonly 'hh:mm:ss A': "hh:mm:ss a";
|
|
27
|
-
};
|
|
28
|
-
export type DateFormatPreset = keyof typeof formatAliases;
|
|
29
|
-
export type DateFormatInput = DateFormatPreset | (string & {});
|
|
30
|
-
export declare function resolveFormatString(formatString: DateFormatInput): "yyyy-MM-dd" | "yyyy-MM-dd HH:mm" | "yyyy-MM-dd HH:mm:ss" | "yyyy-MM-dd HH:mm:ss.SSS" | "yyyy-MM-dd HH:mm:ssXXX" | "yyyy-MM-dd HH:mm:ss.SSSXXX" | "yyyy/MM/dd" | "yyyy/MM/dd HH:mm" | "yyyy/MM/dd HH:mm:ss" | "dd/MM/yyyy" | "MM/dd/yyyy" | "dd-MM-yyyy" | "MM-dd-yyyy" | "yyyy-MM" | "yyyy/MM" | "yyyy" | "dd MMM yyyy" | "MMM dd, yyyy" | "HH:mm" | "HH:mm:ss" | "HH:mm:ss.SSS" | "hh:mm a" | "hh:mm:ss a";
|
|
3
|
+
export type DateFormatPreset = string;
|
|
4
|
+
export type DateFormatInput = string;
|
|
31
5
|
export declare function format(date: DateInput, formatString: DateFormatInput, options?: FormatOptions): string;
|
|
32
6
|
export declare function formatISO(date: DateInput, options?: FormatISOOptions): string;
|
|
33
7
|
export declare function formatRFC3339(date: DateInput, options?: FormatRFC3339Options): string;
|
|
@@ -40,4 +14,3 @@ export declare function toDateTimeString(date: DateInput): string;
|
|
|
40
14
|
export declare function toIsoString(date: DateInput): string;
|
|
41
15
|
export declare function toRfc3339String(date: DateInput): string;
|
|
42
16
|
export declare function toRfc7231String(date: DateInput): string;
|
|
43
|
-
export {};
|
|
@@ -7,36 +7,8 @@ import {
|
|
|
7
7
|
formatRFC7231 as formatRFC7231Date
|
|
8
8
|
} from "date-fns";
|
|
9
9
|
import { toDate } from "./input.js";
|
|
10
|
-
const formatAliases = {
|
|
11
|
-
"YYYY-MM-DD": "yyyy-MM-dd",
|
|
12
|
-
"YYYY-MM-DD HH:mm": "yyyy-MM-dd HH:mm",
|
|
13
|
-
"YYYY-MM-DD HH:mm:ss": "yyyy-MM-dd HH:mm:ss",
|
|
14
|
-
"YYYY-MM-DD HH:mm:ss.SSS": "yyyy-MM-dd HH:mm:ss.SSS",
|
|
15
|
-
"YYYY-MM-DD HH:mm:ssZ": "yyyy-MM-dd HH:mm:ssXXX",
|
|
16
|
-
"YYYY-MM-DD HH:mm:ss.SSSZ": "yyyy-MM-dd HH:mm:ss.SSSXXX",
|
|
17
|
-
"YYYY/MM/DD": "yyyy/MM/dd",
|
|
18
|
-
"YYYY/MM/DD HH:mm": "yyyy/MM/dd HH:mm",
|
|
19
|
-
"YYYY/MM/DD HH:mm:ss": "yyyy/MM/dd HH:mm:ss",
|
|
20
|
-
"DD/MM/YYYY": "dd/MM/yyyy",
|
|
21
|
-
"MM/DD/YYYY": "MM/dd/yyyy",
|
|
22
|
-
"DD-MM-YYYY": "dd-MM-yyyy",
|
|
23
|
-
"MM-DD-YYYY": "MM-dd-yyyy",
|
|
24
|
-
"YYYY-MM": "yyyy-MM",
|
|
25
|
-
"YYYY/MM": "yyyy/MM",
|
|
26
|
-
"YYYY": "yyyy",
|
|
27
|
-
"DD MMM YYYY": "dd MMM yyyy",
|
|
28
|
-
"MMM DD, YYYY": "MMM dd, yyyy",
|
|
29
|
-
"HH:mm": "HH:mm",
|
|
30
|
-
"HH:mm:ss": "HH:mm:ss",
|
|
31
|
-
"HH:mm:ss.SSS": "HH:mm:ss.SSS",
|
|
32
|
-
"hh:mm A": "hh:mm a",
|
|
33
|
-
"hh:mm:ss A": "hh:mm:ss a"
|
|
34
|
-
};
|
|
35
|
-
export function resolveFormatString(formatString) {
|
|
36
|
-
return formatAliases[formatString] ?? formatString;
|
|
37
|
-
}
|
|
38
10
|
export function format(date, formatString, options) {
|
|
39
|
-
return formatDate(toDate(date),
|
|
11
|
+
return formatDate(toDate(date), formatString, options);
|
|
40
12
|
}
|
|
41
13
|
export function formatISO(date, options) {
|
|
42
14
|
return formatISODate(toDate(date), options);
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { parse as parseDate, parseISO as parseISODate } from "date-fns";
|
|
2
|
-
import { resolveFormatString } from "./format.js";
|
|
3
2
|
import { toDate } from "./input.js";
|
|
4
3
|
export function parse(value, formatString, baseDate = /* @__PURE__ */ new Date(), options) {
|
|
5
|
-
return parseDate(value,
|
|
4
|
+
return parseDate(value, formatString, toDate(baseDate), options);
|
|
6
5
|
}
|
|
7
6
|
export function parseISO(value) {
|
|
8
7
|
return parseISODate(value);
|
|
@@ -62,6 +62,17 @@ const definitions = {
|
|
|
62
62
|
|
|
63
63
|
Optional configuration for messages, attributes, and hooks.
|
|
64
64
|
|
|
65
|
+
## Date and Time Comparison Behavior
|
|
66
|
+
|
|
67
|
+
Rules `gt`, `gte`, `lt`, and `lte` use type-aware parsing:
|
|
68
|
+
|
|
69
|
+
- `time` (supports `HH:mm`, optional seconds/milliseconds, optional `Z`/offset)
|
|
70
|
+
- `date` (`YYYY-MM-DD`)
|
|
71
|
+
- `datetime` (date + time, optional `Z`/offset)
|
|
72
|
+
- numeric fallback
|
|
73
|
+
|
|
74
|
+
For `time`, offset-aware and non-offset values cannot be mixed in one comparison.
|
|
75
|
+
|
|
65
76
|
### options.messages
|
|
66
77
|
- Summary: Custom error messages for specific rule keys.
|
|
67
78
|
- Technique: Lookup key format is `{field}.{rule}`.
|
|
@@ -64,4 +64,18 @@ const rules = createValidationRules(
|
|
|
64
64
|
)
|
|
65
65
|
```
|
|
66
66
|
|
|
67
|
+
## Time and Datetime Example
|
|
68
|
+
|
|
69
|
+
```ts
|
|
70
|
+
const rules = createValidationRules(
|
|
71
|
+
{
|
|
72
|
+
start_time: ['required', 'time'],
|
|
73
|
+
end_time: ['required', 'time', 'gte:start_time'],
|
|
74
|
+
starts_at: ['required', 'datetime'],
|
|
75
|
+
ends_at: ['required', 'datetime', 'gte:starts_at'],
|
|
76
|
+
},
|
|
77
|
+
form,
|
|
78
|
+
)
|
|
79
|
+
```
|
|
80
|
+
|
|
67
81
|
See the full list of supported rules on the [Available Rules](/form-validation/rules) page.
|
|
@@ -237,6 +237,42 @@ Notes:
|
|
|
237
237
|
- Use: `'digits_between:6,8'`
|
|
238
238
|
- Example: `['digits_between:6,8']`
|
|
239
239
|
|
|
240
|
+
### time
|
|
241
|
+
- Summary: Must be a valid time string.
|
|
242
|
+
- Technique: Supports strict `HH:mm`, optional seconds/milliseconds, and optional timezone offset.
|
|
243
|
+
- Use: `'time'`
|
|
244
|
+
- Example: `['time']`
|
|
245
|
+
- Supported formats:
|
|
246
|
+
- `HH:mm`
|
|
247
|
+
- `HH:mm:ss`
|
|
248
|
+
- `HH:mm:ss.SSS`
|
|
249
|
+
- `HH:mmZ`
|
|
250
|
+
- `HH:mm:ssZ`
|
|
251
|
+
- `HH:mm:ss.SSSZ`
|
|
252
|
+
- `HH:mm±HHmm`
|
|
253
|
+
- `HH:mm:ss±HHmm`
|
|
254
|
+
- `HH:mm:ss.SSS±HHmm`
|
|
255
|
+
- Offset notes:
|
|
256
|
+
- `Z` means UTC (example: `09:30Z`).
|
|
257
|
+
- `±HH:MM` and `±HHmm` are both accepted (examples: `+07:00`, `-0530`).
|
|
258
|
+
|
|
259
|
+
### datetime
|
|
260
|
+
- Summary: Must be a valid datetime string.
|
|
261
|
+
- Technique: Strict date + time parser with optional timezone offset.
|
|
262
|
+
- Use: `'datetime'`
|
|
263
|
+
- Example: `['datetime']`
|
|
264
|
+
- Supported formats:
|
|
265
|
+
- `YYYY-MM-DDTHH:mm`
|
|
266
|
+
- `YYYY-MM-DD HH:mm`
|
|
267
|
+
- `YYYY-MM-DDTHH:mm:ss`
|
|
268
|
+
- `YYYY-MM-DD HH:mm:ss`
|
|
269
|
+
- `YYYY-MM-DDTHH:mm:ss.SSS`
|
|
270
|
+
- `YYYY-MM-DD HH:mm:ss.SSS`
|
|
271
|
+
- Datetime timezone suffix (optional for each format):
|
|
272
|
+
- `Z`
|
|
273
|
+
- `±HH:MM`
|
|
274
|
+
- `±HHmm`
|
|
275
|
+
|
|
240
276
|
### bail
|
|
241
277
|
- Summary: Placeholder (no-op).
|
|
242
278
|
- Technique: No behavior; included for parity.
|
|
@@ -245,27 +281,29 @@ Notes:
|
|
|
245
281
|
|
|
246
282
|
### gt:field
|
|
247
283
|
- Summary: Must be greater than another field.
|
|
248
|
-
- Technique:
|
|
284
|
+
- Technique: Type-aware comparison in this order: `time` -> `date` (`YYYY-MM-DD`) -> `datetime` -> numeric.
|
|
249
285
|
- Use: `'gt:other'`
|
|
250
286
|
- Example: `['gt:other']`
|
|
251
287
|
|
|
252
288
|
### gte:field
|
|
253
289
|
- Summary: Must be greater than or equal to another field.
|
|
254
|
-
- Technique:
|
|
290
|
+
- Technique: Type-aware comparison in this order: `time` -> `date` (`YYYY-MM-DD`) -> `datetime` -> numeric.
|
|
255
291
|
- Use: `'gte:other'`
|
|
256
292
|
- Example: `['gte:other']`
|
|
257
293
|
|
|
258
294
|
### lt:field
|
|
259
295
|
- Summary: Must be less than another field.
|
|
260
|
-
- Technique:
|
|
296
|
+
- Technique: Type-aware comparison in this order: `time` -> `date` (`YYYY-MM-DD`) -> `datetime` -> numeric.
|
|
261
297
|
- Use: `'lt:other'`
|
|
262
298
|
- Example: `['lt:other']`
|
|
263
299
|
|
|
264
300
|
### lte:field
|
|
265
301
|
- Summary: Must be less than or equal to another field.
|
|
266
|
-
- Technique:
|
|
302
|
+
- Technique: Type-aware comparison in this order: `time` -> `date` (`YYYY-MM-DD`) -> `datetime` -> numeric.
|
|
267
303
|
- Use: `'lte:other'`
|
|
268
304
|
- Example: `['lte:other']`
|
|
305
|
+
- Comparison notes:
|
|
306
|
+
- For `time`, comparing offset-aware values against non-offset values fails (both sides must either include offset or not).
|
|
269
307
|
|
|
270
308
|
### starts_with:a,b,c
|
|
271
309
|
- Summary: Must start with any of the given prefixes.
|