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

String.prototype.normalize() - JavaScript | MDN

This page was translated from English by the community. Learn more and join the MDN Web Docs community.

View in English Always switch to English

String.prototype.normalize()

Baseline
Widely available

This feature is well established and works across many devices and browser versions. Its been available across browsers since 2016 ..

normalize() ( , ).

- , .

: - - , code point .

- - - code point -, .

'' 'ae', ,

In this article

str.normalize([form])

form

"NFC", "NFD", "NFKC" "NFKD", . undefined, "NFC".

  • NFC (Normalization Form Canonical Composition, 'NFC'), ;
  • NFD (Normalization Form Canonical Decomposition, 'NFD');
  • NFKC (Normalization Form Compatibility Composition, 'NFKC');
  • NFKD (Normalization Form Compatibility Decomposition, 'NFKD').

RangeError

form , RangeError.

normalize() . .

: normalize()

js
let valueStr = ["h", "", "", "ae", "g", ""],
  normArr = valueStr.map(function (text) {
    return text.normalize(); // (  'NFC') normArr ( ) -> [ae, g, h, , , ]
    //return text.normalize('NFD'); // normArr ( ) -> [ae, g, g, h, h, ]
    //return text.normalize('NFKC'); // normArr ( ) -> [ae, g, h, , , ]
    //return text.normalize('NFKD'); // normArr ( ) -> [ae, g, g, h, h, ]
  });

//     ,    , :
normArr.sort(function (f, s) {
  if (f < s) {
    return -1;
  } else if (f === s) {
    return 0;
  } else {
    return 1;
  }
});

//        .          
let valueStrNorm = ["h", "s", "", "", "", "ae", "g", ""];
valueStrNorm.sort(function (first, second) {
  let fN = first.normalize(),
    sN = second.normalize("NFKC");

  if (fN < sN) {
    return -1;
  } else if (fN === sN) {
    return 0;
  } else {
    return 1;
  }
});

valueStrNorm.join(", "); //-> ae, g, h, s, , , , 

Specification
ECMAScript 2027 LanguageSpecification
# sec-string.prototype.normalize


Web Proxy Viewer  |  New URL  |  Original Page