Remove empty string keys¶
removeEmptyStringKeys is a built‑in normalization rule that removes object keys whose values are empty strings.
This clears placeholder or accidental text fields while preserving all meaningful string values. If the value is not a plain object, or no keys contain empty strings, no normalization step is emitted.
Signature¶
export const removeEmptyStringKeys: NormalizationRule<unknown>
(value: unknown, mode: NormalizationMode, path: FieldPath) => NormalizationStep[]
Events¶
| Event code | Description |
|---|---|
object.without.empty-strings |
Keys with empty string values were removed. |
Design rationale¶
- Removes only keys whose values are empty strings ("").
- Preserves all non‑empty strings and all non‑string values.
- Eliminates placeholder text fields commonly produced by UI frameworks, form libraries, or incomplete user input.
- Emits a normalization step only when at least one empty string key is removed.
- Classified as
lossynormalization — the original empty string values are discarded. - Produces cleaner object shapes for downstream validators, scanners, and policy layers.
Invoke¶
removeEmptyStringKeys runs automatically when:
- The value is structurally a plain object (not an array).
- The normalization stage is active.
- The current mode allows
lossynormalization.
Mode behavior:
strict: Rule does not run (lossy).moderate: Rule does not run (lossy).lax: Rule runs.
Normalization cannot be invoked manually. It is always applied automatically based on structural type and mode.
Examples¶
Empty string keys removed¶
const value = {
name: "",
title: "Director",
notes: ""
};
const result = removeEmptyStringKeys(value, "lax", "$");
// → [
// {
// path: "$",
// nextValue: { title: "Director" },
// lossy: "lossy",
// events: [
// JaneEvent{ kind: "info", code: "object.without.empty-strings", ... }
// ]
// }
// ]
No empty strings — no normalization¶
const result = removeEmptyStringKeys({ a: "x", b: "" }, "strict", "$");
// → []
Non‑object value¶
const result = removeEmptyStringKeys("not an object", "lax", "$");
// → []