(options: IntegerOptions)
| 1004 | * @since 4.0.0 |
| 1005 | */ |
| 1006 | export const integer = (options: IntegerOptions): Prompt<number> => { |
| 1007 | const opts: IntegerOptionsReq = { |
| 1008 | default: 0, |
| 1009 | min: Number.NEGATIVE_INFINITY, |
| 1010 | max: Number.POSITIVE_INFINITY, |
| 1011 | incrementBy: 1, |
| 1012 | decrementBy: 1, |
| 1013 | validate: (n) => { |
| 1014 | if (n < opts.min) { |
| 1015 | return Effect.fail(`${n} must be greater than or equal to ${opts.min}`) |
| 1016 | } |
| 1017 | if (n > opts.max) { |
| 1018 | return Effect.fail(`${n} must be less than or equal to ${opts.max}`) |
| 1019 | } |
| 1020 | return Effect.succeed(n) |
| 1021 | }, |
| 1022 | ...options |
| 1023 | } |
| 1024 | const initialValue = options.default === undefined ? "" : `${opts.default}` |
| 1025 | const initialState: NumberState = { |
| 1026 | cursor: initialValue.length, |
| 1027 | value: initialValue, |
| 1028 | error: Option.none() |
| 1029 | } |
| 1030 | return custom(initialState, { |
| 1031 | render: handleRenderInteger(opts), |
| 1032 | process: handleProcessInteger(opts), |
| 1033 | clear: handleNumberClear(opts) |
| 1034 | }) |
| 1035 | } |
| 1036 | |
| 1037 | /** |
| 1038 | * Creates a text prompt that returns an array of strings by splitting the |
nothing calls this directly
no test coverage detected