[ Web Proxy ]
URL:
Viewing: https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/String/normalize [Back]  [Original]

String.prototype.normalize() - JavaScript | MDN

MDN Web Docs

View in English Always switch to English

String.prototype.normalize()

Baseline

20169

normalize() String Unicode

const name1 = "\u0041\u006d\u00e9\u006c\u0069\u0065";
const name2 = "\u0041\u006d\u0065\u0301\u006c\u0069\u0065";

console.log(`${name1}, ${name2}`);
// : "Amlie, Amlie"
console.log(name1 === name2);
// : false
console.log(name1.length === name2.length);
// : false

const name1NFC = name1.normalize("NFC");
const name2NFC = name2.normalize("NFC");

console.log(`${name1NFC}, ${name2NFC}`);
// : "Amlie, Amlie"
console.log(name1NFC === name2NFC);
// : true
console.log(name1NFC.length === name2NFC.length);
// : true

js
normalize()
normalize(form)

form

Unicode "NFC", "NFD", "NFKC", "NFKD" undefined "NFC"

"NFC"

C

"NFD"

D

"NFKC"

KC

"NFKD"

KD

Unicode

RangeError

form

Unicode "A" U+0041 ""

  • U+00F1
  • "n" (U+006E) (U+0303)
js
const string1 = "\u00F1";
const string2 = "\u006E\u0303";

console.log(string1); // 
console.log(string2); // 

js
const string1 = "\u00F1"; // 
const string2 = "\u006E\u0303"; // 

console.log(string1 === string2); // false
console.log(string1.length); // 1
console.log(string2.length); // 2

normalize() 2 1 1

Unicode 2

normalize() "NFD" "NFC" ""

js
let string1 = "\u00F1"; // 
let string2 = "\u006E\u0303"; // 

string1 = string1.normalize("NFD");
string2 = string2.normalize("NFD");

console.log(string1 === string2); // true
console.log(string1.length); // 2
console.log(string2.length); // 2

"NFD" 2 "NFD" "" "\u006E\u0303"

"NFC" "" "\u00F1"

js
let string1 = "\u00F1"; // 
let string2 = "\u006E\u0303"; // 

string1 = string1.normalize("NFC");
string2 = string2.normalize("NFC");

console.log(string1 === string2); // true
console.log(string1.length); // 1
console.log(string2.length); // 1
console.log(string2.codePointAt(0).toString(16)); // f1

Unicode 2

  • U+FB00 "" 2 U+0066 ("ff")
  • U+24B9 "" U+0044 ("D")

normalize() "NFKD" "NFKC"

js
let string1 = "\uFB00";
let string2 = "\u0066\u0066";

console.log(string1); // 
console.log(string2); // ff
console.log(string1 === string2); // false
console.log(string1.length); // 1
console.log(string2.length); // 2

string1 = string1.normalize("NFKD");
string2 = string2.normalize("NFKD");

console.log(string1); // ff <- 
console.log(string2); // ff
console.log(string1 === string2); // true
console.log(string1.length); // 2
console.log(string2.length); // 2

"f"

"NFKD" "NFKC"

normalize()

js
// 

// U+1E9B: LATIN SMALL LETTER LONG S WITH DOT ABOVE
// U+0323: COMBINING DOT BELOW
const str = "\u1E9B\u0323";

//  (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

//  (NFD)

// U+017F: LATIN SMALL LETTER LONG S
// U+0323: COMBINING DOT BELOW
// U+0307: COMBINING DOT ABOVE
str.normalize("NFD"); // '\u017F\u0323\u0307'

//  (NFKC)

// U+1E69: LATIN SMALL LETTER S WITH DOT BELOW AND DOT ABOVE
str.normalize("NFKC"); // '\u1E69'

//  (NFKD)

// U+0073: LATIN SMALL LETTER S
// U+0323: COMBINING DOT BELOW
// U+0307: COMBINING DOT ABOVE
str.normalize("NFKD"); // '\u0073\u0323\u0307'

ECMAScript 2027 LanguageSpecification
# sec-string.prototype.normalize


Web Proxy Viewer  |  New URL  |  Original Page