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).
str.normalize([form])
form
"NFC"
, "NFD"
, "NFKC"
, or "NFKD"
, specifying the Unicode Normalization Form. If omitted or undefined
, "NFC"
is used. NFC
— Normalization Form Canonical Composition.NFD
— Normalization Form Canonical Decomposition.NFKC
— Normalization Form Compatibility Composition.NFKD
— Normalization Form Compatibility Decomposition.A string containing the Unicode Normalization Form of the given string.
RangeError
RangeError
is thrown if form
isn't one of the values specified above.The normalize()
method returns the specified Unicode Normalization Form of the string. It does not affect the value of the string itself.
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'
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. | Living Standard |
Feature | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|---|
Basic support | 34 | Yes | 31 | No | Yes | 10 |
Feature | Android webview | Chrome for Android | Edge mobile | Firefox for Android | IE mobile | Opera Android | iOS Safari |
---|---|---|---|---|---|---|---|
Basic support | No | 34 | Yes | No | No | Yes | 10 |
© 2005–2018 Mozilla Developer Network and individual contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/normalize