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

Function integer

packages/effect/src/unstable/cli/Prompt.ts:1006–1035  ·  view source on GitHub ↗
(options: IntegerOptions)

Source from the content-addressed store, hash-verified

1004 * @since 4.0.0
1005 */
1006export const integer = (options: IntegerOptions): Prompt<number> => {
1007 const opts: IntegerOptionsReq = {
1008 default: 0,
1009 min: Number.NEGATIVE_INFINITY,
1010 max: Number.POSITIVE_INFINITY,
1011 incrementBy: 1,
1012 decrementBy: 1,
1013 validate: (n) => {
1014 if (n < opts.min) {
1015 return Effect.fail(`${n} must be greater than or equal to ${opts.min}`)
1016 }
1017 if (n > opts.max) {
1018 return Effect.fail(`${n} must be less than or equal to ${opts.max}`)
1019 }
1020 return Effect.succeed(n)
1021 },
1022 ...options
1023 }
1024 const initialValue = options.default === undefined ? "" : `${opts.default}`
1025 const initialState: NumberState = {
1026 cursor: initialValue.length,
1027 value: initialValue,
1028 error: Option.none()
1029 }
1030 return custom(initialState, {
1031 render: handleRenderInteger(opts),
1032 process: handleProcessInteger(opts),
1033 clear: handleNumberClear(opts)
1034 })
1035}
1036
1037/**
1038 * Creates a text prompt that returns an array of strings by splitting the

Callers

nothing calls this directly

Calls 6

handleRenderIntegerFunction · 0.85
handleProcessIntegerFunction · 0.85
handleNumberClearFunction · 0.85
customFunction · 0.70
failMethod · 0.45
succeedMethod · 0.45

Tested by

no test coverage detected