API Reference / @evolu/common / Type / trim

Variable: trim

const trim: TransformBrandFactory<"Trimmed", string>;

Defined in: packages/common/src/Type.ts:1006

Trims leading and trailing whitespace from a string.

This Type Factory transforms the input string by removing whitespace from both ends. For validation only, use trimmed Type Factory.

Example

const TrimString = trim(String);
expect(TrimString.from("a ")).toEqual(ok("a"));
expect(TrimString.fromParent("a ").value).toEqual("a");

const TrimNonEmptyString = trim(NonEmptyString);
expect(TrimNonEmptyString.from("a " as NonEmptyString)).toEqual(ok("a"));
expect(
  TrimNonEmptyString.fromParent("a " as NonEmptyString).value,
).toEqual("a");

Note: This transformation is irreversible. Calling toParent will not restore the original representation.

Was this page helpful?