String utils

From Esposter/Esposter · View interactive version

String utils is an AI agent skill from the GitHub repository Esposter/Esposter. Apply when trimming, normalizing or sanitizing a string, pluralizing a count, or matching a token inside authored content. Esposter's string handling for app code, Zod boundaries and authored rich text.

How to use this skill

Skill file

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():

When not to use `normalizeString`

.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

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.