Skip to content

Remove empty string items

removeEmptyStringItems is a built‑in normalization rule that removes empty string entries from arrays.

It eliminates placeholder or accidental text values while preserving all meaningful items. Because this transformation removes user‑supplied elements, it is considered lossy and runs only in lax mode.

Signature

export const removeEmptyStringItems: NormalizationRule<unknown>
(value: unknown, mode: NormalizationMode, path: FieldPath) => NormalizationStep[]

Events

Event code Description
array.without.empty-strings Empty string items were removed from array.

Design rationale

  • Removes empty string placeholders that commonly arise from UI inputs, form fields, or partial constructions.
  • Preserves all meaningful items while eliminating structurally useless entries.
  • Considered lossy because user‑provided values ("") are removed.
  • Emits a normalization step only when at least one empty string is removed.
  • Produces cleaner, more predictable arrays for downstream validation and policy layers.

Invoke

removeEmptyStringItems runs automatically when:

  • The value is structurally an array.
  • The normalization stage is active.
  • The current mode allows lossy normalization.

Mode behavior:

  • strict: Rule does not run.
  • moderate: Rule does not run (this rule is lossy).
  • lax: Rule runs.

Normalization cannot be invoked manually. It is always applied automatically based on structural type and mode.

Examples

Empty strings removed

const value = ["a", "", "b", ""];

const result = removeEmptyStringItems(value, "lax", "$");
// → [
//     {
//       path: "$",
//       nextValue: ["a", "b"],
//       lossy: "lossy",
//       events: [
//         JaneEvent{ kind: "info", code: "array.without.empty-strings", ... }
//       ]
//     }
//   ]

No empty strings — no normalization

const result = removeEmptyStringItems(["a", "b"], "lax", "$");
// → []

Non‑array value

const result = removeEmptyStringItems("not an array", "lax", "$");
// → []