(options: FloatOptions)
| 951 | * @since 4.0.0 |
| 952 | */ |
| 953 | export const float = (options: FloatOptions): Prompt<number> => { |
| 954 | const opts: FloatOptionsReq = { |
| 955 | default: 0, |
| 956 | min: Number.NEGATIVE_INFINITY, |
| 957 | max: Number.POSITIVE_INFINITY, |
| 958 | incrementBy: 1, |
| 959 | decrementBy: 1, |
| 960 | precision: 2, |
| 961 | validate: (n) => { |
| 962 | if (n < opts.min) { |
| 963 | return Effect.fail(`${n} must be greater than or equal to ${opts.min}`) |
| 964 | } |
| 965 | if (n > opts.max) { |
| 966 | return Effect.fail(`${n} must be less than or equal to ${opts.max}`) |
| 967 | } |
| 968 | return Effect.succeed(n) |
| 969 | }, |
| 970 | ...options |
| 971 | } |
| 972 | const initialValue = options.default === undefined ? "" : `${opts.default}` |
| 973 | const initialState: NumberState = { |
| 974 | cursor: initialValue.length, |
| 975 | value: initialValue, |
| 976 | error: Option.none() |
| 977 | } |
| 978 | return custom(initialState, { |
| 979 | render: handleRenderFloat(opts), |
| 980 | process: handleProcessFloat(opts), |
| 981 | clear: handleNumberClear(opts) |
| 982 | }) |
| 983 | } |
| 984 | /** |
| 985 | * Creates a text prompt that does not echo typed input and returns the |
| 986 | * submitted value wrapped in `Redacted`. |
nothing calls this directly
no test coverage detected