( rawOptions: string | undefined | null, )
| 26 | * insensitive: `|tomorrow|optional` === `|optional|tomorrow`. |
| 27 | */ |
| 28 | export function parseVDateOptions( |
| 29 | rawOptions: string | undefined | null, |
| 30 | ): ParsedVDateOptions { |
| 31 | if (!rawOptions) return { optional: false, withTime: false }; |
| 32 | |
| 33 | // Pull the bare control flags out before re-joining the rest as the default, |
| 34 | // so a legacy pipe-containing natural-language default still survives. Order |
| 35 | // is insensitive (same approach as |optional). A literal default of exactly |
| 36 | // "time"/"datetime" needs the |default-style escape — vanishingly rare. |
| 37 | const { remaining: afterOptional, found: bareOptional } = extractBareFlagPart( |
| 38 | splitPipeParts(rawOptions), |
| 39 | "optional", |
| 40 | ); |
| 41 | const { remaining: afterTime, found: bareTime } = extractBareFlagPart( |
| 42 | afterOptional, |
| 43 | "time", |
| 44 | ); |
| 45 | const { remaining, found: bareDatetime } = extractBareFlagPart( |
| 46 | afterTime, |
| 47 | "datetime", |
| 48 | ); |
| 49 | |
| 50 | let explicitOptional: boolean | undefined; |
| 51 | let keyedDatetime = false; |
| 52 | let snap: DateSnap | undefined; |
| 53 | const rest: string[] = []; |
| 54 | |
| 55 | for (const part of remaining) { |
| 56 | const keyed = parsePipeKeyValue(part.trim()); |
| 57 | if (keyed?.key === "optional") { |
| 58 | explicitOptional = parseBooleanFlag(keyed.value); |
| 59 | continue; |
| 60 | } |
| 61 | if (keyed?.key === "type") { |
| 62 | // |type:datetime enables the time picker; any keyed |type:... is a |
| 63 | // control flag, never part of the natural-language default. |
| 64 | if (keyed.value.trim().toLowerCase() === "datetime") keyedDatetime = true; |
| 65 | continue; |
| 66 | } |
| 67 | if (keyed?.key === "startof" || keyed?.key === "endof") { |
| 68 | // |startof:<unit> / |endof:<unit> snap the resolved date (issue #511). |
| 69 | // First wins; a bad unit throws. Never part of the default value. |
| 70 | if (!snap) { |
| 71 | snap = { |
| 72 | boundary: keyed.key === "startof" ? "start" : "end", |
| 73 | unit: normalizeDateUnit(keyed.value), |
| 74 | }; |
| 75 | } |
| 76 | continue; |
| 77 | } |
| 78 | |
| 79 | rest.push(part); |
| 80 | } |
| 81 | |
| 82 | const defaultValue = rest.join("|").trim() || undefined; |
| 83 | return { |
| 84 | defaultValue, |
| 85 | optional: explicitOptional ?? bareOptional, |
no test coverage detected