MCPcopy Create free account
hub / github.com/Effect-TS/effect / float

Function float

packages/effect/src/unstable/cli/Prompt.ts:953–983  ·  view source on GitHub ↗
(options: FloatOptions)

Source from the content-addressed store, hash-verified

951 * @since 4.0.0
952 */
953export 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`.

Callers

nothing calls this directly

Calls 6

handleRenderFloatFunction · 0.85
handleProcessFloatFunction · 0.85
handleNumberClearFunction · 0.85
customFunction · 0.70
failMethod · 0.45
succeedMethod · 0.45

Tested by

no test coverage detected