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

String.prototype.normalize() - JavaScript | MDN

Cette page a t traduite partir de l'anglais par la communaut. Vous pouvez contribuer en rejoignant la communaut francophone sur MDN Web Docs.

View in English Always switch to English

String.prototype.normalize()

Baseline
Large disponibilit

Cette fonctionnalit est bien tablie et fonctionne sur de nombreux appareils et versions de navigateurs. Elle est disponible sur tous les navigateurs depuis septembre 2016.

La mthode normalize() permet de renvoyer la forme normalise Unicode d'une chane de caractres.

Dans cet article

Exemple interactif

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

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

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

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

Syntaxe

js
str.normalize([form]);

Paramtres

form

Paramtre optionnel. Une chane parmi "NFC", "NFD", "NFKC", ou "NFKD", dfinissant la forme de normalisation Unicode utiliser. Si le paramtre n'est pas prcis ou vaut undefined, la valeur par dfaut utilise sera "NFC".

  • NFC - Normalization Form Canonical Composition.
  • NFD - Normalization Form Canonical Decomposition.
  • NFKC - Normalization Form Compatibility Composition.
  • NFKD - Normalization Form Compatibility Decomposition.

Valeur de retour

Une chane de caractres qui est le forme Unicode normalise de la chane appelante.

Exceptions

RangeError

Une exception RangeError est envoye si le paramtre form n'est pas une des valeurs dfinies ci-avant.

Description

La mthode normalize() renvoie la forme normalise Unicode de la chane de caractres. Elle n'affecte pas la valeur de la chane.

Exemples

js
// Chane initiale

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

// Forme canonique compose (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(); // la mme chane que prcdemment

// Forme canonique dcompose (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"

// Forme compose compatible (NFKC)

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

// Forme dcompose compatible (NFKD)

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

Spcifications

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

Compatibilit des navigateurs

Voir aussi


Web Proxy Viewer  |  New URL  |  Original Page