The normalize()
method returns the Unicode Normalization Form of a given string (if the value isn't a string, it will be converted to one first).
The source for this interactive example is stored in a GitHub repository. If you'd like to contribute to the interactive examples project, please clone https://github.com/mdn/interactive-examples and send us a pull request.
Syntax
str.normalize([form])
Parameters
form
- One of
"NFC"
,"NFD"
,"NFKC"
, or"NFKD"
, specifying the Unicode Normalization Form. If omitted orundefined
,"NFC"
is used.NFC
— Normalization Form Canonical Composition.NFD
— Normalization Form Canonical Decomposition.NFKC
— Normalization Form Compatibility Composition.NFKD
— Normalization Form Compatibility Decomposition.
Return value
A string containing the Unicode Normalization Form of the given string.
Errors thrown
RangeError
- A
RangeError
is thrown ifform
isn't one of the values specified above.
Description
The normalize()
method returns the specified Unicode Normalization Form of the string. It does not affect the value of the string itself.
Examples
Using normalize()
// Initial string // U+1E9B: LATIN SMALL LETTER LONG S WITH DOT ABOVE // U+0323: COMBINING DOT BELOW var str = '\u1E9B\u0323'; // Canonically-composed form (NFC) // U+1E9B: LATIN SMALL LETTER LONG S WITH DOT ABOVE // U+0323: COMBINING DOT BELOW str.normalize('NFC'); // '\u1E9B\u0323' str.normalize(); // same as above // Canonically-decomposed form (NFD) // U+017F: LATIN SMALL LETTER LONG S // U+0323: COMBINING DOT BELOW // U+0307: COMBINING DOT ABOVE str.normalize('NFD'); // '\u017F\u0323\u0307' // Compatibly-composed (NFKC) // U+1E69: LATIN SMALL LETTER S WITH DOT BELOW AND DOT ABOVE str.normalize('NFKC'); // '\u1E69' // Compatibly-decomposed (NFKD) // U+0073: LATIN SMALL LETTER S // U+0323: COMBINING DOT BELOW // U+0307: COMBINING DOT ABOVE str.normalize('NFKD'); // '\u0073\u0323\u0307'
Specifications
Specification | Status | Comment |
---|---|---|
ECMAScript 2015 (6th Edition, ECMA-262) The definition of 'String.prototype.normalize' in that specification. |
Standard | Initial definition. |
ECMAScript Latest Draft (ECMA-262) The definition of 'String.prototype.normalize' in that specification. |
Draft |
Browser compatibility
The compatibility table in this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.
Desktop | Mobile | Server | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Basic support | Chrome Full support 34 | Edge Full support Yes | Firefox Full support 31 | IE No support No | Opera Full support Yes | Safari Full support 10 | WebView Android No support No | Chrome Android Full support 34 | Edge Mobile Full support Yes | Firefox Android Full support 31 | Opera Android Full support Yes | Safari iOS Full support 10 | Samsung Internet Android Full support Yes | nodejs Full support 0.12 |
Legend
- Full support
- Full support
- No support
- No support