JavaScript string.normalize() Method

In this tute, we will discuss the JavaScript string.normalize() method | return Unicode normalization.

The JavaScript string.normalize() method is used to normalize the given string. It returns the Unicode normal form of the given string. When the given input is not a string, it will convert it into a string.

It takes the type/form in which the normalized string is to be returned finally as the only parameter. There are 4 normal forms:

“NFC” – Canonical Decomposition that followed by the Canonical Composition.

“NFD” – Canonical Decomposition

“NFKC” – It refers to the Compatibility Decomposition that is followed by Canonical Composition.

“NFKD” – Compatibility┬áDecomposition

Return value:

The value returned by this method is the Unicode Normalization form of the given string.

You may have heard of Unicode. It is nothing but simply assigning a unique numeric value to each character called the code-point. Similarly, we can relate this to ASCII in electronic communication standards. It involves assigning a unique value to each character.

When we call the normalize() method without passing parameter, it uses the “NFC” form. Also, there’s a possible error thrown named RangeError. This arises when the parameter passes is not one of the above forms.

var str = "Normalization";

var nfc = str.normalize("NFC");    // Normalization
var nfd = str.normalize("NFD");    // Normalization
var nfkc = str.normalize("NFKC");  // Normalization
var nfkc = str.normalize("NFKD");  // Normalization


Finally, If you have any queries or doubts related to JavaScript string.normalize() method, simply comment in the comment section provided below.

Also, read:

Leave a Reply

Your email address will not be published. Required fields are marked *