Skip to content

String has whitespace edges

stringHasWhitespaceEdges is a built‑in scan rule that detects strings with leading or trailing whitespace.

It compares the raw string to its trimmed form. When the two differ, the rule emits a warn‑level string.has.whitespace-edges scan event containing the original value. If the value is not a string or contains no edge whitespace, no events are emitted.

Signature

export const stringHasWhitespaceEdges: ScanRule (raw: unknown, path: FieldPath) => JaneEvent[]

Events

Event code Description
string.has.whitespace-edges String contains leading or trailing whitespace.

Design rationale

  • Detects accidental padding, formatting mistakes, and subtle input‑shape inconsistencies.
  • Uses a literal comparison (raw !== raw.trim()) — no heuristics or Unicode normalization.
  • Emits a warning when edge whitespace is present.
  • Surfaces anomalies early so normalization or policy layers can decide how to handle them.
  • Provides metadata ({ raw }) for debugging and analysis.
  • Performs no mutation or transformation of the input.

Invoke

stringHasWhitespaceEdges runs automatically whenever the scan stage is enabled.

Activation methods:

  • Enable scan explicitly: jane.value(input).scan().
  • Use a mode that enables scan:
  • strict() enables scan by default.
  • moderate() and lax() do not enable scan unless .scan() is called.
  • Enable scan with policy: jane.value(input).withPolicy({ mode: 'strict' }).

If scan is not enabled or if the value is not a string, stringHasWhitespaceEdges does not run and no edge‑whitespace detection occurs.

Examples

Whitespace edges detected

const result = stringHasWhitespaceEdges("  hello ", "$");
// → [ JaneEvent{ kind: "warn", code: "string.has.whitespace-edges", ... } ]

No whitespace edges

const result = stringHasWhitespaceEdges("hello", "$");
// → []

Non‑string value

const result = stringHasWhitespaceEdges(123, "$");
// → []