(options: NumberOptions)
| 1109 | * @since 4.0.0 |
| 1110 | */ |
| 1111 | export const Number = (options: NumberOptions): Prompt<number> => { |
| 1112 | const opts: NumberOptionsReq = { |
| 1113 | default: 0, |
| 1114 | min: globalThis.Number.NEGATIVE_INFINITY, |
| 1115 | max: globalThis.Number.POSITIVE_INFINITY, |
| 1116 | incrementBy: 1, |
| 1117 | decrementBy: 1, |
| 1118 | precision: 2, |
| 1119 | validate: (n) => { |
| 1120 | if (n < opts.min) { |
| 1121 | return Effect.fail(`${n} must be greater than or equal to ${opts.min}`) |
| 1122 | } |
| 1123 | if (n > opts.max) { |
| 1124 | return Effect.fail(`${n} must be less than or equal to ${opts.max}`) |
| 1125 | } |
| 1126 | return Effect.succeed(n) |
| 1127 | }, |
| 1128 | ...options |
| 1129 | } |
| 1130 | const initialValue = options.default === undefined ? "" : `${opts.default}` |
| 1131 | const initialState: NumberState = { |
| 1132 | cursor: initialValue.length, |
| 1133 | value: initialValue, |
| 1134 | error: Option.none() |
| 1135 | } |
| 1136 | return Custom(initialState, { |
| 1137 | render: handleRenderFloat(opts), |
| 1138 | process: handleProcessFloat(opts), |
| 1139 | clear: handleNumberClear(opts) |
| 1140 | }) |
| 1141 | } |
| 1142 | /** |
| 1143 | * Creates a text prompt that does not echo typed input and returns the |
| 1144 | * submitted value wrapped in `Redacted`. |
no test coverage detected