unorm

raw JSON →
1.6.0 verified Sat Apr 25 auth: no javascript maintenance

JavaScript library for Unicode normalization forms NFC, NFD, NFKC, and NFKD, compliant with Unicode 8.0. The package provides simple functions to normalize strings according to the Unicode Standard Annex #15. Version 1.6.0 is the latest stable release, last updated in 2019. It is a CommonJS module but also ships a browser bundle as a global. This library is a polyfill for String.prototype.normalize and is useful for text processing, internationalization, and ensuring consistent string comparison. Unlike the built-in normalizer (added in ES6), unorm works in older environments and offers fine-grained control. It has no external dependencies and is lightweight.

error require is not defined
cause Using unorm in a browser without a bundler or script tag.
fix
Include unorm via a <script> tag: <script src="node_modules/unorm/unorm.js"></script>, then use window.unorm.nfc()
error TypeError: unorm.nfc is not a function
cause Incorrect import (e.g., default import) when using ESM.
fix
Use named imports: import { nfc } from 'unorm'
error Module "unorm" has been externalized for browser compatibility and cannot be accessed
cause Using Vite or similar bundler that treats CommonJS modules as external.
fix
Add unorm to vite's optimizeDeps.include: ['unorm']
gotcha unorm does not ship TypeScript type definitions; users must create their own or use @types/unorm (community-maintained).
fix Install @types/unorm from DefinitelyTyped or declare module 'unorm' in a .d.ts file.
deprecated String.prototype.normalize is available in Node.js >= 6 and modern browsers; unorm is only needed for polyfilling older environments.
fix Use built-in native normalize() if targeting Node.js >= 6 or modern browsers.
gotcha The package uses ECMAScript 5 features; older browsers (IE8 and below) require es5-shim.
fix Include es5-shim before unorm for legacy browser support.
gotcha unorm uses CommonJS module exports; direct ESM imports may fail in some bundlers without proper configuration.
fix Use require() or configure bundler to handle CommonJS modules.
npm install unorm
yarn add unorm
pnpm add unorm

Demonstrates all four Unicode normalization functions with a sample string.

import { nfc, nfd, nfkc, nfkd } from 'unorm';

const text = '\u212B\u00C5ngstr\u00F6m';
console.log('NFC:', nfc(text));
console.log('NFD:', nfd(text));
console.log('NFKC:', nfkc(text));
console.log('NFKD:', nfkd(text));