MCPcopy Index your code
hub / github.com/bombshell-dev/clack / validParts

Function validParts

packages/core/src/prompts/date.ts:65–74  ·  view source on GitHub ↗

Validate and return calendar parts, or undefined if invalid

(parts: DateParts)

Source from the content-addressed store, hash-verified

63
64/** Validate and return calendar parts, or undefined if invalid */
65function validParts(parts: DateParts): { year: number; month: number; day: number } | undefined {
66 const { year, month, day } = parse(parts);
67 if (!year || year < 0 || year > 9999) return undefined;
68 if (!month || month < 1 || month > 12) return undefined;
69 if (!day || day < 1) return undefined;
70 const d = new Date(Date.UTC(year, month - 1, day));
71 if (d.getUTCFullYear() !== year || d.getUTCMonth() !== month - 1 || d.getUTCDate() !== day)
72 return undefined;
73 return { year, month, day };
74}
75
76function toDate(parts: DateParts): Date | undefined {
77 const p = validParts(parts);

Callers 2

toDateFunction · 0.85
#onKeyMethod · 0.85

Calls 1

parseFunction · 0.85

Tested by

no test coverage detected