String Normalization
`normalizeString`
Trims whitespace and returns empty string for an absent (undefined) input. Lives in @esposter/shared.
import { normalizeString } from "@esposter/shared";
normalizeString(" hello "); // → "hello"
normalizeString(undefined); // → ""
`pluralize`
${count} ${pluralize("result", count)} — the hand-rolled ""/"s" ternary is a no-restricted-syntax error, and a non-plural s disables it with that reason (references/pluralize.md).
Convention: `string` not `string | null`
Optional text is string with "" as its absence — the absent-values skill (references/string-sentinel.md, and references/sentinel-columns.md for the column side).
When to use `normalizeString`
The default trim in app code — reach for it over a bare .trim():
- Parsing (CSV, XLSX, clipboard):
normalizeString(cell?.toString()) - Array mapping:
values.map(normalizeString).filter(Boolean) - Guard checks:
if (!normalizeString(value)) return; - Filter predicates:
.filter((line) => normalizeString(line) !== "") - Zod schemas: "Zod Schema Alignment" on this page
When not to use `normalizeString`
- Never in Vue — lint-enforced by
restrictedTrimSyntaxes.ts; thevueskill owns the why (references/forms.md). - User-facing transformation actions — e.g.
computeStringTransformation.tsTrimcase; keepvalue.trim(), it's implementing a named user operation. - Trimming a process's or a file's output inside a package — stdout, a token file, a hook's stdin, an XML reader's own
trimoption..trim()is correct there: none of it is user input crossing a Zod boundary, and a package that has no other use for@esposter/sharedshould not take it on for a trim.
.trimStart() and .trimEnd() are separate methods — replace only when semantically equivalent to a full .trim().
Blank tests — `checkIsBlankText`
A field holding spaces is not blank, so a blank test on text a person or an input supplies reads the trimmed value: checkIsBlankText(value) (@esposter/shared), and checkIsBlankText(value) ? fallback : value in place of a || fallback. A component calls the predicate, since it may not trim. === "" on a raw text value is the restrictedSyntaxes.ts error. A raw empty that is the meaning disables it on its line with that reason: an id, a server-issued value, a sentinel, a number input (which holds no spaces), a parser's untrimmed line, or a value the caller has already normalised. A fallback to "" is not a hit, since an empty fallback renders the same as a blank value.
Zod Schema Alignment
Base select schemas normalize so server validation matches client input. Always transform first, then validators in the pipe. Never add trim transforms to derived schemas (UpdateFooInput, etc.) — only in the base select schema.
Prefer the shared schema helpers over hand-rolling the transform+pipe — the zod skill (references/string-normalization.md).
// db-schema createSelectSchema overrides — the canonical form
foo: (schema) => createNormalizedStringSchema(FOO_MAX_LENGTH, schema),
Matching a Token Inside Authored Content
A token in authored content is matched on the delimiter that opened it, over the parsed value's string leaves, in one pass keyed by a Map, and a changed form widens the reader rather than backfilling (references/content-tokens.md, openspec/specs/architecture/content-token-rewriting/design.md).
HTML Sanitization at the Zod Boundary
Rich-text HTML is sanitized once, by .transform(sanitizeTextHtml) in the base Zod schema — never a frontend call, except a localStorage draft (references/html-sanitization.md).
Reference pages
references/pluralize.md— when a string carries a count, or the plural ternary is refused.references/content-tokens.md— before writing or widening a regex over authored content.references/html-sanitization.md— when a field holds rich-text HTML, or a sanitize call is about to be written.