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

Method constructor

packages/core/src/prompts/date.ts:171–200  ·  view source on GitHub ↗
(opts: DateOptions)

Source from the content-addressed store, hash-verified

169 }
170
171 constructor(opts: DateOptions) {
172 const detected = opts.format
173 ? { segments: segmentsFor(opts.format), separator: opts.separator ?? '/' }
174 : detectLocaleFormat(opts.locale);
175 const sep = opts.separator ?? detected.separator;
176 const segments = opts.format ? segmentsFor(opts.format) : detected.segments;
177
178 const initialDate = opts.initialValue ?? opts.defaultValue;
179 const segmentValues: DateParts = initialDate
180 ? {
181 year: String(initialDate.getUTCFullYear()).padStart(4, '0'),
182 month: String(initialDate.getUTCMonth() + 1).padStart(2, '0'),
183 day: String(initialDate.getUTCDate()).padStart(2, '0'),
184 }
185 : { year: '____', month: '__', day: '__' };
186
187 const initialDisplay = segments.map((s) => segmentValues[s.type]).join(sep);
188
189 super({ ...opts, initialUserInput: initialDisplay }, false);
190 this.#segments = segments;
191 this.#separator = sep;
192 this.#segmentValues = segmentValues;
193 this.#minDate = opts.minDate;
194 this.#maxDate = opts.maxDate;
195 this.#refresh();
196
197 this.on('cursor', (key) => this.#onCursor(key));
198 this.on('key', (char, key) => this.#onKey(char, key));
199 this.on('finalize', () => this.#onFinalize(opts));
200 }
201
202 #seg(): { segment: SegmentConfig; index: number } | undefined {
203 const index = Math.max(0, Math.min(this.#cursor.segmentIndex, this.#segments.length - 1));

Callers

nothing calls this directly

Calls 7

#refreshMethod · 0.95
#onCursorMethod · 0.95
#onKeyMethod · 0.95
#onFinalizeMethod · 0.95
segmentsForFunction · 0.85
detectLocaleFormatFunction · 0.85
onMethod · 0.80

Tested by

no test coverage detected