OneEcma normalizes text with InvariantGlobalization enabled. It ships its own normalization data and doesn’t call .NET’s string.Normalize.
dotnet add package RecursiveAI.OneEcmaRequires .NET 10 (net10.0); .NET 9 and earlier aren’t supported.
using RecursiveAI.OneEcma; Console.WriteLine(new ScriptEngine() .Evaluate(""" const text = 'e\u0301 \uFB01'; text.normalize('NFC') + '\n' + text.normalize('NFKC'); """).AsString);
Unzip the example, then dotnet run.
Prints:
é fi é fi
The full program
using RecursiveAI.OneEcma; var engine = new ScriptEngine(); Console.WriteLine(engine.Evaluate(""" const text = 'e\u0301 \uFB01'; function codePoints(value) { return Array.from(value, ch => 'U+' + ch.codePointAt(0) .toString(16).toUpperCase().padStart(4, '0')).join(' '); } const nfc = text.normalize('NFC'); const nfkc = text.normalize('NFKC'); [ `Input: ${codePoints(text)}`, `NFC: ${nfc} (${codePoints(nfc)})`, `NFKC: ${nfkc} (${codePoints(nfkc)})` ].join('\n'); """).AsString);
dotnet run prints:
Input: U+0065 U+0301 U+0020 U+FB01 NFC: é fi (U+00E9 U+0020 U+FB01) NFKC: é fi (U+00E9 U+0020 U+0066 U+0069)
The download enables invariant globalization in Example.csproj. To run the snippet at the top in the same .NET mode, add this block inside your project file’s <Project> element:
<PropertyGroup> <InvariantGlobalization>true</InvariantGlobalization> </PropertyGroup>
A form name other than NFC, NFD, NFKC, or NFKD raises a JavaScript RangeError.
Variations
Use NFD to get the decomposed code points. Replace the JavaScript inside Evaluate with the code below. It prints 65 301.
const text = '\u00E9'; Array.from(text.normalize('NFD'), ch => ch.codePointAt(0).toString(16) ).join(' ');
Related recipes
- Sort JavaScript strings by locale in C#
- Split JavaScript text into graphemes in C#
- Format JavaScript dates by locale and time zone in C#
The short answer
Call JavaScript String.prototype.normalize through OneEcma’s ScriptEngine. NFC composes e and its combining acute accent into é; NFKC also replaces the single fi ligature with f and i. The downloadable project enables .NET invariant globalization and prints the Unicode code points as well as the text, so you can see which characters changed.
What’s the difference between NFC and NFKC in JavaScript?
NFC gives canonically equivalent text the same representation. An é typed as U+00E9 and an e followed by U+0301 are canonically equivalent; both become U+00E9 in this example. NFC leaves the ligature U+FB01 alone. NFKC also applies compatibility mappings before composition. Here, that means rewriting U+FB01 as U+0066 and U+0069. The Unicode normalization specification explains both types of equivalence. String.prototype.normalize() on MDN describes the four names and the NFC default when you omit the argument.
Use NFC if you’re comparing strings that came from different keyboards or input methods and you want canonical equivalence without compatibility folding. NFKC can be useful when your search should match file to file. Keep the original string separately if it must be displayed as entered. Don’t apply NFKC blindly to identifiers whose original distinctions matter: the process loses information, and you can’t recover the original ligature from the resulting fi. Neither form in this example removes the acute accent.
Does JavaScript normalization work with InvariantGlobalization enabled?
In OneEcma, yes. This recipe calls the JavaScript method, not .NET’s string.Normalize. The pinned text services docs say, “Nothing here uses the platform's globalization or normalization support.” The engine carries Unicode 17.0.0 normalization data. Enabling .NET’s invariant globalization mode in the example affects the .NET process, not the data OneEcma uses for this JavaScript operation. This doesn’t imply that unrelated .NET culture APIs get locale data from OneEcma.
When would you use NFD instead of NFC?
NFD decomposes canonically equivalent text but doesn’t compose it again. Use it when you need to inspect a base character and its combining marks separately. In the variation, a single é becomes U+0065 followed by U+0301. NFD alone doesn’t strip that mark, and decomposed text can have a different UTF-16 length from composed text. If you normalize before processing ranges, compute the offsets from the normalized string, not from the original.