(options: IntOptions)
| 1164 | * @since 4.0.0 |
| 1165 | */ |
| 1166 | export const Int = (options: IntOptions): Prompt<number> => { |
| 1167 | const opts: IntOptionsReq = { |
| 1168 | default: 0, |
| 1169 | min: globalThis.Number.NEGATIVE_INFINITY, |
| 1170 | max: globalThis.Number.POSITIVE_INFINITY, |
| 1171 | incrementBy: 1, |
| 1172 | decrementBy: 1, |
| 1173 | validate: (n) => { |
| 1174 | if (n < opts.min) { |
| 1175 | return Effect.fail(`${n} must be greater than or equal to ${opts.min}`) |
| 1176 | } |
| 1177 | if (n > opts.max) { |
| 1178 | return Effect.fail(`${n} must be less than or equal to ${opts.max}`) |
| 1179 | } |
| 1180 | return Effect.succeed(n) |
| 1181 | }, |
| 1182 | ...options |
| 1183 | } |
| 1184 | const initialValue = options.default === undefined ? "" : `${opts.default}` |
| 1185 | const initialState: NumberState = { |
| 1186 | cursor: initialValue.length, |
| 1187 | value: initialValue, |
| 1188 | error: Option.none() |
| 1189 | } |
| 1190 | return Custom(initialState, { |
| 1191 | render: handleRenderInteger(opts), |
| 1192 | process: handleProcessInteger(opts), |
| 1193 | clear: handleNumberClear(opts) |
| 1194 | }) |
| 1195 | } |
| 1196 | |
| 1197 | /** |
| 1198 | * Creates a text prompt that returns an array of strings by splitting the |
nothing calls this directly
no test coverage detected