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

Function defaultFloatProcessor

packages/effect/src/unstable/cli/Prompt.ts:2873–2899  ·  view source on GitHub ↗
(input: string, state: NumberState)

Source from the content-addressed store, hash-verified

2871}
2872
2873const defaultFloatProcessor = (input: string, state: NumberState) => {
2874 if (input === "." && state.value.includes(".")) {
2875 return Effect.succeed(Action.Beep())
2876 }
2877 if (state.value.length === 0 && input === "-") {
2878 return Effect.succeed(Action.NextFrame({
2879 state: { ...state, value: "-", error: Option.none() }
2880 }))
2881 }
2882
2883 const parsed = Number.parseFloat(state.value + input)
2884 if (Number.isNaN(parsed)) {
2885 return Effect.succeed(Action.Beep())
2886 } else {
2887 return Effect.succeed(Action.NextFrame({
2888 state: {
2889 ...state,
2890 value: input === "."
2891 ? `${parsed}.`
2892 : state.value.includes(".") && /^\d$/.test(input)
2893 ? state.value + input
2894 : `${parsed}`,
2895 error: Option.none()
2896 }
2897 }))
2898 }
2899}
2900
2901const handleRenderInteger = (options: IntegerOptionsReq) => {
2902 return (state: NumberState, action: Action<NumberState, number>) => {

Callers 1

handleProcessFloatFunction · 0.85

Calls 1

succeedMethod · 0.45

Tested by

no test coverage detected