| 24 | }; |
| 25 | |
| 26 | export default class Question { |
| 27 | private _question: Readonly<DistinctQuestion>; |
| 28 | private messages: PromptMessages; |
| 29 | private skip: boolean; |
| 30 | private _maxLength: number; |
| 31 | private _minLength: number; |
| 32 | private title: string; |
| 33 | private caseFn: CaseFn; |
| 34 | private fullStopFn: FullStopFn; |
| 35 | private multipleValueDelimiters?: RegExp; |
| 36 | private multipleSelectDefaultDelimiter?: string; |
| 37 | constructor( |
| 38 | name: PromptName, |
| 39 | { |
| 40 | title, |
| 41 | enumList, |
| 42 | messages, |
| 43 | defaultValue, |
| 44 | when, |
| 45 | skip, |
| 46 | fullStopFn, |
| 47 | caseFn, |
| 48 | maxLength, |
| 49 | minLength, |
| 50 | multipleValueDelimiters, |
| 51 | multipleSelectDefaultDelimiter, |
| 52 | }: QuestionConfig, |
| 53 | ) { |
| 54 | if (!name || typeof name !== "string") throw new Error("Question: name is required"); |
| 55 | |
| 56 | this._maxLength = maxLength ?? Infinity; |
| 57 | this._minLength = minLength ?? 0; |
| 58 | this.messages = messages; |
| 59 | this.title = title ?? ""; |
| 60 | this.skip = skip ?? false; |
| 61 | this.fullStopFn = fullStopFn ?? ((_: string) => _); |
| 62 | this.caseFn = |
| 63 | caseFn ?? |
| 64 | ((input: string | string[], delimiter?: string) => |
| 65 | Array.isArray(input) ? input.join(delimiter) : input); |
| 66 | this.multipleValueDelimiters = multipleValueDelimiters; |
| 67 | this.multipleSelectDefaultDelimiter = multipleSelectDefaultDelimiter; |
| 68 | |
| 69 | if (enumList && Array.isArray(enumList)) { |
| 70 | this._question = { |
| 71 | type: multipleSelectDefaultDelimiter ? "checkbox" : "list", |
| 72 | choices: skip |
| 73 | ? [ |
| 74 | ...enumList, |
| 75 | new inquirer.Separator(), |
| 76 | { |
| 77 | name: "empty", |
| 78 | value: "", |
| 79 | }, |
| 80 | ] |
| 81 | : [...enumList], |
| 82 | }; |
| 83 | } else if (/^is[A-Z]/.test(name)) { |
nothing calls this directly
no outgoing calls
no test coverage detected