MCPcopy Create free account
hub / github.com/chhoumann/quickadd / parseVDateOptions

Function parseVDateOptions

src/utils/vdateSyntax.ts:28–89  ·  view source on GitHub ↗
(
	rawOptions: string | undefined | null,
)

Source from the content-addressed store, hash-verified

26 * insensitive: `|tomorrow|optional` === `|optional|tomorrow`.
27 */
28export 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,

Calls 6

extractBareFlagPartFunction · 0.90
splitPipePartsFunction · 0.90
parsePipeKeyValueFunction · 0.90
parseBooleanFlagFunction · 0.90
normalizeDateUnitFunction · 0.90
pushMethod · 0.80

Tested by

no test coverage detected