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

Function Number

packages/effect/src/cli/Prompt.ts:1111–1141  ·  view source on GitHub ↗
(options: NumberOptions)

Source from the content-addressed store, hash-verified

1109 * @since 4.0.0
1110 */
1111export 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`.

Callers 15

coreIntFunction · 0.50
coreFloatFunction · 0.50
parsePaxFunction · 0.50
paxIntegerFunction · 0.50
paxMillisFunction · 0.50
isValidOffsetFunction · 0.50
parseNumberMethod · 0.50
makeConfigFunction · 0.50
feedSyncFunction · 0.50
pushU64Function · 0.50
uvarintBigMethod · 0.50
numberVarintMethod · 0.50

Calls 6

handleRenderFloatFunction · 0.85
handleProcessFloatFunction · 0.85
handleNumberClearFunction · 0.85
CustomFunction · 0.70
failMethod · 0.65
succeedMethod · 0.45

Tested by

no test coverage detected