MCPcopy
hub / github.com/Effect-TS/effect / parseNumber

Function parseNumber

packages/effect/src/Schema.ts:5314–5330  ·  view source on GitHub ↗
(
  self: S & Schema<A, Schema.Encoded<S>, Schema.Context<S>>
)

Source from the content-addressed store, hash-verified

5312 * @since 3.10.0
5313 */
5314export function parseNumber<S extends Schema.Any, A extends string>(
5315 self: S & Schema<A, Schema.Encoded<S>, Schema.Context<S>>
5316): transformOrFail<S, typeof Number$> {
5317 return transformOrFail(
5318 self,
5319 Number$,
5320 {
5321 strict: false,
5322 decode: (i, _, ast) =>
5323 ParseResult.fromOption(
5324 number_.parse(i),
5325 () => new ParseResult.Type(ast, i, `Unable to decode ${JSON.stringify(i)} into a number`)
5326 ),
5327 encode: (a) => ParseResult.succeed(String(a))
5328 }
5329 )
5330}
5331
5332/**
5333 * This schema transforms a `string` into a `number` by parsing the string using the `parse` function of the `effect/Number` module.

Callers 1

NumberFromStringClass · 0.85

Calls 3

transformOrFailInterface · 0.85
StringInterface · 0.85
parseMethod · 0.80

Tested by

no test coverage detected