Hyperlinkv0.8.0-beta.28

SchemaTransformation

SchemaTransformation.numberFromStringconsteffect/SchemaTransformation.ts:809
Transformation<number, string, never, never>

Decodes a string into a number and encodes a number back to a string.

When to use

Use when you need a schema transformation to parse numeric strings from APIs, form data, or URL parameters.

Details

Decoding coerces the string to a number like Number(s). Encoding coerces the number to a string like String(n). This does not validate that the result is finite; combine with Schema.Finite or Schema.Int for stricter checks.

Example (Converting a string to a number)

import { Schema, SchemaTransformation } from "effect"

const schema = Schema.String.pipe(
  Schema.decodeTo(Schema.Number, SchemaTransformation.numberFromString)
)
export const numberFromString = new Transformation(
  SchemaGetter.Number(),
  SchemaGetter.String()
)
Referenced by 2 symbols