MCPcopy
hub / github.com/bombshell-dev/clack / validate

Function validate

packages/prompts/src/date.ts:82–97  ·  view source on GitHub ↗
(value: Date | undefined)

Source from the content-addressed store, hash-verified

80 return new DatePrompt({
81 ...opts,
82 validate(value: Date | undefined) {
83 if (value === undefined) {
84 if (opts.defaultValue !== undefined) return undefined;
85 if (validate) return runValidation(validate, value);
86 return settings.date.messages.required;
87 }
88 const iso = (d: Date) => d.toISOString().slice(0, 10);
89 if (opts.minDate && iso(value) < iso(opts.minDate)) {
90 return settings.date.messages.afterMin(opts.minDate);
91 }
92 if (opts.maxDate && iso(value) > iso(opts.maxDate)) {
93 return settings.date.messages.beforeMax(opts.maxDate);
94 }
95 if (validate) return runValidation(validate, value);
96 return undefined;
97 },
98 render() {
99 const hasGuide = (opts?.withGuide ?? settings.withGuide) !== false;
100 const titlePrefix = `${hasGuide ? `${styleText('gray', S_BAR)}\n` : ''}${symbol(this.state)} `;

Callers 1

runValidationFunction · 0.50

Calls 2

runValidationFunction · 0.90
isoFunction · 0.85

Tested by

no test coverage detected