MCPcopy Create free account
hub / github.com/Zoo-Code-Org/Zoo-Code / normalizeString

Function normalizeString

src/utils/text-normalization.ts:48–77  ·  view source on GitHub ↗
(str: string, options: NormalizeOptions = DEFAULT_OPTIONS)

Source from the content-addressed store, hash-verified

46 * @returns The normalized string
47 */
48export function normalizeString(str: string, options: NormalizeOptions = DEFAULT_OPTIONS): string {
49 const opts = { ...DEFAULT_OPTIONS, ...options }
50 let normalized = str
51
52 // Replace smart quotes
53 if (opts.smartQuotes) {
54 for (const [smart, regular] of Object.entries(NORMALIZATION_MAPS.SMART_QUOTES)) {
55 normalized = normalized.replace(new RegExp(smart, "g"), regular)
56 }
57 }
58
59 // Replace typographic characters
60 if (opts.typographicChars) {
61 for (const [typographic, regular] of Object.entries(NORMALIZATION_MAPS.TYPOGRAPHIC)) {
62 normalized = normalized.replace(new RegExp(typographic, "g"), regular)
63 }
64 }
65
66 // Normalize whitespace
67 if (opts.extraWhitespace) {
68 normalized = normalized.replace(/\s+/g, " ")
69 }
70
71 // Trim whitespace
72 if (opts.trim) {
73 normalized = normalized.trim()
74 }
75
76 return normalized
77}
78
79/**
80 * Unescapes common HTML entities in a string

Callers 3

getSimilarityFunction · 0.90
applyDiffMethod · 0.90

Calls 2

entriesMethod · 0.80
replaceMethod · 0.65

Tested by

no test coverage detected