Hyperlinkv0.8.0-beta.28

SchemaTransformation

SchemaTransformation.trimfunctioneffect/SchemaTransformation.ts:428
(): Transformation<string, string>

Transforms strings by trimming whitespace on decode. Encode is passthrough (no change).

When to use

Use when you need a schema transformation to normalize user input by stripping leading/trailing whitespace.

Details

Decoding applies String.prototype.trim(). Encoding is passthrough and returns the string unchanged. This is not round-trippable if the original had whitespace.

Example (Trimming on decode)

import { Schema, SchemaTransformation } from "effect"

const Trimmed = Schema.String.pipe(
  Schema.decode(SchemaTransformation.trim())
)
export function trim(): Transformation<string, string> {
  return new Transformation(
    SchemaGetter.trim(),
    SchemaGetter.passthrough()
  )
}
Referenced by 1 symbols