A small normalization step can clean user input before later code stores or routes it.

input normalization Normalize early so the rest of the pipeline sees a predictable typed record.

Input Normalization Case

rawName
normalize.ts
Replay: real traced execution (multi-file project)
type NormalizedUser = {
    displayName: string;
    slug: string;
};

function normalizeUser(rawName: string): NormalizedUser {
    const trimmed: string = rawName.trim();
    const displayName: string = trimmed.replace(/\s+/g, " ");
    const slug: string = displayName.toLowerCase().replace(/\s+/g, "-");

    return { displayName, slug };
}

const rawName: string = "  Trace Bot  ";
const user: NormalizedUser = normalizeUser(rawName);

console.log(`name=${user.displayName};slug=${user.slug}`);
type NormalizedUser = {
    displayName: string;
    slug: string;
};

function normalizeUser(rawName: string): NormalizedUser {
    const trimmed: string = rawName.trim();
    const displayName: string = trimmed.replace(/\s+/g, " ");
    const slug: string = displayName.toLowerCase().replace(/\s+/g, "-");

    return { displayName, slug };
}

const rawName: string = "  Ada Lovelace  ";
const user: NormalizedUser = normalizeUser(rawName);

console.log(`name=${user.displayName};slug=${user.slug}`);
  1. rawName ← Trace Bot

    11    return { displayName, slug };12}1314const rawName→   Trace Bot  : string = "  Trace Bot  ";  //@rawName="  Ada Lovelace  "15const user: NormalizedUser = normalizeUser(rawName  Trace Bot  );
  2. trimmed ← Trace Bot, displayName ← Trace Bot, slug ← trace-bot

    3    slug: string;4};56function normalizeUser(rawName  Trace Bot  : string): NormalizedUser {7    const trimmed→ Trace Bot: string = rawName  Trace Bot  .trim();8    const displayName→ Trace Bot: string = trimmedTrace Bot.replace(/\s+/g, " ");9    const slug→ trace-bot: string = displayNameTrace Bot.toLowerCase().replace(/\s+/g, "-");1011    return { displayName, slug };12}
  3. user ← [object Object]

    14const rawName: string = "  Trace Bot  ";  //@rawName="  Ada Lovelace  "15const user→ [object Object]: NormalizedUser = normalizeUser(rawName  Trace Bot  );1617console.log(`name=${user.displayNameTrace Bot};slug=${user.slugtrace-bot}`);
    outputname=Trace Bot;slug=trace-bot
  1. rawName ← Ada Lovelace

    11    return { displayName, slug };12}1314const rawName→   Ada Lovelace  : string = "  Ada Lovelace  ";15const user: NormalizedUser = normalizeUser(rawName  Ada Lovelace  );
  2. trimmed ← Ada Lovelace, displayName ← Ada Lovelace, slug ← ada-lovelace

    3    slug: string;4};56function normalizeUser(rawName  Ada Lovelace  : string): NormalizedUser {7    const trimmed→ Ada Lovelace: string = rawName  Ada Lovelace  .trim();8    const displayName→ Ada Lovelace: string = trimmedAda Lovelace.replace(/\s+/g, " ");9    const slug→ ada-lovelace: string = displayNameAda Lovelace.toLowerCase().replace(/\s+/g, "-");1011    return { displayName, slug };12}
  3. user ← [object Object]

    14const rawName: string = "  Ada Lovelace  ";15const user→ [object Object]: NormalizedUser = normalizeUser(rawName  Ada Lovelace  );1617console.log(`name=${user.displayNameAda Lovelace};slug=${user.slugada-lovelace}`);
    outputname=Ada Lovelace;slug=ada-lovelace