From 0c354000990d8662066f6eb2f6b9e377f25cb355 Mon Sep 17 00:00:00 2001 From: "Queen Vinyl Da.i'gyu-Kazotetsu" Date: Fri, 28 Jul 2023 01:43:12 -0700 Subject: [PATCH] fr: Format /web/javascript using Prettier (part 4) (#14642) --- .../intl/datetimeformat/formatrange/index.md | 18 +-- .../formatrangetoparts/index.md | 6 +- .../datetimeformat/formattoparts/index.md | 67 ++++----- .../intl/datetimeformat/index.md | 63 +++++---- .../datetimeformat/resolvedoptions/index.md | 10 +- .../supportedlocalesof/index.md | 6 +- .../intl/displaynames/displaynames/index.md | 2 +- .../global_objects/intl/displaynames/index.md | 58 ++++---- .../intl/displaynames/of/index.md | 16 +-- .../displaynames/resolvedoptions/index.md | 10 +- .../displaynames/supportedlocalesof/index.md | 10 +- .../intl/getcanonicallocales/index.md | 2 +- .../reference/global_objects/intl/index.md | 6 +- .../intl/listformat/formattoparts/index.md | 9 +- .../global_objects/intl/listformat/index.md | 27 +++- .../intl/listformat/listformat/index.md | 29 ++-- .../intl/listformat/resolvedoptions/index.md | 6 +- .../listformat/supportedlocalesof/index.md | 6 +- .../intl/locale/basename/index.md | 2 +- .../intl/locale/calendar/index.md | 2 +- .../intl/locale/casefirst/index.md | 2 +- .../intl/locale/collation/index.md | 2 +- .../intl/locale/getweekinfo/index.md | 4 +- .../intl/locale/language/index.md | 2 +- .../intl/locale/locale/index.md | 6 +- .../intl/locale/maximize/index.md | 6 +- .../intl/locale/minimize/index.md | 7 +- .../intl/locale/numberingsystem/index.md | 4 +- .../intl/locale/numeric/index.md | 2 +- .../intl/locale/region/index.md | 2 +- .../intl/locale/script/index.md | 2 +- .../intl/locale/tostring/index.md | 7 +- .../intl/numberformat/format/index.md | 4 +- .../intl/numberformat/formatrange/index.md | 3 +- .../numberformat/formatrangetoparts/index.md | 18 +-- .../intl/numberformat/formattoparts/index.md | 27 ++-- .../global_objects/intl/numberformat/index.md | 40 ++++-- .../intl/numberformat/numberformat/index.md | 70 +++++----- .../numberformat/resolvedoptions/index.md | 14 +- .../numberformat/supportedlocalesof/index.md | 2 +- .../global_objects/intl/pluralrules/index.md | 10 +- .../intl/pluralrules/pluralrules/index.md | 32 ++--- .../intl/pluralrules/resolvedoptions/index.md | 12 +- .../intl/pluralrules/select/index.md | 12 +- .../intl/pluralrules/selectrange/index.md | 6 +- .../pluralrules/supportedlocalesof/index.md | 6 +- .../intl/relativetimeformat/format/index.md | 8 +- .../relativetimeformat/formattoparts/index.md | 2 +- .../intl/relativetimeformat/index.md | 6 +- .../relativetimeformat/index.md | 12 +- .../resolvedoptions/index.md | 10 +- .../supportedlocalesof/index.md | 6 +- .../global_objects/intl/segmenter/index.md | 9 +- .../intl/segmenter/resolvedoptions/index.md | 10 +- .../intl/segmenter/segment/index.md | 14 +- .../segment/segments/@@iterator/index.md | 4 +- .../segment/segments/containing/index.md | 6 +- .../intl/segmenter/segmenter/index.md | 13 +- .../segmenter/supportedlocalesof/index.md | 10 +- .../intl/supportedvaluesof/index.md | 28 ++-- .../global_objects/isfinite/index.md | 21 ++- .../reference/global_objects/isnan/index.md | 46 +++--- .../global_objects/json/parse/index.md | 20 +-- .../global_objects/json/stringify/index.md | 131 +++++++++++------- .../global_objects/map/@@iterator/index.md | 2 +- .../global_objects/map/@@species/index.md | 6 +- .../global_objects/map/clear/index.md | 6 +- .../global_objects/map/delete/index.md | 2 +- .../global_objects/map/entries/index.md | 2 +- .../global_objects/map/foreach/index.md | 11 +- .../reference/global_objects/map/get/index.md | 6 +- .../reference/global_objects/map/has/index.md | 4 +- .../reference/global_objects/map/index.md | 76 +++++----- .../global_objects/map/keys/index.md | 2 +- .../reference/global_objects/map/map/index.md | 10 +- .../reference/global_objects/map/set/index.md | 4 +- .../global_objects/map/size/index.md | 2 +- .../global_objects/map/values/index.md | 2 +- .../global_objects/math/abs/index.md | 18 +-- .../global_objects/math/acos/index.md | 12 +- .../global_objects/math/acosh/index.md | 10 +- .../global_objects/math/asin/index.md | 12 +- .../global_objects/math/asinh/index.md | 18 +-- .../global_objects/math/atan/index.md | 6 +- .../global_objects/math/atan2/index.md | 2 +- .../global_objects/math/atanh/index.md | 22 +-- .../global_objects/math/cbrt/index.md | 4 +- .../global_objects/math/ceil/index.md | 44 +++--- .../global_objects/math/clz32/index.md | 31 +++-- .../global_objects/math/cos/index.md | 8 +- .../global_objects/math/cosh/index.md | 18 ++- .../reference/global_objects/math/e/index.md | 2 +- .../global_objects/math/exp/index.md | 6 +- .../global_objects/math/expm1/index.md | 12 +- .../global_objects/math/floor/index.md | 10 +- .../global_objects/math/fround/index.md | 10 +- .../global_objects/math/hypot/index.md | 22 +-- .../global_objects/math/imul/index.md | 28 ++-- .../global_objects/math/ln10/index.md | 2 +- .../global_objects/math/log/index.md | 8 +- 100 files changed, 802 insertions(+), 651 deletions(-) diff --git a/files/fr/web/javascript/reference/global_objects/intl/datetimeformat/formatrange/index.md b/files/fr/web/javascript/reference/global_objects/intl/datetimeformat/formatrange/index.md index dd615dae269091..265b455cf4cad4 100644 --- a/files/fr/web/javascript/reference/global_objects/intl/datetimeformat/formatrange/index.md +++ b/files/fr/web/javascript/reference/global_objects/intl/datetimeformat/formatrange/index.md @@ -13,7 +13,7 @@ La méthode **`Intl.DateTimeFormat.prototype.formatRange()`** permet de formater ## Syntaxe ```js -formatRange(dateDébut, dateFin) +formatRange(dateDébut, dateFin); ``` ## Exemples @@ -31,11 +31,11 @@ let date3 = new Date(Date.UTC(2007, 0, 20, 10, 0, 0)); // > 'Sat, 20 Jan 2007 10:00:00 GMT' let fmt1 = new Intl.DateTimeFormat("en", { - year: '2-digit', - month: 'numeric', - day: 'numeric', - hour: 'numeric', - minute: 'numeric' + year: "2-digit", + month: "numeric", + day: "numeric", + hour: "numeric", + minute: "numeric", }); console.log(fmt1.format(date1)); console.log(fmt1.formatRange(date1, date2)); @@ -45,9 +45,9 @@ console.log(fmt1.formatRange(date1, date3)); // > '1/10/07, 10:00 AM – 1/20/07, 10:00 AM' let fmt2 = new Intl.DateTimeFormat("en", { - year: 'numeric', - month: 'short', - day: 'numeric' + year: "numeric", + month: "short", + day: "numeric", }); console.log(fmt2.format(date1)); console.log(fmt2.formatRange(date1, date2)); diff --git a/files/fr/web/javascript/reference/global_objects/intl/datetimeformat/formatrangetoparts/index.md b/files/fr/web/javascript/reference/global_objects/intl/datetimeformat/formatrangetoparts/index.md index 657402fbb70622..9755d03c7ab4a8 100644 --- a/files/fr/web/javascript/reference/global_objects/intl/datetimeformat/formatrangetoparts/index.md +++ b/files/fr/web/javascript/reference/global_objects/intl/datetimeformat/formatrangetoparts/index.md @@ -11,7 +11,7 @@ La fonction **`Intl.DateTimeFormat.prototype.formatRangeToParts()`** permet, sel ## Syntaxe ```js -Intl.DateTimeFormat.prototype.formatRangeToParts(dateDebut, dateFin) +Intl.DateTimeFormat.prototype.formatRangeToParts(dateDebut, dateFin); ``` ## Exemples @@ -27,8 +27,8 @@ let date2 = new Date(Date.UTC(2007, 0, 10, 11, 0, 0)); // > 'Wed, 10 Jan 2007 11:00:00 GMT' let fmt = new Intl.DateTimeFormat("en", { - hour: 'numeric', - minute: 'numeric' + hour: "numeric", + minute: "numeric", }); console.log(fmt.formatRange(date1, date2)); diff --git a/files/fr/web/javascript/reference/global_objects/intl/datetimeformat/formattoparts/index.md b/files/fr/web/javascript/reference/global_objects/intl/datetimeformat/formattoparts/index.md index a3c94acfca4c83..587ad225f8349a 100644 --- a/files/fr/web/javascript/reference/global_objects/intl/datetimeformat/formattoparts/index.md +++ b/files/fr/web/javascript/reference/global_objects/intl/datetimeformat/formattoparts/index.md @@ -11,7 +11,7 @@ La méthode **`Intl.DateTimeFormat.prototype.formatToParts()`** permet de mettre ## Syntaxe ```js -Intl.DateTimeFormat.prototype.formatToParts(date) +Intl.DateTimeFormat.prototype.formatToParts(date); ``` ### Paramètres @@ -67,15 +67,15 @@ Les types possibles sont : var date = Date.UTC(2012, 11, 17, 3, 0, 42); var formatter = new Intl.DateTimeFormat("en-us", { - weekday: 'long', - year: 'numeric', - month: 'numeric', - day: 'numeric', - hour: 'numeric', - minute: 'numeric', - second: 'numeric', + weekday: "long", + year: "numeric", + month: "numeric", + day: "numeric", + hour: "numeric", + minute: "numeric", + second: "numeric", hour12: true, - timeZone: "UTC" + timeZone: "UTC", }); formatter.format(date); @@ -89,33 +89,38 @@ formatter.formatToParts(date); // return value: [ - { type: 'weekday', value: 'Monday' }, - { type: 'separator', value: ', ' }, - { type: 'month', value: '12' }, - { type: 'literal', value: '/' }, - { type: 'day', value: '17' }, - { type: 'literal', value: '/' }, - { type: 'year', value: '2012' }, - { type: 'literal', value: ', ' }, - { type: 'hour', value: '3' }, - { type: 'literal', value: ':' }, - { type: 'minute', value: '00' }, - { type: 'literal', value: ':' }, - { type: 'second', value: '42' }, - { type: 'literal', value: ' ' }, - { type: 'dayPeriod', value: 'AM' } -] + { type: "weekday", value: "Monday" }, + { type: "separator", value: ", " }, + { type: "month", value: "12" }, + { type: "literal", value: "/" }, + { type: "day", value: "17" }, + { type: "literal", value: "/" }, + { type: "year", value: "2012" }, + { type: "literal", value: ", " }, + { type: "hour", value: "3" }, + { type: "literal", value: ":" }, + { type: "minute", value: "00" }, + { type: "literal", value: ":" }, + { type: "second", value: "42" }, + { type: "literal", value: " " }, + { type: "dayPeriod", value: "AM" }, +]; ``` L'information étant décomposée, on peut alors la mettre en forme et la recomposée de façon adaptée : ```js -var dateString = formatter.formatToParts(date).map(({type, value}) => { - switch (type) { - case 'dayPeriod': return `${value}`; - default : return value; - } -}).reduce((string, part) => string + part); +var dateString = formatter + .formatToParts(date) + .map(({ type, value }) => { + switch (type) { + case "dayPeriod": + return `${value}`; + default: + return value; + } + }) + .reduce((string, part) => string + part); console.log(formatter.format(date)); // "Monday, 12/17/2012, 3:00:42 AM" diff --git a/files/fr/web/javascript/reference/global_objects/intl/datetimeformat/index.md b/files/fr/web/javascript/reference/global_objects/intl/datetimeformat/index.md index 63fc0c13f2aa34..462a991db7bba3 100644 --- a/files/fr/web/javascript/reference/global_objects/intl/datetimeformat/index.md +++ b/files/fr/web/javascript/reference/global_objects/intl/datetimeformat/index.md @@ -59,30 +59,30 @@ var date = new Date(Date.UTC(2012, 11, 20, 3, 0, 0)); // fuseau horaire CEST // l'anglais américain utilise l'ordre mois-jour-année -console.log(new Intl.DateTimeFormat('en-US').format(date)); +console.log(new Intl.DateTimeFormat("en-US").format(date)); // → "12/20/2012" // l'anglais britannique utilise l'ordre jour-mois-année -console.log(new Intl.DateTimeFormat('en-GB').format(date)); +console.log(new Intl.DateTimeFormat("en-GB").format(date)); // → "20/12/2012" // le coréen utilise l'ordre année-mois-jour -console.log(new Intl.DateTimeFormat('ko-KR').format(date)); +console.log(new Intl.DateTimeFormat("ko-KR").format(date)); // → "2012. 12. 20." // l'arabe, dans la plupart des pays arabophones, utilise les chiffres arabes -console.log(new Intl.DateTimeFormat('ar-EG').format(date)); +console.log(new Intl.DateTimeFormat("ar-EG").format(date)); // → "٢٠‏/١٢‏/٢٠١٢" // en ce qui concerne le japonais, les applications peuvent // souhaiter utiliser le calendrier japonais // pour lequel 2012 était l'année 24 de l'ère Heisei -console.log(new Intl.DateTimeFormat('ja-JP-u-ca-japanese').format(date)); +console.log(new Intl.DateTimeFormat("ja-JP-u-ca-japanese").format(date)); // → "24/12/20" // quand une locale non prise en charge est demandée (par exemple le balinais) // il est possible de fournir une locale de recours (ici l'indonésien) -console.log(new Intl.DateTimeFormat(['ban', 'id']).format(date)); +console.log(new Intl.DateTimeFormat(["ban", "id"]).format(date)); // → "20/12/2012" ``` @@ -94,49 +94,64 @@ Les formats de la date et de l'heure peuvent être personnalisés en utilisant l var date = new Date(Date.UTC(2012, 11, 20, 3, 0, 0)); // fournir le jour de la semaine avec une date longue -var options = {weekday: "long", year: "numeric", month: "long", day: "numeric"}; -console.log(new Intl.DateTimeFormat('de-DE', options).format(date)); +var options = { + weekday: "long", + year: "numeric", + month: "long", + day: "numeric", +}; +console.log(new Intl.DateTimeFormat("de-DE", options).format(date)); // → "Donnerstag, 20. Dezember 2012" // une application peut vouloir utiliser UTC et le rendre visible -options.timeZone = 'UTC'; -options.timeZoneName = 'short'; -console.log(new Intl.DateTimeFormat('en-US', options).format(date)); +options.timeZone = "UTC"; +options.timeZoneName = "short"; +console.log(new Intl.DateTimeFormat("en-US", options).format(date)); // → "Thursday, December 20, 2012, GMT" // parfois, il faut plus de précision -options = {hour: "numeric", minute: "numeric", second: "numeric", - timeZoneName: "short"}; -console.log(new Intl.DateTimeFormat('en-AU', options).format(date)); +options = { + hour: "numeric", + minute: "numeric", + second: "numeric", + timeZoneName: "short", +}; +console.log(new Intl.DateTimeFormat("en-AU", options).format(date)); // → "2:00:00 pm AEDT" // voire beaucoup plus de précision options.fractionalSecondDigits = 3; // le nombre de chiffres décimaux pour les fractions de secondes -console.log(new Intl.DateTimeFormat('en-AU', options).format(date)); +console.log(new Intl.DateTimeFormat("en-AU", options).format(date)); // → "2:00:00.200 pm AEDT" // parfois, même les USA ont besoin d'afficher une heure sur 24h -options = {year: "numeric", month: "numeric", day: "numeric", - hour: "numeric", minute: "numeric", second: "numeric", - hour12: false}; -console.log(new Intl.DateTimeFormat('en-US', options)); +options = { + year: "numeric", + month: "numeric", + day: "numeric", + hour: "numeric", + minute: "numeric", + second: "numeric", + hour12: false, +}; +console.log(new Intl.DateTimeFormat("en-US", options)); // → "12/19/2012, 19:00:00" // pour utiliser la locale par défaut du navigateur, on utilise default -console.log(new Intl.DateTimeFormat('default', options).format(date)); +console.log(new Intl.DateTimeFormat("default", options).format(date)); // → "12/19/2012, 19:00:00" (peut varier selon la locale du navigateur) // on peut aussi inclure la période du jour -options = {hour: "numeric", dayPeriod: "short"}; -console.log(new Intl.DateTimeFormat('en-US', options).format(date)); +options = { hour: "numeric", dayPeriod: "short" }; +console.log(new Intl.DateTimeFormat("en-US", options).format(date)); // → "4 at night" ``` Le calendrier et la numération utilisés peuvent être choisis indépendamment avec l'argument `options` : ```js -var options = {calendar: 'chinese', numberingSystem: 'arab'}; -var dateFormat = new Intl.DateTimeFormat('default', options); +var options = { calendar: "chinese", numberingSystem: "arab" }; +var dateFormat = new Intl.DateTimeFormat("default", options); var usedOptions = dateFormat.resolvedOptions(); console.log(usedOptions.calendar); diff --git a/files/fr/web/javascript/reference/global_objects/intl/datetimeformat/resolvedoptions/index.md b/files/fr/web/javascript/reference/global_objects/intl/datetimeformat/resolvedoptions/index.md index 10bd960798914f..89ac1969979c28 100644 --- a/files/fr/web/javascript/reference/global_objects/intl/datetimeformat/resolvedoptions/index.md +++ b/files/fr/web/javascript/reference/global_objects/intl/datetimeformat/resolvedoptions/index.md @@ -13,7 +13,7 @@ La méthode **`Intl.DateTimeFormat.prototype.resolvedOptions()`** renvoie un nou ## Syntaxe ```js -resolvedOptions() +resolvedOptions(); ``` ### Valeur de retour @@ -45,11 +45,11 @@ La valeur renvoyée par cette méthode contient les propriétés suivantes : var germanFakeRegion = new Intl.DateTimeFormat("de-XX", { timeZone: "UTC" }); var usedOptions = germanFakeRegion.resolvedOptions(); -usedOptions.locale; // "de" -usedOptions.calendar; // "gregory" +usedOptions.locale; // "de" +usedOptions.calendar; // "gregory" usedOptions.numberingSystem; // "latn" -usedOptions.timeZone; // "UTC" -usedOptions.month; // "numeric" +usedOptions.timeZone; // "UTC" +usedOptions.month; // "numeric" ``` ## Spécifications diff --git a/files/fr/web/javascript/reference/global_objects/intl/datetimeformat/supportedlocalesof/index.md b/files/fr/web/javascript/reference/global_objects/intl/datetimeformat/supportedlocalesof/index.md index 6bfdd16c4945bb..207193e79f6019 100644 --- a/files/fr/web/javascript/reference/global_objects/intl/datetimeformat/supportedlocalesof/index.md +++ b/files/fr/web/javascript/reference/global_objects/intl/datetimeformat/supportedlocalesof/index.md @@ -43,8 +43,10 @@ Si on dispose d'un environnement qui supporte les locales indonésienne et allem ```js var locales = ["ban", "id-u-co-pinyin", "de-ID"]; -var options = {localeMatcher: "lookup"}; -console.log(Intl.DateTimeFormat.supportedLocalesOf(locales, options).join(", ")); +var options = { localeMatcher: "lookup" }; +console.log( + Intl.DateTimeFormat.supportedLocalesOf(locales, options).join(", "), +); // → "id-u-co-pinyin, de-ID" ``` diff --git a/files/fr/web/javascript/reference/global_objects/intl/displaynames/displaynames/index.md b/files/fr/web/javascript/reference/global_objects/intl/displaynames/displaynames/index.md index 1f9f7a63da46f0..baa365af7358ec 100644 --- a/files/fr/web/javascript/reference/global_objects/intl/displaynames/displaynames/index.md +++ b/files/fr/web/javascript/reference/global_objects/intl/displaynames/displaynames/index.md @@ -62,7 +62,7 @@ new Intl.DisplayNames([langues[, options]]) Dans son utilisation simple, sans spécifier de langue, une chaine dans la langue locale par défaut et avec les options par défaut sera retournée. ```js -console.log((new Intl.DisplayNames()).of('US')); +console.log(new Intl.DisplayNames().of("US")); // Expected output: 'us' ``` diff --git a/files/fr/web/javascript/reference/global_objects/intl/displaynames/index.md b/files/fr/web/javascript/reference/global_objects/intl/displaynames/index.md index 3f9d8b08cd96c9..09f688fbc81065 100644 --- a/files/fr/web/javascript/reference/global_objects/intl/displaynames/index.md +++ b/files/fr/web/javascript/reference/global_objects/intl/displaynames/index.md @@ -57,19 +57,19 @@ Pour créer un objet `Intl.DisplayNames` pour une langue et obtenir le nom corre ```js // Obtenir le nom d'une langue en anglais -let nomsLangues= new Intl.DisplayNames(['en'], {type: 'language'}); -nomsLangues.of('fr'); // "French" -nomsLangues.of('de'); // "German" -nomsLangues.of('fr-CA'); // "Canadian French" -nomsLangues.of('zh-Hant'); // "Traditional Chinese" -nomsLangues.of('en-US'); // "American English" -nomsLangues.of('zh-TW'); // "Chinese (Taiwan)" +let nomsLangues = new Intl.DisplayNames(["en"], { type: "language" }); +nomsLangues.of("fr"); // "French" +nomsLangues.of("de"); // "German" +nomsLangues.of("fr-CA"); // "Canadian French" +nomsLangues.of("zh-Hant"); // "Traditional Chinese" +nomsLangues.of("en-US"); // "American English" +nomsLangues.of("zh-TW"); // "Chinese (Taiwan)" // Obtenir le nom d'une langue en chinois traditionnel -nomsLangues = new Intl.DisplayNames(['zh-Hant'], {type: 'language'}); -nomsLangues.of('fr'); // "法文" -nomsLangues.of('zh'); // "中文" -nomsLangues.of('de'); // "德文" +nomsLangues = new Intl.DisplayNames(["zh-Hant"], { type: "language" }); +nomsLangues.of("fr"); // "法文" +nomsLangues.of("zh"); // "中文" +nomsLangues.of("de"); // "德文" ``` ### Affichage des noms de systèmes d'écriture @@ -80,16 +80,16 @@ Pour créer un objet `Intl.DisplayNames` pour une langue et obtenir le nom corre ```js // Obtenir le nom d'un système d'écriture en anglais -let nomsSystèmes = new Intl.DisplayNames(['en'], {type: 'script'}); -nomsSystèmes.of('Latn'); // "Latin" -nomsSystèmes.of('Arab'); // "Arabic" -nomsSystèmes.of('Kana'); // "Katakana" +let nomsSystèmes = new Intl.DisplayNames(["en"], { type: "script" }); +nomsSystèmes.of("Latn"); // "Latin" +nomsSystèmes.of("Arab"); // "Arabic" +nomsSystèmes.of("Kana"); // "Katakana" // Obtenir le nom d'un système d'écriture en chinois traditionnel -nomsSystèmes = new Intl.DisplayNames(['zh-Hant'], {type: 'script'}); -nomsSystèmes.of('Latn'); // "拉丁文" -nomsSystèmes.of('Arab'); // "阿拉伯文" -nomsSystèmes.of('Kana'); // "片假名" +nomsSystèmes = new Intl.DisplayNames(["zh-Hant"], { type: "script" }); +nomsSystèmes.of("Latn"); // "拉丁文" +nomsSystèmes.of("Arab"); // "阿拉伯文" +nomsSystèmes.of("Kana"); // "片假名" ``` ### Affichage des noms de devises @@ -98,18 +98,18 @@ Pour créer un objet `Intl.DisplayNames` pour une langue et obtenir le nom corre ```js // Obtenir le nom d'une devise in English -let nomsDevises = new Intl.DisplayNames(['en'], {type: 'currency'}); -nomsDevises.of('USD'); // "US Dollar" -nomsDevises.of('EUR'); // "Euro" -nomsDevises.of('TWD'); // "New Taiwan Dollar" -nomsDevises.of('CNY'); // "Chinese Yuan" +let nomsDevises = new Intl.DisplayNames(["en"], { type: "currency" }); +nomsDevises.of("USD"); // "US Dollar" +nomsDevises.of("EUR"); // "Euro" +nomsDevises.of("TWD"); // "New Taiwan Dollar" +nomsDevises.of("CNY"); // "Chinese Yuan" // Obtenir le nom d'une devise in Traditional Chinese -nomsDevises = new Intl.DisplayNames(['zh-Hant'], {type: 'currency'}); -nomsDevises.of('USD'); // "美元" -nomsDevises.of('EUR'); // "歐元" -nomsDevises.of('TWD'); // "新台幣" -nomsDevises.of('CNY'); // "人民幣" +nomsDevises = new Intl.DisplayNames(["zh-Hant"], { type: "currency" }); +nomsDevises.of("USD"); // "美元" +nomsDevises.of("EUR"); // "歐元" +nomsDevises.of("TWD"); // "新台幣" +nomsDevises.of("CNY"); // "人民幣" ``` ## Spécifications diff --git a/files/fr/web/javascript/reference/global_objects/intl/displaynames/of/index.md b/files/fr/web/javascript/reference/global_objects/intl/displaynames/of/index.md index c36251fd5a0b83..888a5061b9d337 100644 --- a/files/fr/web/javascript/reference/global_objects/intl/displaynames/of/index.md +++ b/files/fr/web/javascript/reference/global_objects/intl/displaynames/of/index.md @@ -12,7 +12,7 @@ La méthode **`Intl.DisplayNames.prototype.of()`** prend comme argument un code ## Syntaxe ```js -of(code) +of(code); ``` ### Paramètres @@ -23,7 +23,7 @@ of(code) - Si le type est `"region"`, le code sera [un code de région ISO-3166 sur deux lettres](https://www.iso.org/iso-3166-country-codes.html), ou [un code de région géographique sur trois chiffres UN M49](https://unstats.un.org/unsd/methodology/m49/). - Si le type est `"script"`, le code sera [un code de script ISO-15924 sur quatre lettres](https://unicode.org/iso15924/iso15924-codes.html). - - Si le type est `"language"`, le code sera de la forme d'une sous-séquence _languageCode_ \["-"_scriptCode_] \["-" _regionCode_ ] \*("-" _variant_ ) de la grammaire unicode_language_id pour [la grammaire des identifiants de locales et de langues Unicode UTS 35](https://unicode.org/reports/tr35/#Unicode_language_identifier). _languageCode_ est soit un code de langue ISO 639-1 sur deux lettres ou un code de langue ISO 639-2 sur trois lettres. + - Si le type est `"language"`, le code sera de la forme d'une sous-séquence _languageCode_ \["-"_scriptCode_] \["-" _regionCode_ ] ("-" _variant_ ) de la grammaire unicode\_language\_id pour [la grammaire des identifiants de locales et de langues Unicode UTS 35](https://unicode.org/reports/tr35/#Unicode_language_identifier). _languageCode_ est soit un code de langue ISO 639-1 sur deux lettres ou un code de langue ISO 639-2 sur trois lettres. - Si le type est `"currency"`, le code sera [un code à 3 lettres ISO 4217](https://www.iso.org/iso-4217-currency-codes.html). ### Valeur de retour @@ -35,14 +35,14 @@ Une chaîne de caractères formatée spécifique à une locale. ### Utilisation de la méthode of() ```js -let regionNames = new Intl.DisplayNames(['en'], {type: 'region'}); -regionNames.of('419'); // "Latin America" +let regionNames = new Intl.DisplayNames(["en"], { type: "region" }); +regionNames.of("419"); // "Latin America" -let languageNames = new Intl.DisplayNames(['en'], {type: 'language'}); -languageNames.of('fr'); // "French" +let languageNames = new Intl.DisplayNames(["en"], { type: "language" }); +languageNames.of("fr"); // "French" -let currencyNames = new Intl.DisplayNames(['en'], {type: 'currency'}); -currencyNames.of('EUR'); // "Euro" +let currencyNames = new Intl.DisplayNames(["en"], { type: "currency" }); +currencyNames.of("EUR"); // "Euro" ``` ## Spécifications diff --git a/files/fr/web/javascript/reference/global_objects/intl/displaynames/resolvedoptions/index.md b/files/fr/web/javascript/reference/global_objects/intl/displaynames/resolvedoptions/index.md index 881bfb8b9ff0a5..e4337b79ecbb22 100644 --- a/files/fr/web/javascript/reference/global_objects/intl/displaynames/resolvedoptions/index.md +++ b/files/fr/web/javascript/reference/global_objects/intl/displaynames/resolvedoptions/index.md @@ -10,7 +10,7 @@ La méthode **`Intl.DisplayNames.prototype.resolvedOptions()`** renvoie un nouve ## Syntaxe ```js -resolvedOptions() +resolvedOptions(); ``` ### Valeur de retour @@ -35,12 +35,12 @@ L'objet renvoyé par `resolvedOptions()` possède les propriétés suivantes&nbs ### Utiliser resolvedOptions() ```js -const displayNames = new Intl.DisplayNames(['de-DE'], {type: 'region'}); +const displayNames = new Intl.DisplayNames(["de-DE"], { type: "region" }); const usedOptions = displayNames.resolvedOptions(); -console.log(usedOptions.locale); // "de-DE" -console.log(usedOptions.style); // "long" -console.log(usedOptions.type); // "region" +console.log(usedOptions.locale); // "de-DE" +console.log(usedOptions.style); // "long" +console.log(usedOptions.type); // "region" console.log(usedOptions.fallback); // "code" ``` diff --git a/files/fr/web/javascript/reference/global_objects/intl/displaynames/supportedlocalesof/index.md b/files/fr/web/javascript/reference/global_objects/intl/displaynames/supportedlocalesof/index.md index 27640d0d9b96d7..438d5bda770a1a 100644 --- a/files/fr/web/javascript/reference/global_objects/intl/displaynames/supportedlocalesof/index.md +++ b/files/fr/web/javascript/reference/global_objects/intl/displaynames/supportedlocalesof/index.md @@ -10,8 +10,8 @@ La méthode **`Intl.DisplayNames.supportedLocalesOf()`** renvoie un tableau dont ## Syntaxe ```js -Intl.DisplayNames.supportedLocalesOf(locales) -Intl.DisplayNames.supportedLocalesOf(locales, options) +Intl.DisplayNames.supportedLocalesOf(locales); +Intl.DisplayNames.supportedLocalesOf(locales, options); ``` ### Paramètres @@ -36,9 +36,9 @@ Un tableau de chaînes de caractères qui est un sous-ensemble des balises de la Soit un environnement d'exécution qui prend en charge l'indonésien et l'allemand pour les noms d'affichage mais pas le balinais, `supportedLocalesOf` renverra les balises indonésiennes et germaniques inchangées bien que la collation `pinyin` n'est ni pertinente pour les noms d'affichage ou même utilisée pour l'indonésien et qu'un dialecte germanique pour l'indonésien sera peu probablement pris en charge. On notera que c'est l'algorithme "`lookup`" qui est utilisé ici ("`best fit`" pourrait décider que l'indonésien est une correspondance acceptable pour du balinais vu que les locuteurs balinais comprennent l'indonésien et inclure la balise de langue balinaise également). ```js -const locales = ['ban', 'id-u-co-pinyin', 'de-ID']; -const options = { localeMatcher: 'lookup' }; -console.log(Intl.DisplayNames.supportedLocalesOf(locales, options).join(', ')); +const locales = ["ban", "id-u-co-pinyin", "de-ID"]; +const options = { localeMatcher: "lookup" }; +console.log(Intl.DisplayNames.supportedLocalesOf(locales, options).join(", ")); // → "id-u-co-pinyin, de-ID" ``` diff --git a/files/fr/web/javascript/reference/global_objects/intl/getcanonicallocales/index.md b/files/fr/web/javascript/reference/global_objects/intl/getcanonicallocales/index.md index 057e4fc0091f41..420b9c811d7a10 100644 --- a/files/fr/web/javascript/reference/global_objects/intl/getcanonicallocales/index.md +++ b/files/fr/web/javascript/reference/global_objects/intl/getcanonicallocales/index.md @@ -13,7 +13,7 @@ La méthode **`Intl.getCanonicalLocales()`** renvoie un tableau contenant les no ## Syntaxe ```js -Intl.getCanonicalLocales(locales) +Intl.getCanonicalLocales(locales); ``` ### Paramètres diff --git a/files/fr/web/javascript/reference/global_objects/intl/index.md b/files/fr/web/javascript/reference/global_objects/intl/index.md index 5b67c07a5b5d78..7c5feadee46f24 100644 --- a/files/fr/web/javascript/reference/global_objects/intl/index.md +++ b/files/fr/web/javascript/reference/global_objects/intl/index.md @@ -79,9 +79,11 @@ Vous pouvez utiliser Intl pour formater des dates et nombres dans un format qui const compte = 26254.39; const date = new Date("2012-05-24"); -function afficher (langue) { +function afficher(langue) { console.log( - `${new Intl.DateTimeFormat(langue).format(date)} ${new Intl.NumberFormat(langue).format(compte)}` + `${new Intl.DateTimeFormat(langue).format(date)} ${new Intl.NumberFormat( + langue, + ).format(compte)}`, ); } diff --git a/files/fr/web/javascript/reference/global_objects/intl/listformat/formattoparts/index.md b/files/fr/web/javascript/reference/global_objects/intl/listformat/formattoparts/index.md index ba9ac6f92a1ef5..88c6c4bdf41339 100644 --- a/files/fr/web/javascript/reference/global_objects/intl/listformat/formattoparts/index.md +++ b/files/fr/web/javascript/reference/global_objects/intl/listformat/formattoparts/index.md @@ -11,7 +11,7 @@ La méthode **`Intl.ListFormat.prototype.formatToParts()`** renvoie un tableau ( ## Syntaxe ```js -Intl.ListFormat.prototype.formatToParts(list) +Intl.ListFormat.prototype.formatToParts(list); ``` ### Paramètres @@ -34,8 +34,11 @@ Les options de locale et de style utilisées pour le formatage sont fournies lor ## Exemples ```js -const fruits = ['Apple', 'Orange', 'Pineapple']; -const myListFormat = new Intl.ListFormat('en-GB', { style: 'long', type: 'conjunction' }); +const fruits = ["Apple", "Orange", "Pineapple"]; +const myListFormat = new Intl.ListFormat("en-GB", { + style: "long", + type: "conjunction", +}); console.table(myListFormat.formatToParts(fruits)); // [ diff --git a/files/fr/web/javascript/reference/global_objects/intl/listformat/index.md b/files/fr/web/javascript/reference/global_objects/intl/listformat/index.md index 529a64b8fc95cc..a9bea532b4397d 100644 --- a/files/fr/web/javascript/reference/global_objects/intl/listformat/index.md +++ b/files/fr/web/javascript/reference/global_objects/intl/listformat/index.md @@ -34,15 +34,25 @@ L'objet **`Intl.ListFormat`** permet de formater des listes de façon différent Dans l'exemple qui suit, on voit comment créer un formateur de liste pour l'anglais. ```js -const list = ['Motorcycle', 'Bus', 'Car']; +const list = ["Motorcycle", "Bus", "Car"]; - console.log(new Intl.ListFormat('en-GB', { style: 'long', type: 'conjunction' }).format(list)); +console.log( + new Intl.ListFormat("en-GB", { style: "long", type: "conjunction" }).format( + list, + ), +); // > Motorcycle, Bus and Car - console.log(new Intl.ListFormat('en-GB', { style: 'short', type: 'disjunction' }).format(list)); +console.log( + new Intl.ListFormat("en-GB", { style: "short", type: "disjunction" }).format( + list, + ), +); // > Motorcycle, Bus or Car - console.log(new Intl.ListFormat('en-GB', { style: 'narrow', type: 'unit' }).format(list)); +console.log( + new Intl.ListFormat("en-GB", { style: "narrow", type: "unit" }).format(list), +); // > Motorcycle Bus Car ``` @@ -51,8 +61,13 @@ const list = ['Motorcycle', 'Bus', 'Car']; Dans l'exemple qui suit, on voit comment créer un formateur de liste, renvoyant les fragments, pour l'anglais. ```js -const list = ['Motorcycle', 'Bus', 'Car']; -console.log(new Intl.ListFormat('en-GB', { style: 'long', type: 'conjunction' }).formatToParts(list)); +const list = ["Motorcycle", "Bus", "Car"]; +console.log( + new Intl.ListFormat("en-GB", { + style: "long", + type: "conjunction", + }).formatToParts(list), +); // [ { "type": "element", "value": "Motorcycle" }, // { "type": "literal", "value": ", " }, diff --git a/files/fr/web/javascript/reference/global_objects/intl/listformat/listformat/index.md b/files/fr/web/javascript/reference/global_objects/intl/listformat/listformat/index.md index e1b29b766bb444..6400b218131a28 100644 --- a/files/fr/web/javascript/reference/global_objects/intl/listformat/listformat/index.md +++ b/files/fr/web/javascript/reference/global_objects/intl/listformat/listformat/index.md @@ -12,9 +12,9 @@ Le constructeur **`Intl.ListFormat()`** permet de créer des objets [`Intl.ListF ## Syntaxe ```js -new Intl.ListFormat() -new Intl.ListFormat(locales) -new Intl.ListFormat(locales, options) +new Intl.ListFormat(); +new Intl.ListFormat(locales); +new Intl.ListFormat(locales, options); ``` ### Paramètres @@ -29,9 +29,8 @@ new Intl.ListFormat(locales, options) - : - : L'algorithme de correspondance des locales à utiliser. Les valeurs possibles sont "`lookup`" et "`best fit`" ; la valeur par défaut est "`best fit`". Pour plus d'information, voir la page [`Intl`](/fr/docs/Web/JavaScript/Reference/Global_Objects/Intl#négociation_de_la_locale). - `type` - : Le format de sortie produit. Les valeurs possibles sont "`conjunction`" qui indique une liste additive (par exemple "`A, B, et C`"), c'est la valeur par défaut, ou "`disjunction`" qui indique une liste d'options distinctes (par exemple, "`A, B, ou C`"), ou "`unit`" qui indique une liste de valeurs avec des unités (par exemple, "`5 kg, 12 L`"). - - `style` - - : La longueur du message formaté. Les valeurs possibles sont "`long`", la valeur par défaut (par exemple "`A, B, et C`") ; "`short`" (par exemple - "`A, B, C`"), ou "`narrow`" (par exemple, "`A B C`"). Lorsque la valeur de `style` est "`short`" ou "`narrow`", seule la valeur "`unit`" est autorisée pour l'option "type". + - `style` - : La longueur du message formaté. Les valeurs possibles sont "`long`", la valeur par défaut (par exemple "`A, B, et C`") ; "`short`" (par exemple + "`A, B, C`"), ou "`narrow`" (par exemple, "`A B C`"). Lorsque la valeur de `style` est "`short`" ou "`narrow`", seule la valeur "`unit`" est autorisée pour l'option "type". ## Exemples @@ -40,15 +39,25 @@ new Intl.ListFormat(locales, options) L'exemple suivant illustre comment créer un formateur de liste basé sur la langue française. ```js -const list = ['Moto', 'Bus', 'Car']; +const list = ["Moto", "Bus", "Car"]; -console.log(new Intl.ListFormat('fr', { style: 'long', type: 'conjunction' }).format(list)); +console.log( + new Intl.ListFormat("fr", { style: "long", type: "conjunction" }).format( + list, + ), +); // > Moto, Bus et Car -console.log(new Intl.ListFormat('fr', { style: 'short', type: 'disjunction' }).format(list)); +console.log( + new Intl.ListFormat("fr", { style: "short", type: "disjunction" }).format( + list, + ), +); // > Moto, Bus ou Car -console.log(new Intl.ListFormat('fr', { style: 'narrow', type: 'unit' }).format(list)); +console.log( + new Intl.ListFormat("fr", { style: "narrow", type: "unit" }).format(list), +); // > Moto Bus Car ``` diff --git a/files/fr/web/javascript/reference/global_objects/intl/listformat/resolvedoptions/index.md b/files/fr/web/javascript/reference/global_objects/intl/listformat/resolvedoptions/index.md index d8d7b3d3194323..6f53776d17f518 100644 --- a/files/fr/web/javascript/reference/global_objects/intl/listformat/resolvedoptions/index.md +++ b/files/fr/web/javascript/reference/global_objects/intl/listformat/resolvedoptions/index.md @@ -11,7 +11,7 @@ La méthode **`Intl.ListFormat.prototype.resolvedOptions()`** renvoie un nouvel ## Syntaxe ```js -listFormat.resolvedOptions() +listFormat.resolvedOptions(); ``` ### Valeur de retour @@ -36,8 +36,8 @@ const deListFormatter = new Intl.ListFormat("de-DE", { style: "short" }); const usedOptions = de.resolvedOptions(); console.log(usedOptions.locale); // "de-DE" -console.log(usedOptions.style); // "short" -console.log(usedOptions.type); // "conjunction" (la valeur par défaut) +console.log(usedOptions.style); // "short" +console.log(usedOptions.type); // "conjunction" (la valeur par défaut) ``` ## Spécifications diff --git a/files/fr/web/javascript/reference/global_objects/intl/listformat/supportedlocalesof/index.md b/files/fr/web/javascript/reference/global_objects/intl/listformat/supportedlocalesof/index.md index 1b414e459f6b9b..770b76a3599621 100644 --- a/files/fr/web/javascript/reference/global_objects/intl/listformat/supportedlocalesof/index.md +++ b/files/fr/web/javascript/reference/global_objects/intl/listformat/supportedlocalesof/index.md @@ -40,9 +40,9 @@ Cette méthode renvoie un tableau qui est un sous-ensemble des balises de locale Si on dispose d'un environnement (un navigateur par exemple) qui supporte le formatage des listes dans les locales indonésienne, allemande mais pas balinaise, `supportedLocalesOf` renvoie les balises pour l'indonésien et l'allemand quand bien même le formatage des listes pinyin n'est pas utilisée avec l'indonésien et qu'il n'existe pas une version spécifique de l'allemand pour l'Indonésie. On illustre ici l'algorithme `"lookup"`. SI on utilisait `"best fit"` pour trouver les locales correspondantes, on aurait pu avoir une balise supplémentaire pour le balinais en plus car la plupart des balinais comprennent l'indonésien. ```js -const locales = ['ban', 'id-u-co-pinyin', 'de-ID']; -const options = { localeMatcher: 'lookup' }; -console.log(Intl.ListFormat.supportedLocalesOf(locales, options).join(', ')); +const locales = ["ban", "id-u-co-pinyin", "de-ID"]; +const options = { localeMatcher: "lookup" }; +console.log(Intl.ListFormat.supportedLocalesOf(locales, options).join(", ")); // → "id-u-co-pinyin, de-ID" ``` diff --git a/files/fr/web/javascript/reference/global_objects/intl/locale/basename/index.md b/files/fr/web/javascript/reference/global_objects/intl/locale/basename/index.md index 2c1b1f6bca4219..8688cf3cb427a2 100644 --- a/files/fr/web/javascript/reference/global_objects/intl/locale/basename/index.md +++ b/files/fr/web/javascript/reference/global_objects/intl/locale/basename/index.md @@ -41,7 +41,7 @@ console.log(japan.baseName); // Prints out "ja-JP" // Input string indicates language as Dutch and region as Belgium, // but options object overrides the region and sets it to the Netherlands -let dutch = new Intl.Locale("nl-Latn-BE", {region: "NL"}); +let dutch = new Intl.Locale("nl-Latn-BE", { region: "NL" }); console.log(dutch.baseName); // Prints out "nl-Latn-NL" ``` diff --git a/files/fr/web/javascript/reference/global_objects/intl/locale/calendar/index.md b/files/fr/web/javascript/reference/global_objects/intl/locale/calendar/index.md index 44807366372266..3ef24740c97464 100644 --- a/files/fr/web/javascript/reference/global_objects/intl/locale/calendar/index.md +++ b/files/fr/web/javascript/reference/global_objects/intl/locale/calendar/index.md @@ -142,7 +142,7 @@ console.log(frBuddhist.calendar); // affiche "buddhist" dans la console Le constructeur {{jsxref("Locale", "Intl.Locale")}} peut utiliser un argument optionnel qui est un objet permettant de configurer la locale via différentes extensions dont les calendriers. En utilisant la propriété `calendar` de cet objet, on définit le calendrier qui sera utilisé : ```js -let frBuddhist = new Intl.Locale("fr-FR", {calendar: "buddhist"}); +let frBuddhist = new Intl.Locale("fr-FR", { calendar: "buddhist" }); console.log(frBuddhist.calendar); // affiche "buddhist" dans la console ``` diff --git a/files/fr/web/javascript/reference/global_objects/intl/locale/casefirst/index.md b/files/fr/web/javascript/reference/global_objects/intl/locale/casefirst/index.md index acced63ee259e8..fbfd867816369d 100644 --- a/files/fr/web/javascript/reference/global_objects/intl/locale/casefirst/index.md +++ b/files/fr/web/javascript/reference/global_objects/intl/locale/casefirst/index.md @@ -38,7 +38,7 @@ console.log(caseFirstStr.caseFirst); // Prints "upper" Le constructeur [`Intl.Locale`](/fr/docs/Web/JavaScript/Reference/Objets_globaux/Locale) permet d'utiliser un objet de configuration comme deuxième argument. Les propriétés de cet objet seront autant d'extensions Unicode à utiliser pour la locale. Ici, on peut utiliser un objet avec la propriété `caseFirst` pour indiquer l'impact de la casse sur la collation de cette locale : ```js -let caseFirstObj= new Intl.Locale("en-Latn-US", {caseFirst: "lower"}); +let caseFirstObj = new Intl.Locale("en-Latn-US", { caseFirst: "lower" }); console.log(us12hour.caseFirst); // affichera "lower" dans la console. ``` diff --git a/files/fr/web/javascript/reference/global_objects/intl/locale/collation/index.md b/files/fr/web/javascript/reference/global_objects/intl/locale/collation/index.md index 0cf9f45758fe73..4907947c4850a8 100644 --- a/files/fr/web/javascript/reference/global_objects/intl/locale/collation/index.md +++ b/files/fr/web/javascript/reference/global_objects/intl/locale/collation/index.md @@ -157,7 +157,7 @@ console.log(stringColl.collation); // Affichera "emoji" dans la console Le constructeur [`Intl.Locale`](/fr/docs/Web/JavaScript/Reference/Objets_globaux/Locale) possède un deuxième argument optionnel qui est un objet de configuration. Chaque propriété de cet objet pourra permettre de préciser une extension à la locale, y compris un type de collation. Pour définir le type de collation, on pourra utiliser une propriété `collation` sur cet objet avec une des valeurs indiquées ci-avant : ```js -let configColl = new Intl.Locale("en-Latn-US", {collation: "emoji"}); +let configColl = new Intl.Locale("en-Latn-US", { collation: "emoji" }); console.log(configColl.collation); // Affichera "emoji" dans la console ``` diff --git a/files/fr/web/javascript/reference/global_objects/intl/locale/getweekinfo/index.md b/files/fr/web/javascript/reference/global_objects/intl/locale/getweekinfo/index.md index 4e1f4a8e53da09..2f1dd59d63b4e0 100644 --- a/files/fr/web/javascript/reference/global_objects/intl/locale/getweekinfo/index.md +++ b/files/fr/web/javascript/reference/global_objects/intl/locale/getweekinfo/index.md @@ -23,10 +23,10 @@ let af = new Intl.Locale("af"); console.log(af.weekInfo); // affiche {firstDay: 7, weekend: [6, 7], minimalDays: 1} let enGB = new Intl.Locale("en-GB"); -console.log(enGB.weekInfo) // affiche {firstDay: 1, weekend: [6, 7], minimalDays: 4} +console.log(enGB.weekInfo); // affiche {firstDay: 1, weekend: [6, 7], minimalDays: 4} let msBN = new Intl.Locale("en-GB"); -console.log(msBN.weekInfo) // affiche {firstDay: 7, weekend: [5, 7], minimalDays: 1} +console.log(msBN.weekInfo); // affiche {firstDay: 7, weekend: [5, 7], minimalDays: 1} // Le week-end à Brunei est sur vendredi et dimanche mais pas sur samedi ``` diff --git a/files/fr/web/javascript/reference/global_objects/intl/locale/language/index.md b/files/fr/web/javascript/reference/global_objects/intl/locale/language/index.md index af5133b8c1ea6e..8cc145eac462d2 100644 --- a/files/fr/web/javascript/reference/global_objects/intl/locale/language/index.md +++ b/files/fr/web/javascript/reference/global_objects/intl/locale/language/index.md @@ -29,7 +29,7 @@ console.log(langStr.language); // Affichera "en" dans la console Bien que la composante de la langue doive être indiquée dans le premier paramètre, le constructeur {{jsxref("Locale", "Locale")}} prend comme deuxième argument un objet de configuration qui permet de surcharger cette composante. ```js -let langObj = new Intl.Locale("en-Latn-US", {language: "es"}); +let langObj = new Intl.Locale("en-Latn-US", { language: "es" }); console.log(langObj.language); // Affichera "es" dans la console ``` diff --git a/files/fr/web/javascript/reference/global_objects/intl/locale/locale/index.md b/files/fr/web/javascript/reference/global_objects/intl/locale/locale/index.md index af3fe249444995..5122bcd0cd17d0 100644 --- a/files/fr/web/javascript/reference/global_objects/intl/locale/locale/index.md +++ b/files/fr/web/javascript/reference/global_objects/intl/locale/locale/index.md @@ -12,8 +12,8 @@ Le constructeur **`Intl.Locale`** est une propriété native de l'objet `Intl` q ## Syntaxe ```js -new Intl.Locale(tag) -new Intl.Locale(tag, options) +new Intl.Locale(tag); +new Intl.Locale(tag, options); ``` ### Paramètres @@ -30,7 +30,7 @@ new Intl.Locale(tag, options) Sous sa forme la plus simple, le constructeur [`Intl.Locale`] prend comme argument une chaîne de caractères représentant un identifiant de locale : ```js -let us = new Intl.Locale('en-US'); +let us = new Intl.Locale("en-US"); ``` ### Utiliser le constructeur Locale avec un objet options diff --git a/files/fr/web/javascript/reference/global_objects/intl/locale/maximize/index.md b/files/fr/web/javascript/reference/global_objects/intl/locale/maximize/index.md index d444276766911f..a7ad4989432ef4 100644 --- a/files/fr/web/javascript/reference/global_objects/intl/locale/maximize/index.md +++ b/files/fr/web/javascript/reference/global_objects/intl/locale/maximize/index.md @@ -13,7 +13,7 @@ La méthode **`Intl.Locale.prototype.maximize()`** permet d'obtenir les valeurs ## Syntaxe ```js -locale.maximize() +locale.maximize(); ``` ### Valeur de retour @@ -27,7 +27,7 @@ Il est parfois utile d'identifier les composantes les plus probables d'une local ## Exemples ```js -let maLocale = new Intl.Locale("fr", {hourCycle: "h24", calendar: "gregory"}); +let maLocale = new Intl.Locale("fr", { hourCycle: "h24", calendar: "gregory" }); console.log(maLocale.baseName); // Affiche "fr" console.log(maLocale.toString()); // Affiche "fr-u-ca-gregory-hc-h24" let maLocMaximized = maLocale.maximize(); @@ -38,7 +38,7 @@ console.log(maLocMaximized.baseName); // Affiche "fr-Latn-FR-u-ca-gregory-hc-h24". // On notera que les extensions (après "-u") restent inchangées. -console.log(myLocMaximized.toString()); +console.log(myLocMaximized.toString()); ``` ## Spécifications diff --git a/files/fr/web/javascript/reference/global_objects/intl/locale/minimize/index.md b/files/fr/web/javascript/reference/global_objects/intl/locale/minimize/index.md index 28e512dd8e0149..54755b0c786048 100644 --- a/files/fr/web/javascript/reference/global_objects/intl/locale/minimize/index.md +++ b/files/fr/web/javascript/reference/global_objects/intl/locale/minimize/index.md @@ -13,7 +13,7 @@ La méthode **`Intl.Locale.prototype.minimize()`** tente de retirer les informat ## Syntaxe ```js -locale.minimize() +locale.minimize(); ``` ### Valeur de retour @@ -29,7 +29,10 @@ Cette méthode effectue l'opération inverse de {{jsxref("Locale/maximize", "max ## Exemples ```js -let maLocale = new Intl.Locale("fr-Latn-FR", {hourCycle: "h24", calendar: "gregory"}); +let maLocale = new Intl.Locale("fr-Latn-FR", { + hourCycle: "h24", + calendar: "gregory", +}); console.log(maLocale.baseName); // Affiche "fr-Latn-FR" console.log(maLocale.toString()); // Affiche "fr-Latn-FR-u-ca-gregory-hc-h24" let maLocMinimized = maLocale.minimize(); diff --git a/files/fr/web/javascript/reference/global_objects/intl/locale/numberingsystem/index.md b/files/fr/web/javascript/reference/global_objects/intl/locale/numberingsystem/index.md index 6fb597a3b14097..68bce3f91a6d54 100644 --- a/files/fr/web/javascript/reference/global_objects/intl/locale/numberingsystem/index.md +++ b/files/fr/web/javascript/reference/global_objects/intl/locale/numberingsystem/index.md @@ -120,7 +120,9 @@ console.log(numberingSystemStr.numberingSystem); Le constructeur [`Intl.Locale`](/fr/docs/Web/JavaScript/Reference/Objets_globaux/Locale) possède un deuxième argument, optionnel, qui est un objet permettant de configurer la locale. Les propriétés de cet objet sont utilisées comme extensions pour la locale ; les clés des propriétés sont les noms des extensions et leurs valeurs sont celles utilisées pour chaque extension. On peut donc utiliser la propriété `numberingSystem` sur cet objet afin de définir le système de numération à utiliser pour cette locale. ```js -let numberingSystemViaObj= new Intl.Locale("en-Latn-US", {numberingSystem: "latn"}); +let numberingSystemViaObj = new Intl.Locale("en-Latn-US", { + numberingSystem: "latn", +}); console.log(us12hour.numberingSystem); // affichera "latn" dans la console ``` diff --git a/files/fr/web/javascript/reference/global_objects/intl/locale/numeric/index.md b/files/fr/web/javascript/reference/global_objects/intl/locale/numeric/index.md index 6b94d3b5c4328a..1af3d883baa92b 100644 --- a/files/fr/web/javascript/reference/global_objects/intl/locale/numeric/index.md +++ b/files/fr/web/javascript/reference/global_objects/intl/locale/numeric/index.md @@ -29,7 +29,7 @@ console.log(numericStr.numeric); Le constructeur [`Intl.Locale`](/fr/docs/Web/JavaScript/Reference/Objets_globaux/Locale) possède un deuxième argument, optionnel, qui est un objet permettant de configurer la locale. Les propriétés de cet objet sont utilisées comme extensions pour la locale ; les clés des propriétés sont les noms des extensions et leurs valeurs sont celles utilisées pour chaque extension. On peut donc utiliser la propriété `numeric` sur cet objet afin de définir le système de numération à utiliser pour cette locale. ```js -let numericViaObj= new Intl.Locale("en-Latn-US", {numeric: true}); +let numericViaObj = new Intl.Locale("en-Latn-US", { numeric: true }); console.log(us12hour.numeric); // Affichera "true" dans la console ``` diff --git a/files/fr/web/javascript/reference/global_objects/intl/locale/region/index.md b/files/fr/web/javascript/reference/global_objects/intl/locale/region/index.md index dec2c5b759b3fa..8f0682014e360e 100644 --- a/files/fr/web/javascript/reference/global_objects/intl/locale/region/index.md +++ b/files/fr/web/javascript/reference/global_objects/intl/locale/region/index.md @@ -30,7 +30,7 @@ console.log(regionStr.region); Le constructeur {{jsxref("Locale", "Locale")}} prend comme second argument un objet de paramétrage dont chacune des propriétés permet de définir une extension ou une composante de la locale. ```js -let regionObj = new Intl.Locale("fr-Latn", {region: "FR"}); +let regionObj = new Intl.Locale("fr-Latn", { region: "FR" }); console.log(regionObj.region); // Affichera "FR" dans la console diff --git a/files/fr/web/javascript/reference/global_objects/intl/locale/script/index.md b/files/fr/web/javascript/reference/global_objects/intl/locale/script/index.md index e979bee921d83d..3e0e0724c2e860 100644 --- a/files/fr/web/javascript/reference/global_objects/intl/locale/script/index.md +++ b/files/fr/web/javascript/reference/global_objects/intl/locale/script/index.md @@ -29,7 +29,7 @@ console.log(scriptStr.script); // Affichera "Latn" dans la console Le constructeur {{jsxref("Locale", "Locale")}} permet d'utiliser un objet de configuration dont les propriétés définiront les caractéristiques de la locale : ```js -let scriptObj = new Intl.Locale("fr-FR", {script: "Latn"}); +let scriptObj = new Intl.Locale("fr-FR", { script: "Latn" }); console.log(scriptObj.script); // Affichera "Latn" dans la console ``` diff --git a/files/fr/web/javascript/reference/global_objects/intl/locale/tostring/index.md b/files/fr/web/javascript/reference/global_objects/intl/locale/tostring/index.md index 758f86d867add8..f95d360b4a10ea 100644 --- a/files/fr/web/javascript/reference/global_objects/intl/locale/tostring/index.md +++ b/files/fr/web/javascript/reference/global_objects/intl/locale/tostring/index.md @@ -13,7 +13,7 @@ La méthode **`Intl.Locale.prototype.toString()`** renvoie [l'identifiant de loc ## Syntaxe ```js -locale.toString() +locale.toString(); ``` ### Valeur de retour @@ -27,7 +27,10 @@ Une instance de `Locale` est une représentation JavaScript d'une locale au sens ## Exemples ```js -let maLocale = new Intl.Locale("fr-Latn-FR", {hourCycle: "h24", calendar: "gregory"}); +let maLocale = new Intl.Locale("fr-Latn-FR", { + hourCycle: "h24", + calendar: "gregory", +}); console.log(maLocale.baseName); // Affiche "fr-Latn-FR" console.log(maLocale.toString()); // Affiche "fr-Latn-FR-u-ca-gregory-hc-h24" ``` diff --git a/files/fr/web/javascript/reference/global_objects/intl/numberformat/format/index.md b/files/fr/web/javascript/reference/global_objects/intl/numberformat/format/index.md index 61bd3c8a706c6e..59da65516759c0 100644 --- a/files/fr/web/javascript/reference/global_objects/intl/numberformat/format/index.md +++ b/files/fr/web/javascript/reference/global_objects/intl/numberformat/format/index.md @@ -13,7 +13,7 @@ La méthode **`Intl.NumberFormat.prototype.format()`** formate un nombre en fonc ## Syntaxe ```js -numberFormat.format(nombre) +numberFormat.format(nombre); ``` ### Paramètres @@ -32,7 +32,7 @@ La fonction d'accesseur `format` permet de formater un nombre donné en une cha On peut utiliser la fonction renvoyée par `format` pour formater une valeur monétaire selon la locale russe : ```js -var options = {style: "currency", currency: "RUB"}; +var options = { style: "currency", currency: "RUB" }; var numberFormat = new Intl.NumberFormat("ru-RU", options); console.log(numberFormat.format(654321.987)); // → "654 321,99 руб." diff --git a/files/fr/web/javascript/reference/global_objects/intl/numberformat/formatrange/index.md b/files/fr/web/javascript/reference/global_objects/intl/numberformat/formatrange/index.md index 75f1db7b599f48..7f35b19e7d6922 100644 --- a/files/fr/web/javascript/reference/global_objects/intl/numberformat/formatrange/index.md +++ b/files/fr/web/javascript/reference/global_objects/intl/numberformat/formatrange/index.md @@ -11,12 +11,13 @@ La méthode **`Intl.NumberFormat.prototype.formatRange()`** formate un intervall ## Syntaxe ```js -formatRange(debutIntervalle, finIntervalle) +formatRange(debutIntervalle, finIntervalle); ``` ### Paramètres - `debutIntervalle` + - : Une valeur numérique [`Number`](/fr/docs/Web/JavaScript/Reference/Global_Objects/Number) ou [`BigInt`](/fr/docs/Web/JavaScript/Reference/Global_Objects/BigInt). - `finIntervalle` diff --git a/files/fr/web/javascript/reference/global_objects/intl/numberformat/formatrangetoparts/index.md b/files/fr/web/javascript/reference/global_objects/intl/numberformat/formatrangetoparts/index.md index ecb1ada46b01b1..7ea3a28c3c6836 100644 --- a/files/fr/web/javascript/reference/global_objects/intl/numberformat/formatrangetoparts/index.md +++ b/files/fr/web/javascript/reference/global_objects/intl/numberformat/formatrangetoparts/index.md @@ -11,13 +11,14 @@ La méthode **`Intl.Numberformat.prototype.formatRangeToParts()`** permet de for ## Syntaxe ```js -formatRangeToParts() -formatRangeToParts(debutIntervalle, finIntervalle) +formatRangeToParts(); +formatRangeToParts(debutIntervalle, finIntervalle); ``` ### Paramètres - `debutIntervalle` + - : Une valeur numérique [`Number`](/fr/docs/Web/JavaScript/Reference/Global_Objects/Number) ou [`BigInt`](/fr/docs/Web/JavaScript/Reference/Global_Objects/BigInt). - `finIntervalle` @@ -37,9 +38,8 @@ La méthode `formatRangeToParts()` est utile lorsqu'on souhaite construire des c { type: "literal", value: "-", source: "shared" }, { type: "integer", value: "5", source: "endRange" }, { type: "literal", value: " ", source: "shared" }, - { type: "currency", value: "€", source: "shared" } -] - + { type: "currency", value: "€", source: "shared" }, +]; ``` Les types de valeur possibles pour les fragments sont : @@ -79,12 +79,12 @@ Les types de valeur possibles pour les fragments sont : const debutIntervalle = 3500; const finIntervalle = 9500; -const formateur = new Intl.NumberFormat('de-DE', { - style: 'currency', - currency: 'EUR' +const formateur = new Intl.NumberFormat("de-DE", { + style: "currency", + currency: "EUR", }); -formateur.formatRange(debutIntervalle, finIntervalle) +formateur.formatRange(debutIntervalle, finIntervalle); // "3.500,00–9.500,00 €" ``` diff --git a/files/fr/web/javascript/reference/global_objects/intl/numberformat/formattoparts/index.md b/files/fr/web/javascript/reference/global_objects/intl/numberformat/formattoparts/index.md index 69c8f8cc3f0570..b598a9b4188b9a 100644 --- a/files/fr/web/javascript/reference/global_objects/intl/numberformat/formattoparts/index.md +++ b/files/fr/web/javascript/reference/global_objects/intl/numberformat/formattoparts/index.md @@ -11,7 +11,7 @@ La méthode **`Intl.Numberformat.prototype.formatToParts()`** permet de produire ## Syntaxe ```js -Intl.NumberFormat.prototype.formatToParts(nombre) +Intl.NumberFormat.prototype.formatToParts(nombre); ``` ### Paramètres @@ -38,7 +38,7 @@ La méthode `formatToParts()` est peut être utilisée lorsqu'on met en forme de Les valeurs possibles pour l'attribut `type` sont : - `currency` - - : Le suffixe associé à la devise. Ce peut être le symbole "$", "€" ou bien le nom de la devise "Dollar", "Euro" selon la façon dont `currencyDisplay` est indiquée. + - : Le suffixe associé à la devise. Ce peut être le symbole "$", "€" ou bien le nom de la devise "Dollar", "Euro" selon la façon dont `currencyDisplay` est indiquée. - `decimal` - : Le séparateur décimal utilisé ("."). - `fraction` @@ -67,9 +67,9 @@ Les valeurs possibles pour l'attribut `type` sont : ```js var number = 3500; -var formatter = new Intl.NumberFormat('de-DE', { - style: 'currency', - currency: 'EUR' +var formatter = new Intl.NumberFormat("de-DE", { + style: "currency", + currency: "EUR", }); formatter.format(number); @@ -96,12 +96,17 @@ formatter.formatToParts(number); Maintenant que la chaîne est décomposée, on peut la réassembler d'une façon spécifique. On peut, par exemple utiliser {{jsxref("Array.prototype.map()")}}, [une fonction fléchée](/fr/docs/Web/JavaScript/Reference/Fonctions/Fonctions_fléchées), une [instruction `switch`](/fr/docs/Web/JavaScript/Reference/Instructions/switch), [des littéraux de gabarits](/fr/docs/Web/JavaScript/Reference/Littéraux_gabarits) et {{jsxref("Array.prototype.reduce()")}}. ```js -var numberString = formatter.formatToParts(number).map(({type, value}) => { - switch (type) { - case 'currency': return `${value}`; - default : return value; - } -}).reduce((string, part) => string + part); +var numberString = formatter + .formatToParts(number) + .map(({ type, value }) => { + switch (type) { + case "currency": + return `${value}`; + default: + return value; + } + }) + .reduce((string, part) => string + part); ``` Grâce à cette fonction, on pourra mettre en gras le suffixe associé à la devise : diff --git a/files/fr/web/javascript/reference/global_objects/intl/numberformat/index.md b/files/fr/web/javascript/reference/global_objects/intl/numberformat/index.md index 35bd3b1a841a7e..6b112b759dcef3 100644 --- a/files/fr/web/javascript/reference/global_objects/intl/numberformat/index.md +++ b/files/fr/web/javascript/reference/global_objects/intl/numberformat/index.md @@ -87,32 +87,48 @@ Les résultats fournis peuvent être paramétrés grâce à l'argument `options` var nombre = 123456.789; // on affiche une devise avec le style "currency" -console.log(new Intl.NumberFormat("de-DE", {style: "currency", currency: "EUR"}).format(nombre)); +console.log( + new Intl.NumberFormat("de-DE", { style: "currency", currency: "EUR" }).format( + nombre, + ), +); // → 123.456,79 € // Le yen japonais n'a pas de centimes -console.log(new Intl.NumberFormat("ja-JP", {style: "currency", currency: "JPY"}).format(nombre)) +console.log( + new Intl.NumberFormat("ja-JP", { style: "currency", currency: "JPY" }).format( + nombre, + ), +); // → ¥123,457 // On se limite ici à trois chiffres significatifs -console.log(new Intl.NumberFormat("en-IN", {maximumSignificantDigits: 3}).format(nombre)); +console.log( + new Intl.NumberFormat("en-IN", { maximumSignificantDigits: 3 }).format( + nombre, + ), +); // → 1,23,000 ``` ### Utiliser les options `style` et `unit` ```js -console.log(new Intl.NumberFormat('pt-PT', { - style: 'unit', - unit: 'kilometer-per-hour' -}).format(50)); +console.log( + new Intl.NumberFormat("pt-PT", { + style: "unit", + unit: "kilometer-per-hour", + }).format(50), +); // → 50 km/h -console.log((16).toLocaleString('en-GB', { - style: 'unit', - unit: 'liter', - unitDisplay: 'long' -})); +console.log( + (16).toLocaleString("en-GB", { + style: "unit", + unit: "liter", + unitDisplay: "long", + }), +); // → 16 litres ``` diff --git a/files/fr/web/javascript/reference/global_objects/intl/numberformat/numberformat/index.md b/files/fr/web/javascript/reference/global_objects/intl/numberformat/numberformat/index.md index ce68acef374240..686fa81bc3b1e3 100644 --- a/files/fr/web/javascript/reference/global_objects/intl/numberformat/numberformat/index.md +++ b/files/fr/web/javascript/reference/global_objects/intl/numberformat/numberformat/index.md @@ -12,9 +12,9 @@ Le constructeur **`Intl.NumberFormat()`** permet de créer des objets [`Intl.Num ## Syntaxe ```js -new Intl.NumberFormat() -new Intl.NumberFormat(locales) -new Intl.NumberFormat(locales, options) +new Intl.NumberFormat(); +new Intl.NumberFormat(locales); +new Intl.NumberFormat(locales, options); ``` ### Paramètres @@ -120,9 +120,9 @@ console.log(new Intl.NumberFormat().format(amount)); ```js let amount = 3500; -new Intl.NumberFormat('en-US', {style: 'decimal'}).format(amount); +new Intl.NumberFormat("en-US", { style: "decimal" }).format(amount); // → '3,500' -new Intl.NumberFormat('fr', {style: 'percent'}).format(amount); +new Intl.NumberFormat("fr", { style: "percent" }).format(amount); // → '350 000 %' ``` @@ -133,10 +133,14 @@ Si l'option `style` vaut `'unit'`, une propriété `unit` doit être fournie. Le ```js let amount = 3500; -new Intl.NumberFormat('en-US', {style: 'unit', unit: 'liter'}).format(amount); +new Intl.NumberFormat("en-US", { style: "unit", unit: "liter" }).format(amount); // → '3,500 L' -new Intl.NumberFormat('fr', {style: 'unit', unit: 'liter', unitDisplay: 'long'}).format(amount); +new Intl.NumberFormat("fr", { + style: "unit", + unit: "liter", + unitDisplay: "long", +}).format(amount); // → '3 500 litres' ``` @@ -146,20 +150,22 @@ Si l'option `style` vaut `'currency'`, une propriété `currency` doit être fou ```js let amount = -3500; -new Intl.NumberFormat('en-US', {style: 'currency', currency: 'USD'}).format(amount); +new Intl.NumberFormat("en-US", { style: "currency", currency: "USD" }).format( + amount, +); // → '-$3,500.00' -new Intl.NumberFormat('bn', { - style: 'currency', - currency: 'USD', - currencyDisplay: 'name' +new Intl.NumberFormat("bn", { + style: "currency", + currency: "USD", + currencyDisplay: "name", }).format(amount); // → '-3,500.00 US dollars' -new Intl.NumberFormat('fr', { - style: 'currency', - currency: 'EUR', - currencySign: 'accounting' +new Intl.NumberFormat("fr", { + style: "currency", + currency: "EUR", + currencySign: "accounting", }).format(amount); // → "(3 500,00 €)" ``` @@ -169,30 +175,30 @@ new Intl.NumberFormat('fr', { Ces notations sont portées par l'option `notation` et peuvent être formatées ainsi : ```js -new Intl.NumberFormat('en-US', { notation: "scientific" }).format(987654321); +new Intl.NumberFormat("en-US", { notation: "scientific" }).format(987654321); // → 9.877E8 -new Intl.NumberFormat('pt-PT', { notation: "scientific" }).format(987654321); +new Intl.NumberFormat("pt-PT", { notation: "scientific" }).format(987654321); // → 9,877E8 -new Intl.NumberFormat('en-GB', { notation: "engineering" }).format(987654321); +new Intl.NumberFormat("en-GB", { notation: "engineering" }).format(987654321); // → 987.654E6 -new Intl.NumberFormat('de', { notation: "engineering" }).format(987654321); +new Intl.NumberFormat("de", { notation: "engineering" }).format(987654321); // → 987,654E6 -new Intl.NumberFormat('zh-CN', { notation: "compact" }).format(987654321); +new Intl.NumberFormat("zh-CN", { notation: "compact" }).format(987654321); // → 9.9亿 -new Intl.NumberFormat('fr', { +new Intl.NumberFormat("fr", { notation: "compact", - compactDisplay: "long" + compactDisplay: "long", }).format(987654321); // → 988 millions -new Intl.NumberFormat('en-GB', { +new Intl.NumberFormat("en-GB", { notation: "compact", - compactDisplay: "short" + compactDisplay: "short", }).format(987654321); // → 988M ``` @@ -203,8 +209,8 @@ Dans l'exemple qui suit, on affiche toujours le signe sauf si la valeur est zér ```js new Intl.NumberFormat("en-US", { - style: "percent", - signDisplay: "exceptZero" + style: "percent", + signDisplay: "exceptZero", }).format(0.55); // → '+55%' ``` @@ -212,11 +218,11 @@ new Intl.NumberFormat("en-US", { On notera que lorsque le style porte sur les devises et que le style de signe vaut "`accounting`", des parenthèses pourront être utilisées plutôt qu'un signe moins : ```js -new Intl.NumberFormat('bn', { - style: 'currency', - currency: 'USD', - currencySign: 'accounting', - signDisplay: 'always' +new Intl.NumberFormat("bn", { + style: "currency", + currency: "USD", + currencySign: "accounting", + signDisplay: "always", }).format(-3500); // → '($3,500.00)' diff --git a/files/fr/web/javascript/reference/global_objects/intl/numberformat/resolvedoptions/index.md b/files/fr/web/javascript/reference/global_objects/intl/numberformat/resolvedoptions/index.md index d0c2f8c9487eb5..2d08316eb1b215 100644 --- a/files/fr/web/javascript/reference/global_objects/intl/numberformat/resolvedoptions/index.md +++ b/files/fr/web/javascript/reference/global_objects/intl/numberformat/resolvedoptions/index.md @@ -13,7 +13,7 @@ La méthode **`Intl.NumberFormat.prototype.resolvedOptions()`** renvoie un nouve ## Syntaxe ```js -numberFormat.resolvedOptions() +numberFormat.resolvedOptions(); ``` ### Valeur de retour @@ -45,16 +45,16 @@ Un seul des deux groupes suivants est inclus dans les propriétés : ### Utiliser la méthode `resolvedOptions()` ```js -var de = new Intl.NumberFormat('de-DE'); +var de = new Intl.NumberFormat("de-DE"); var usedOptions = de.resolvedOptions(); -usedOptions.locale; // "de-DE" -usedOptions.numberingSystem; // "latn" -usedOption.style; // "decimal" -usedOptions.minimumIntegerDigits; // 1 +usedOptions.locale; // "de-DE" +usedOptions.numberingSystem; // "latn" +usedOption.style; // "decimal" +usedOptions.minimumIntegerDigits; // 1 usedOptions.minimumFractionDigits; // 0 usedOptions.maximumFractionDigits; // 3 -usedOptions.useGrouping; // true +usedOptions.useGrouping; // true ``` ## Spécifications diff --git a/files/fr/web/javascript/reference/global_objects/intl/numberformat/supportedlocalesof/index.md b/files/fr/web/javascript/reference/global_objects/intl/numberformat/supportedlocalesof/index.md index 86b376f500481c..be22a83b3fb2d2 100644 --- a/files/fr/web/javascript/reference/global_objects/intl/numberformat/supportedlocalesof/index.md +++ b/files/fr/web/javascript/reference/global_objects/intl/numberformat/supportedlocalesof/index.md @@ -43,7 +43,7 @@ Si on dispose d'un environnement qui supporte les locales indonésienne et allem ```js var locales = ["ban", "id-u-co-pinyin", "de-ID"]; -var options = {localeMatcher: "lookup"}; +var options = { localeMatcher: "lookup" }; console.log(Intl.NumberFormat.supportedLocalesOf(locales, options).join(", ")); // → "id-u-co-pinyin, de-ID" ``` diff --git a/files/fr/web/javascript/reference/global_objects/intl/pluralrules/index.md b/files/fr/web/javascript/reference/global_objects/intl/pluralrules/index.md index 31bddf964d5ff3..f15d5dcae7dd19 100644 --- a/files/fr/web/javascript/reference/global_objects/intl/pluralrules/index.md +++ b/files/fr/web/javascript/reference/global_objects/intl/pluralrules/index.md @@ -37,15 +37,15 @@ Dans cet exemple, on voit l'impact de la locale sur les règles de nombre. Afin // L'arabe possède plusieurs règles // de nombre -new Intl.PluralRules('ar-EG').select(0); +new Intl.PluralRules("ar-EG").select(0); // → 'zero' -new Intl.PluralRules('ar-EG').select(1); +new Intl.PluralRules("ar-EG").select(1); // → 'one' -new Intl.PluralRules('ar-EG').select(2); +new Intl.PluralRules("ar-EG").select(2); // → 'two' -new Intl.PluralRules('ar-EG').select(6); +new Intl.PluralRules("ar-EG").select(6); // → 'few' -new Intl.PluralRules('ar-EG').select(18); +new Intl.PluralRules("ar-EG").select(18); // → 'many' ``` diff --git a/files/fr/web/javascript/reference/global_objects/intl/pluralrules/pluralrules/index.md b/files/fr/web/javascript/reference/global_objects/intl/pluralrules/pluralrules/index.md index b4f19846d6113c..cab7711aca42eb 100644 --- a/files/fr/web/javascript/reference/global_objects/intl/pluralrules/pluralrules/index.md +++ b/files/fr/web/javascript/reference/global_objects/intl/pluralrules/pluralrules/index.md @@ -10,9 +10,9 @@ Le constructeur **`Intl.PluralRules()`** permet de créer des objets [`Intl.Plur ## Syntaxe ```js -new Intl.PluralRules() -new Intl.PluralRules(locales) -new Intl.PluralRules(locales, options) +new Intl.PluralRules(); +new Intl.PluralRules(locales); +new Intl.PluralRules(locales, options); ``` ### Parameters @@ -66,13 +66,13 @@ pr.select(2); Les résultats peuvent être personnalisés avec l'argument `options` qui possède une propriété `type` qu'on peut fixer à `ordinal`. Cela s'avère utile pour déterminer l'indicateur ordinal (par exemple en anglais où il y a des variations entre "1st", "2nd", "3rd", "4th", "42nd" et ainsi de suite). ```js -var pr = new Intl.PluralRules('en-US', { type: 'ordinal' }); +var pr = new Intl.PluralRules("en-US", { type: "ordinal" }); const suffixes = new Map([ - ['one', 'st'], - ['two', 'nd'], - ['few', 'rd'], - ['other', 'th'], + ["one", "st"], + ["two", "nd"], + ["few", "rd"], + ["other", "th"], ]); const formatOrdinals = (n) => { const rule = pr.select(n); @@ -80,14 +80,14 @@ const formatOrdinals = (n) => { return `${n}${suffix}`; }; -formatOrdinals(0); // '0th' -formatOrdinals(1); // '1st' -formatOrdinals(2); // '2nd' -formatOrdinals(3); // '3rd' -formatOrdinals(4); // '4th' -formatOrdinals(11); // '11th' -formatOrdinals(21); // '21st' -formatOrdinals(42); // '42nd' +formatOrdinals(0); // '0th' +formatOrdinals(1); // '1st' +formatOrdinals(2); // '2nd' +formatOrdinals(3); // '3rd' +formatOrdinals(4); // '4th' +formatOrdinals(11); // '11th' +formatOrdinals(21); // '21st' +formatOrdinals(42); // '42nd' formatOrdinals(103); // '103rd' ``` diff --git a/files/fr/web/javascript/reference/global_objects/intl/pluralrules/resolvedoptions/index.md b/files/fr/web/javascript/reference/global_objects/intl/pluralrules/resolvedoptions/index.md index 7d62e1a57c469b..b0f7d2375f2132 100644 --- a/files/fr/web/javascript/reference/global_objects/intl/pluralrules/resolvedoptions/index.md +++ b/files/fr/web/javascript/reference/global_objects/intl/pluralrules/resolvedoptions/index.md @@ -11,7 +11,7 @@ La méthode **`Intl.PluralRules.prototype.resolvedOptions()`** renvoie un nouvel ## Syntaxe ```js -pluralRule.resolvedOptions() +pluralRule.resolvedOptions(); ``` ### Valeur de retour @@ -41,15 +41,15 @@ Seul l'un de ces deux groupes de propriétés est inclus : ### Utiliser `resolvedOptions()` ```js -var de = new Intl.PluralRules('de-DE'); +var de = new Intl.PluralRules("de-DE"); var usedOptions = de.resolvedOptions(); -usedOptions.locale; // "de-DE" +usedOptions.locale; // "de-DE" usedOptions.maximumFractionDigits; // 3 usedOptions.minimumFractionDigits; // 0 -usedOptions.minimumIntegerDigits; // 1 -usedOptions.pluralCategories; // Array [ "one", "other" ] -usedOptions.type; // "cardinal" +usedOptions.minimumIntegerDigits; // 1 +usedOptions.pluralCategories; // Array [ "one", "other" ] +usedOptions.type; // "cardinal" ``` ## Spécifications diff --git a/files/fr/web/javascript/reference/global_objects/intl/pluralrules/select/index.md b/files/fr/web/javascript/reference/global_objects/intl/pluralrules/select/index.md index 6f129efb1cde65..dc446fdc64b5a4 100644 --- a/files/fr/web/javascript/reference/global_objects/intl/pluralrules/select/index.md +++ b/files/fr/web/javascript/reference/global_objects/intl/pluralrules/select/index.md @@ -11,7 +11,7 @@ La méthode **`Intl.PluralRules.prototype.select`** renvoie une chaîne de carac ## Syntaxe ```js -pluralRule.select(nombre) +pluralRule.select(nombre); ``` ### Paramètres @@ -26,19 +26,19 @@ Cette fonction permet de sélectionner une règle de nombre en fonction de la lo ## Exemples ```js - new Intl.PluralRules('ar-EG').select(0); +new Intl.PluralRules("ar-EG").select(0); // → 'zero' -new Intl.PluralRules('ar-EG').select(1); +new Intl.PluralRules("ar-EG").select(1); // → 'one' -new Intl.PluralRules('ar-EG').select(2); +new Intl.PluralRules("ar-EG").select(2); // → 'two' -new Intl.PluralRules('ar-EG').select(6); +new Intl.PluralRules("ar-EG").select(6); // → 'few' -new Intl.PluralRules('ar-EG').select(18); +new Intl.PluralRules("ar-EG").select(18); // → 'many' ``` diff --git a/files/fr/web/javascript/reference/global_objects/intl/pluralrules/selectrange/index.md b/files/fr/web/javascript/reference/global_objects/intl/pluralrules/selectrange/index.md index d09a4e9ad1dbfa..e90352d2f7db67 100644 --- a/files/fr/web/javascript/reference/global_objects/intl/pluralrules/selectrange/index.md +++ b/files/fr/web/javascript/reference/global_objects/intl/pluralrules/selectrange/index.md @@ -11,7 +11,7 @@ La méthode **`Intl.PluralRules.prototype.selectRange()`** reçoit deux valeurs ## Syntaxe ```js -selectRange(debutIntervalle, finIntervalle) +selectRange(debutIntervalle, finIntervalle); ``` ### Valeur de retour @@ -27,10 +27,10 @@ Cette fonction sélectionne une catégorie de nombre selon les options de locale ### Utiliser `selectRange()` ```js - new Intl.PluralRules('sl').selectRange(102, 201); +new Intl.PluralRules("sl").selectRange(102, 201); // → 'few' - new Intl.PluralRules('pt').selectRange(102, 102); +new Intl.PluralRules("pt").selectRange(102, 102); // → 'other' ``` diff --git a/files/fr/web/javascript/reference/global_objects/intl/pluralrules/supportedlocalesof/index.md b/files/fr/web/javascript/reference/global_objects/intl/pluralrules/supportedlocalesof/index.md index a924fb38f83a44..115f7ff07b447b 100644 --- a/files/fr/web/javascript/reference/global_objects/intl/pluralrules/supportedlocalesof/index.md +++ b/files/fr/web/javascript/reference/global_objects/intl/pluralrules/supportedlocalesof/index.md @@ -38,9 +38,9 @@ Cette méthode renvoie un tableau contenant un sous-ensemble des balises de lang Dans l'hypothèse où on utilise un système prenant en charge l'indonésien, l'allemand mais pas le balinais pour le formatage avec les règles de nombre, `supportedLocalesOf` renvoie les balises de langue indonésienne et allemande inchangées bien que la collation `pinyin` ne soit pas pertinente ni utilisée avec l'indonésien (et qu'il est peu probable qu'une variante indonésienne pour l'allemand soit prise en charge). On notera que l'algorithme de correspondance `"lookup"` est utilisé ici. L'algorithme `"best fit"` aurait pu déterminer que l'indonésien aurait pu remplacer le balinais car la plupart des personnes parlant le balinais comprend également l'indonésien, la fonction aurait alors pu remplacer la balise de langue balinaise. ```js -var locales = ['ban', 'id-u-co-pinyin', 'de-ID']; -var options = { localeMatcher: 'lookup' }; -console.log(Intl.PluralRules.supportedLocalesOf(locales, options).join(', ')); +var locales = ["ban", "id-u-co-pinyin", "de-ID"]; +var options = { localeMatcher: "lookup" }; +console.log(Intl.PluralRules.supportedLocalesOf(locales, options).join(", ")); // → "id-u-co-pinyin, de-ID" ``` diff --git a/files/fr/web/javascript/reference/global_objects/intl/relativetimeformat/format/index.md b/files/fr/web/javascript/reference/global_objects/intl/relativetimeformat/format/index.md index 380840827698a3..be2df5d98fb2f1 100644 --- a/files/fr/web/javascript/reference/global_objects/intl/relativetimeformat/format/index.md +++ b/files/fr/web/javascript/reference/global_objects/intl/relativetimeformat/format/index.md @@ -9,7 +9,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/ ## Syntaxe ```js -RelativeTimeFormat.format(valeur, unite) +RelativeTimeFormat.format(valeur, unite); ``` ### Paramètres @@ -34,9 +34,9 @@ L'exemple suivant illustre comment créer un outil de formatage pour les valeurs // les temps relatifs en anglais, avec les valeurs par défaut // utilisées explicitement. const rtf = new Intl.RelativeTimeFormat("en", { - localeMatcher: "best fit", // autre valeur possible : "lookup" - numeric: "always", // autre valeur possible : "auto" - style: "long", // autres valeurs possibles : "short" ou "narrow" + localeMatcher: "best fit", // autre valeur possible : "lookup" + numeric: "always", // autre valeur possible : "auto" + style: "long", // autres valeurs possibles : "short" ou "narrow" }); // Formatage d'une valeur relative négative. diff --git a/files/fr/web/javascript/reference/global_objects/intl/relativetimeformat/formattoparts/index.md b/files/fr/web/javascript/reference/global_objects/intl/relativetimeformat/formattoparts/index.md index 7ab944ca1ad6e5..61d4959507792d 100644 --- a/files/fr/web/javascript/reference/global_objects/intl/relativetimeformat/formattoparts/index.md +++ b/files/fr/web/javascript/reference/global_objects/intl/relativetimeformat/formattoparts/index.md @@ -13,7 +13,7 @@ La méthode **`Intl.RelativeTimeFormat.prototype.formatToParts()`** est une mét ## Syntaxe ```js -RelativeTimeFormat.formatToParts(valeur, unite) +RelativeTimeFormat.formatToParts(valeur, unite); ``` ### Paramètres diff --git a/files/fr/web/javascript/reference/global_objects/intl/relativetimeformat/index.md b/files/fr/web/javascript/reference/global_objects/intl/relativetimeformat/index.md index d328bdd387baf8..2eb7fe1b2041b9 100644 --- a/files/fr/web/javascript/reference/global_objects/intl/relativetimeformat/index.md +++ b/files/fr/web/javascript/reference/global_objects/intl/relativetimeformat/index.md @@ -39,9 +39,9 @@ L'exemple suivant illustre comment créer un formateur de temps relatif en angla // On crée un formateur en anglais en utilisant explicitement // les valeurs par défaut. const rtf = new Intl.RelativeTimeFormat("en", { - localeMatcher: "best fit", // autre valeur possible : "lookup" - numeric: "always", // autre valeur possible : "auto" - style: "long", // autre valeur possible : "short" ou "narrow" + localeMatcher: "best fit", // autre valeur possible : "lookup" + numeric: "always", // autre valeur possible : "auto" + style: "long", // autre valeur possible : "short" ou "narrow" }); // On formate un temps relatif avec une valeur négative (-1). diff --git a/files/fr/web/javascript/reference/global_objects/intl/relativetimeformat/relativetimeformat/index.md b/files/fr/web/javascript/reference/global_objects/intl/relativetimeformat/relativetimeformat/index.md index e9866a8ccf557b..8685d08a692895 100644 --- a/files/fr/web/javascript/reference/global_objects/intl/relativetimeformat/relativetimeformat/index.md +++ b/files/fr/web/javascript/reference/global_objects/intl/relativetimeformat/relativetimeformat/index.md @@ -10,9 +10,9 @@ Le constructeur **`Intl.RelativeTimeFormat()`** permet de créer des objets [`In ## Syntaxe ```js -new Intl.RelativeTimeFormat() -new Intl.RelativeTimeFormat(locales) -new Intl.RelativeTimeFormat(locales, options) +new Intl.RelativeTimeFormat(); +new Intl.RelativeTimeFormat(locales); +new Intl.RelativeTimeFormat(locales, options); ``` ### Paramètres @@ -50,9 +50,9 @@ Dans l'exemple suivant, on crée un formateur de temps relatif utilisant la loca // On crée un formateur de temps relatif dans la locale // avec les valeurs par défaut passées explicitement. const rtf = new Intl.RelativeTimeFormat("fr", { - localeMatcher: "best fit", // autres valeurs possibles : "lookup" - numeric: "always", // autres valeurs possibles : "auto" - style: "long", // autres valeurs possibles : "short" ou "narrow" + localeMatcher: "best fit", // autres valeurs possibles : "lookup" + numeric: "always", // autres valeurs possibles : "auto" + style: "long", // autres valeurs possibles : "short" ou "narrow" }); // On formate un temps relatif un jour dans le passé. diff --git a/files/fr/web/javascript/reference/global_objects/intl/relativetimeformat/resolvedoptions/index.md b/files/fr/web/javascript/reference/global_objects/intl/relativetimeformat/resolvedoptions/index.md index e626ef9c7a9c30..31ac4b3452bbbd 100644 --- a/files/fr/web/javascript/reference/global_objects/intl/relativetimeformat/resolvedoptions/index.md +++ b/files/fr/web/javascript/reference/global_objects/intl/relativetimeformat/resolvedoptions/index.md @@ -15,7 +15,7 @@ La méthode **`Intl.RelativeTimeFormat.prototype.resolvedOptions()`** renvoie un ## Syntaxe ```js -relativeTimeFormat.resolvedOptions() +relativeTimeFormat.resolvedOptions(); ``` ### Valeur de retour @@ -49,12 +49,12 @@ L'objet renvoyé par cette méthode possèdera les propriétés suivantes : ## Exemples ```js -var de = new Intl.RelativeTimeFormat('de-DE'); +var de = new Intl.RelativeTimeFormat("de-DE"); var usedOptions = de.resolvedOptions(); -usedOptions.locale; // "de-DE" -usedOptions.style; // "long" -usedOptions.numeric; // "always" +usedOptions.locale; // "de-DE" +usedOptions.style; // "long" +usedOptions.numeric; // "always" usedOptions.numberingSystem; // "latn" ``` diff --git a/files/fr/web/javascript/reference/global_objects/intl/relativetimeformat/supportedlocalesof/index.md b/files/fr/web/javascript/reference/global_objects/intl/relativetimeformat/supportedlocalesof/index.md index c50301cb26612f..b5907bcb333e2f 100644 --- a/files/fr/web/javascript/reference/global_objects/intl/relativetimeformat/supportedlocalesof/index.md +++ b/files/fr/web/javascript/reference/global_objects/intl/relativetimeformat/supportedlocalesof/index.md @@ -44,7 +44,11 @@ Cette méthode renvoie un tableau qui est un sous-ensemble de `locales`. Les bal Si on dispose d'un environnement qui supporte les locales indonésienne et allemande mais pas balinaise pour le formatage des temps relatifs, `supportedLocalesOf` renverra les balises BCP 47 pour l'indonésien et l'allemand (bien que la collation pinyin ne soit pas pertinente pour les dates ni pour l'indonésien et qu'il soit peu probable qu'une variante indonésienne existe pour l'allemand). Pour l'exemple, on l'utilise l'algorithme `"lookup"`. Si on utilisait `"best fit"`, on pourrait considérer que l'indonésien est adéquat pour la locale balinaise (sachant que la plupart des balinais comprend l'indonésien) et donc également renvoyer la balise balinaise. ```js -var locales = ['ban', 'id-u-co-pinyin', 'de-ID'];var options = { localeMatcher: 'lookup' };console.log(Intl.RelativeTimeFormat.supportedLocalesOf(locales, options).join(', '));// → "id-u-co-pinyin, de-ID" +var locales = ["ban", "id-u-co-pinyin", "de-ID"]; +var options = { localeMatcher: "lookup" }; +console.log( + Intl.RelativeTimeFormat.supportedLocalesOf(locales, options).join(", "), +); // → "id-u-co-pinyin, de-ID" ``` ## Spécifications diff --git a/files/fr/web/javascript/reference/global_objects/intl/segmenter/index.md b/files/fr/web/javascript/reference/global_objects/intl/segmenter/index.md index 86d2e2ae77e2ab..cb765cf2666110 100644 --- a/files/fr/web/javascript/reference/global_objects/intl/segmenter/index.md +++ b/files/fr/web/javascript/reference/global_objects/intl/segmenter/index.md @@ -34,16 +34,15 @@ L'objet **`Intl.Segmenter`** permet de segmenter un texte en tenant compte de la En utilisant [`String.prototype.split(" ")`](/fr/docs/Web/JavaScript/Reference/Global_Objects/String/split) pour segmenter un texte en mots, on n'obtient pas le bon résultat si la locale du texte n'utilise pas d'espace entre les mots (ce qui est le cas pour le japonais, le chinois, le thaïlandais, le laotien, le khmer, le birman, etc.). ```js example-bad -const str = '吾輩は猫である。名前はたぬき。'; -console.table(str.split(' ')); +const str = "吾輩は猫である。名前はたぬき。"; +console.table(str.split(" ")); // ['吾輩は猫である。名前はたぬき。'] // Les deux phrases ne sont pas segmentées correctement. - ``` ```js example-good -const str = '吾輩は猫である。名前はたぬき。'; -const segmenterJa = new Intl.Segmenter('ja-JP', { granularity: 'word' }); +const str = "吾輩は猫である。名前はたぬき。"; +const segmenterJa = new Intl.Segmenter("ja-JP", { granularity: "word" }); const segments = segmenterJa.segment(str); console.table(Array.from(segments)); diff --git a/files/fr/web/javascript/reference/global_objects/intl/segmenter/resolvedoptions/index.md b/files/fr/web/javascript/reference/global_objects/intl/segmenter/resolvedoptions/index.md index 0c84991e25d687..3af2dc21ecb807 100644 --- a/files/fr/web/javascript/reference/global_objects/intl/segmenter/resolvedoptions/index.md +++ b/files/fr/web/javascript/reference/global_objects/intl/segmenter/resolvedoptions/index.md @@ -13,7 +13,7 @@ La méthode **`Intl.Segmenter.prototype.resolvedOptions()`** renvoie un nouvel o ## Syntaxe ```js -resolvedOptions() +resolvedOptions(); ``` ### Paramètres @@ -38,7 +38,7 @@ L'objet renvoyé par la méthode possède les propriétés suivantes : ### Utilisation simple ```js -const spanishSegmenter = new Intl.Segmenter('es', {granularity: 'sentence'}); +const spanishSegmenter = new Intl.Segmenter("es", { granularity: "sentence" }); const options = spanishSegmenter.resolvedOptions(); console.log(options.locale); // "es" console.log(options.granularity); // "sentence" @@ -47,7 +47,7 @@ console.log(options.granularity); // "sentence" ### Granularité par défaut ```js -const spanishSegmenter = new Intl.Segmenter('es'); +const spanishSegmenter = new Intl.Segmenter("es"); const options = spanishSegmenter.resolvedOptions(); console.log(options.locale); // "es" console.log(options.granularity); // "grapheme" @@ -56,11 +56,11 @@ console.log(options.granularity); // "grapheme" ### Locale de recours locale ```js -const banSegmenter = new Intl.Segmenter('ban'); +const banSegmenter = new Intl.Segmenter("ban"); const options = banSegmenter.resolvedOptions(); console.log(options.locale); // "fr" sur un environnement d'exécution où la locale -// balinaise n'est pas prise en charge et où le +// balinaise n'est pas prise en charge et où le // français est la locale par défaut console.log(options.granularity); // "grapheme" ``` diff --git a/files/fr/web/javascript/reference/global_objects/intl/segmenter/segment/index.md b/files/fr/web/javascript/reference/global_objects/intl/segmenter/segment/index.md index ca0045d3a4647b..e50bdf5c187f07 100644 --- a/files/fr/web/javascript/reference/global_objects/intl/segmenter/segment/index.md +++ b/files/fr/web/javascript/reference/global_objects/intl/segmenter/segment/index.md @@ -13,7 +13,7 @@ La méthode **`Intl.Segmenter.prototype.segment()`** segmente une chaîne de car ## Syntaxe ```js -segment(input) +segment(input); ``` ### Paramètres @@ -29,7 +29,7 @@ Un nouvel objet itérable [`Segments`](/fr/docs/Web/JavaScript/Reference/Global_ ```js // On crée un segmenteur propre à une locale -const segmenter = new Intl.Segmenter('fr', {granularity: 'word'}); +const segmenter = new Intl.Segmenter("fr", { granularity: "word" }); // On l'utilise pour obtenir un itérateur sur les segments // d'une chaîne de caractères @@ -37,11 +37,13 @@ const input = "Moi ? N'est-ce pas ?"; const segments = segmenter.segment(input); // Et on parcourt cet ensemble -for (const {segment, index, isWordLike} of segments) { - console.log('segment situé aux unités [%d, %d]: «%s»%s', - index, index + segment.length, +for (const { segment, index, isWordLike } of segments) { + console.log( + "segment situé aux unités [%d, %d]: «%s»%s", + index, + index + segment.length, segment, - isWordLike ? ' (type mot)' : '' + isWordLike ? " (type mot)" : "", ); } // Affiche dans la console diff --git a/files/fr/web/javascript/reference/global_objects/intl/segmenter/segment/segments/@@iterator/index.md b/files/fr/web/javascript/reference/global_objects/intl/segmenter/segment/segments/@@iterator/index.md index f2eb7da9b39dfc..513a63ea0a18c5 100644 --- a/files/fr/web/javascript/reference/global_objects/intl/segmenter/segment/segments/@@iterator/index.md +++ b/files/fr/web/javascript/reference/global_objects/intl/segmenter/segment/segments/@@iterator/index.md @@ -14,7 +14,7 @@ La méthode **`Intl.Segments.@@iterator`** fait partie de l'implémentation [du ## Syntaxe ```js -segments[Symbol.iterator] +segments[Symbol.iterator]; ``` La fonction disponible sur cet itérateur est `.next()`, elle est décrite dans [la page du protocole itérateur](/fr/docs/Web/JavaScript/Reference/Iteration_protocols#le_protocole_«_itérateur_»). @@ -26,7 +26,7 @@ Un nouvel objet itérateur. ## Exemples ```js -const segmenter = new Intl.Segmenter('fr', {granularity: 'word'}); +const segmenter = new Intl.Segmenter("fr", { granularity: "word" }); const input = "Moi ? N'est-ce pas ?"; const segments = segmenter.segment(input); const iterator = segments[Symbol.iterator](); diff --git a/files/fr/web/javascript/reference/global_objects/intl/segmenter/segment/segments/containing/index.md b/files/fr/web/javascript/reference/global_objects/intl/segmenter/segment/segments/containing/index.md index 5442ca018be67f..2a5080e14d74c4 100644 --- a/files/fr/web/javascript/reference/global_objects/intl/segmenter/segment/segments/containing/index.md +++ b/files/fr/web/javascript/reference/global_objects/intl/segmenter/segment/segments/containing/index.md @@ -14,7 +14,7 @@ La méthode **`Intl.Segments.containing()`** renvoie un objet décrivant le segm ## Syntaxe ```js -containing(codeUnitIndex) +containing(codeUnitIndex); ``` ### Paramètres @@ -40,9 +40,9 @@ Un objet qui décrit le segment faisant partie de la chaîne de caractères orig ```js // ┃0 1 2 3 4 5┃6┃7┃8┃9 ← Indice des codets // ┃A l l o n s┃-┃y┃!┃ ← Codets -const input = 'Allons-y!'; +const input = "Allons-y!"; -const segmenter = new Intl.Segmenter('fr', {granularity: 'word'}); +const segmenter = new Intl.Segmenter("fr", { granularity: "word" }); const segments = segmenter.segment(input); let current = undefined; diff --git a/files/fr/web/javascript/reference/global_objects/intl/segmenter/segmenter/index.md b/files/fr/web/javascript/reference/global_objects/intl/segmenter/segmenter/index.md index ec23bb4b96aebf..d2fd9312bbf86e 100644 --- a/files/fr/web/javascript/reference/global_objects/intl/segmenter/segmenter/index.md +++ b/files/fr/web/javascript/reference/global_objects/intl/segmenter/segmenter/index.md @@ -13,9 +13,9 @@ Le constructeur **`Intl.Segmenter()`** crée un objet [`Intl.Segmenter`](/fr/doc ## Syntaxe ```js -new Intl.Segmenter() -new Intl.Segmenter(locales) -new Intl.Segmenter(locales, options) +new Intl.Segmenter(); +new Intl.Segmenter(locales); +new Intl.Segmenter(locales, options); ``` ### Paramètres @@ -51,8 +51,11 @@ Dans l'exemple suivant, on compte les mots d'une chaîne en japonais (où le dé ```js const text = "吾輩は猫である。名前はたぬき。"; -const japaneseSegmenter = new Intl.Segmenter('ja-JP', {granularity: 'word'}); -console.log([...japaneseSegmenter.segment(text)].filter(segment => segment.isWordLike).length); +const japaneseSegmenter = new Intl.Segmenter("ja-JP", { granularity: "word" }); +console.log( + [...japaneseSegmenter.segment(text)].filter((segment) => segment.isWordLike) + .length, +); // affiche 8 car le texte est segmenté en '吾輩'|'は'|'猫'|'で'|'ある'|'。'|'名前'|'は'|'たぬき'|'。' ``` diff --git a/files/fr/web/javascript/reference/global_objects/intl/segmenter/supportedlocalesof/index.md b/files/fr/web/javascript/reference/global_objects/intl/segmenter/supportedlocalesof/index.md index 006f6cce8550b9..9a79f9db3b7a57 100644 --- a/files/fr/web/javascript/reference/global_objects/intl/segmenter/supportedlocalesof/index.md +++ b/files/fr/web/javascript/reference/global_objects/intl/segmenter/supportedlocalesof/index.md @@ -13,8 +13,8 @@ La méthode **`Intl.Segmenter.supportedLocalesOf()`** renvoie un tableau contena ## Syntaxe ```js -supportedLocalesOf(locales) -supportedLocalesOf(locales, options) +supportedLocalesOf(locales); +supportedLocalesOf(locales, options); ``` ### Paramètres @@ -41,9 +41,9 @@ Un tableau de chaînes de caractères représentant le sous-ensemble de locales Soit un environnement d'exécution qui prend en charge l'indonésien et l'allemand mais pas le balinais pour la segmentation, `supportedLocalesOf` renvoie les balises de langue indonésienne et allemande inchangées, même si la collation `pinyin` n'est pas pertinente pour la segmentation indonésienne et qu'un dialecte allemand pour l'Indonésie a peu de chances d'être pris en charge. On notera que l'exemple utilise l'algorithme "`lookup`" et que "`best fit`" aurait pu décider que l'indonésien est une correspondance valable pour le balinais, car la plupart des personnes qui parlent balinais comprennent aussi l'indonésien. En utilisant l'algorithme `"best fit"`, on aurait donc pu avoir la balise balinaise dans les résultats. ```js -const locales = ['ban', 'id-u-co-pinyin', 'de-ID']; -const options = { localeMatcher: 'lookup' }; -console.log(Intl.Segmenter.supportedLocalesOf(locales, options).join(', ')); +const locales = ["ban", "id-u-co-pinyin", "de-ID"]; +const options = { localeMatcher: "lookup" }; +console.log(Intl.Segmenter.supportedLocalesOf(locales, options).join(", ")); // → "id-u-co-pinyin, de-ID" ``` diff --git a/files/fr/web/javascript/reference/global_objects/intl/supportedvaluesof/index.md b/files/fr/web/javascript/reference/global_objects/intl/supportedvaluesof/index.md index c236e7f0b70d5b..539eb374b54989 100644 --- a/files/fr/web/javascript/reference/global_objects/intl/supportedvaluesof/index.md +++ b/files/fr/web/javascript/reference/global_objects/intl/supportedvaluesof/index.md @@ -17,7 +17,7 @@ Elle peut également être utilisée pour construire des interfaces utilisateur ## Syntaxe ```js -Intl.supportedValuesOf(cle) +Intl.supportedValuesOf(cle); ``` ### Paramètres @@ -41,7 +41,7 @@ Un tableau trié, contenant des chaînes de caractères uniques indiquant les va On peut vérifier que la méthode est prise en charge en la comparant à `undefined` : ```js -if (typeof Intl.supportedValuesOf !== 'undefined') { +if (typeof Intl.supportedValuesOf !== "undefined") { // la méthode est prise en charge } ``` @@ -51,8 +51,8 @@ if (typeof Intl.supportedValuesOf !== 'undefined') { Pour obtenir les valeurs prises en charge pour les représentations calendaires, on pourra appeler la méthode avec la clé `"calendar"` et parcourir le tableau obtenu : ```js -Intl.supportedValuesOf("calendar").forEach(function(calendar) { - // "buddhist", "chinese", "coptic", "dangi", ... +Intl.supportedValuesOf("calendar").forEach(function (calendar) { + // "buddhist", "chinese", "coptic", "dangi", ... }); ``` @@ -61,24 +61,24 @@ Intl.supportedValuesOf("calendar").forEach(function(calendar) { Les autres valeurs peuvent être obtenues de la même façon : ```js -Intl.supportedValuesOf("collation").forEach(function(collation) { - // "big5han", "compat", "dict", "emoji", ... +Intl.supportedValuesOf("collation").forEach(function (collation) { + // "big5han", "compat", "dict", "emoji", ... }); -Intl.supportedValuesOf("currency").forEach(function(currency) { - // "ADP", "AED", "AFA", "AFN", "ALK", "ALL", "AMD", ... +Intl.supportedValuesOf("currency").forEach(function (currency) { + // "ADP", "AED", "AFA", "AFN", "ALK", "ALL", "AMD", ... }); -Intl.supportedValuesOf("numberingSystem").forEach(function(numberingSystem) { - // "adlm", "ahom", "arab", "arabext", "bali", ... +Intl.supportedValuesOf("numberingSystem").forEach(function (numberingSystem) { + // "adlm", "ahom", "arab", "arabext", "bali", ... }); -Intl.supportedValuesOf("timeZone").forEach(function(timeZone) { - // "Africa/Abidjan", "Africa/Accra", "Africa/Addis_Ababa", "Africa/Algiers", ... +Intl.supportedValuesOf("timeZone").forEach(function (timeZone) { + // "Africa/Abidjan", "Africa/Accra", "Africa/Addis_Ababa", "Africa/Algiers", ... }); -Intl.supportedValuesOf("unit").forEach(function(unit) { - // "acre", "bit", "byte", "celsius", "centimeter", ... +Intl.supportedValuesOf("unit").forEach(function (unit) { + // "acre", "bit", "byte", "celsius", "centimeter", ... }); ``` diff --git a/files/fr/web/javascript/reference/global_objects/isfinite/index.md b/files/fr/web/javascript/reference/global_objects/isfinite/index.md index 4a640ff6657eb3..2965438d7a9bcb 100644 --- a/files/fr/web/javascript/reference/global_objects/isfinite/index.md +++ b/files/fr/web/javascript/reference/global_objects/isfinite/index.md @@ -13,7 +13,7 @@ La fonction globale **`isFinite()`** détermine si la valeur passée en argument ## Syntaxe ```js -isFinite(valeurÀTester) +isFinite(valeurÀTester); ``` ### Paramètres @@ -34,19 +34,18 @@ Cette fonction peut être utilisée pour déterminer si un nombre est fini ou no ## Exemples ```js -isFinite(Infinity); // false -isFinite(NaN); // false +isFinite(Infinity); // false +isFinite(NaN); // false isFinite(-Infinity); // false -isFinite(0); // true -isFinite(2e64); // true -isFinite(910); // true -isFinite(null); // true, ce qui aurait été false - // avec la méthode Number.isFinite(null) +isFinite(0); // true +isFinite(2e64); // true +isFinite(910); // true +isFinite(null); // true, ce qui aurait été false +// avec la méthode Number.isFinite(null) - -isFinite("0"); // true ce qui aurait été false - // avec la méthode Number.isFinite("0") +isFinite("0"); // true ce qui aurait été false +// avec la méthode Number.isFinite("0") ``` ## Spécifications diff --git a/files/fr/web/javascript/reference/global_objects/isnan/index.md b/files/fr/web/javascript/reference/global_objects/isnan/index.md index 6656201c5e8e43..18269209dc8999 100644 --- a/files/fr/web/javascript/reference/global_objects/isnan/index.md +++ b/files/fr/web/javascript/reference/global_objects/isnan/index.md @@ -13,7 +13,7 @@ La fonction **`isNaN()`** permet de déterminer si une valeur est {{jsxref("NaN" ## Syntaxe ```js -isNaN(valeurÀTester) +isNaN(valeurÀTester); ``` ### Paramètres @@ -44,7 +44,7 @@ Depuis les premières spécifications pour `isNaN()`, son comportement sur les a La version ECMAScript ES2015 ajoute la méthode {{jsxref("Number.isNaN()")}}. `Number.isNaN(x)` permettra de tester de façon plus fiable si `x` vaut `NaN` ou non. Si on ne dispose pas de cette méthode, on peut également utiliser l'expression `(x != x)` afin de tester de façon plus certaine si `x` vaut `NaN` ou non (en effet le résultat de cette expression n'aura pas les faux positifs de `isNaN`). Sous cet angle, `isNaN()` peut être vu comme : ```js -var isNaN = function(valeur) { +var isNaN = function (valeur) { return Number.isNaN(Number(valeur)); }; ``` @@ -52,7 +52,7 @@ var isNaN = function(valeur) { Ou encore, en utilisant le fait que `NaN` est la seule valeur différente d'elle-même : ```js -var isNaN = function(valeur) { +var isNaN = function (valeur) { var n = Number(valeur); return n !== n; }; @@ -66,7 +66,7 @@ On peut par exemple construire une fonction dont on souhaite qu'elle incrémente ```js function incrément(x) { - if (isNaN(x)){ + if (isNaN(x)) { x = 0; } return x + 1; @@ -78,38 +78,38 @@ function incrémentCourt(x) { isNaN(x) ? 1 : x + 1; } -incrément("blabla"); // 1 -incrément(1); // 2 -incrément(NaN); // 1 +incrément("blabla"); // 1 +incrément(1); // 2 +incrément(NaN); // 1 ``` ## Exemples ```js -isNaN(NaN); // true +isNaN(NaN); // true isNaN(undefined); // true -isNaN({}); // true +isNaN({}); // true -isNaN(true); // false -isNaN(null); // false -isNaN(37); // false +isNaN(true); // false +isNaN(null); // false +isNaN(37); // false // strings -isNaN("37"); // false : "37" est converti vers le nombre 37 qui n'est pas NaN -isNaN("37.37"); // false : "37.37" est converti vers le nombre 37.37 qui n'est pas NaN -isNaN("37,25"); // true : la virgule n'est pas considérée comme un séparateur décimal -isNaN("123ABC"); // true : "123ABC" converti en 123 par parseInt mais en NaN par Number -isNaN(""); // false : la chaîne vide est convertie en 0 qui n'est pas NaN -isNaN(" "); // false : une chaîne de blancs est convertie en 0 qui n'est pas NaN +isNaN("37"); // false : "37" est converti vers le nombre 37 qui n'est pas NaN +isNaN("37.37"); // false : "37.37" est converti vers le nombre 37.37 qui n'est pas NaN +isNaN("37,25"); // true : la virgule n'est pas considérée comme un séparateur décimal +isNaN("123ABC"); // true : "123ABC" converti en 123 par parseInt mais en NaN par Number +isNaN(""); // false : la chaîne vide est convertie en 0 qui n'est pas NaN +isNaN(" "); // false : une chaîne de blancs est convertie en 0 qui n'est pas NaN // dates -isNaN(new Date()); // false -isNaN(new Date().toString()); // true +isNaN(new Date()); // false +isNaN(new Date().toString()); // true // Voici le résultat « faux-positif » qui fait que isNaN n'est pas entièrement fiable -isNaN("blabla") // true : "blabla" est converti en un nombre - // Si on souhaite convertir cette valeur en nombre, cela échoue - // et on obtient NaN +isNaN("blabla"); // true : "blabla" est converti en un nombre +// Si on souhaite convertir cette valeur en nombre, cela échoue +// et on obtient NaN ``` ## Spécifications diff --git a/files/fr/web/javascript/reference/global_objects/json/parse/index.md b/files/fr/web/javascript/reference/global_objects/json/parse/index.md index f495a065759c0c..8639c03a925857 100644 --- a/files/fr/web/javascript/reference/global_objects/json/parse/index.md +++ b/files/fr/web/javascript/reference/global_objects/json/parse/index.md @@ -37,11 +37,11 @@ Lève une exception {{jsxref("SyntaxError")}} si la chaine de caractère à anal ```js try { - JSON.parse('{}'); // {} - JSON.parse('true'); // true - JSON.parse('"toto"'); // "toto" + JSON.parse("{}"); // {} + JSON.parse("true"); // true + JSON.parse('"toto"'); // "toto" JSON.parse('[1, 5, "false"]'); // [1, 5, "false"] - JSON.parse('null'); // null + JSON.parse("null"); // null } catch (e) { console.error("Parsing error:", e); } @@ -55,17 +55,17 @@ Si le _reviver_ ne transforme que certaines valeurs et pas d'autres, assurez-vou ```js JSON.parse('{"p": 5}', (key, value) => { - if (typeof value === 'number') { - return value * 2; // renvoie value * 2 pour les nombres + if (typeof value === "number") { + return value * 2; // renvoie value * 2 pour les nombres } - return value; // pour le reste, la valeur est inchangée + return value; // pour le reste, la valeur est inchangée }); // { p: 10 } JSON.parse('{"1": 1, "2": 2,"3": {"4": 4, "5": {"6": 6}}}', (key, value) => { - console.log(key); // on affiche le nom de la propriété dans la console - return value; // et on renvoie la valeur inchangée. + console.log(key); // on affiche le nom de la propriété dans la console + return value; // et on renvoie la valeur inchangée. }); // 1 @@ -81,7 +81,7 @@ JSON.parse('{"1": 1, "2": 2,"3": {"4": 4, "5": {"6": 6}}}', (key, value) => { ```js example-bad // les deux instructions qui suivent lèveront une SyntaxError -JSON.parse('[1, 2, 3, 4, ]'); +JSON.parse("[1, 2, 3, 4, ]"); JSON.parse('{ "toto" : 1, }'); ``` diff --git a/files/fr/web/javascript/reference/global_objects/json/stringify/index.md b/files/fr/web/javascript/reference/global_objects/json/stringify/index.md index a67aea37c0404e..fe9e36c095d49e 100644 --- a/files/fr/web/javascript/reference/global_objects/json/stringify/index.md +++ b/files/fr/web/javascript/reference/global_objects/json/stringify/index.md @@ -54,18 +54,18 @@ La fonction `JSON.stringify()` convertit un objet en JSON : - Pour les autres instances d'objets tels que {{jsxref("Map")}}, {{jsxref("Set")}}, {{jsxref("WeakMap")}} et {{jsxref("WeakSet")}}, seules les propriétés énumérables sont sérialisées. ```js -JSON.stringify({}); // '{}' -JSON.stringify(true); // 'true' -JSON.stringify("toto"); // '"toto"' -JSON.stringify([1, "false", false]); // '[1,"false",false]' -JSON.stringify([NaN, null, Infinity]); // '[null,null,null]' -JSON.stringify({ x: 5 }); // '{"x":5}' +JSON.stringify({}); // '{}' +JSON.stringify(true); // 'true' +JSON.stringify("toto"); // '"toto"' +JSON.stringify([1, "false", false]); // '[1,"false",false]' +JSON.stringify([NaN, null, Infinity]); // '[null,null,null]' +JSON.stringify({ x: 5 }); // '{"x":5}' JSON.stringify(new Date(2006, 0, 2, 15, 4, 5)); // '"2006-01-02T23:04:05.000Z"' // Exemples -JSON.stringify({x: 5, y: 6}); +JSON.stringify({ x: 5, y: 6 }); // '{"x":5,"y":6}' JSON.stringify([new Number(3), new String("false"), new Boolean(false)]); // '[3,"false",false]' @@ -78,57 +78,78 @@ JSON.stringify(a); // '["toto","truc"]' // Symboles -JSON.stringify({x: undefined, y: Object, z: Symbol("")}); +JSON.stringify({ x: undefined, y: Object, z: Symbol("") }); // '{}' -JSON.stringify({[Symbol("toto")]: "toto"}); +JSON.stringify({ [Symbol("toto")]: "toto" }); // '{}' -JSON.stringify({[Symbol.for("toto")]: "toto"}, [Symbol.for("toto")]); +JSON.stringify({ [Symbol.for("toto")]: "toto" }, [Symbol.for("toto")]); // '{}' -JSON.stringify({[Symbol.for("toto")]: "toto"}, function (k, v) { - if (typeof k === "symbol"){ +JSON.stringify({ [Symbol.for("toto")]: "toto" }, function (k, v) { + if (typeof k === "symbol") { return "a symbol"; } }); // '{}' -JSON.stringify({ x: [10, undefined, function(){}, Symbol('')] }); +JSON.stringify({ x: [10, undefined, function () {}, Symbol("")] }); // '{"x":[10,null,null,null]}' // Structures de données classiques -JSON.stringify([new Set([1]), new Map([[1, 2]]), new WeakSet([{a: 1}]), new WeakMap([[{a: 1}, 2]])]); +JSON.stringify([ + new Set([1]), + new Map([[1, 2]]), + new WeakSet([{ a: 1 }]), + new WeakMap([[{ a: 1 }, 2]]), +]); // '[{},{},{},{}]' // TypedArray JSON.stringify([new Int8Array([1]), new Int16Array([1]), new Int32Array([1])]); // '[{"0":1},{"0":1},{"0":1}]' -JSON.stringify([new Uint8Array([1]), new Uint8ClampedArray([1]), new Uint16Array([1]), new Uint32Array([1])]); +JSON.stringify([ + new Uint8Array([1]), + new Uint8ClampedArray([1]), + new Uint16Array([1]), + new Uint32Array([1]), +]); // '[{"0":1},{"0":1},{"0":1},{"0":1}]' JSON.stringify([new Float32Array([1]), new Float64Array([1])]); // '[{"0":1},{"0":1}]' // toJSON() -JSON.stringify({ x: 5, y: 6, toJSON(){ return this.x + this.y; } }); +JSON.stringify({ + x: 5, + y: 6, + toJSON() { + return this.x + this.y; + }, +}); // '11' // Symbols: -JSON.stringify({ x: undefined, y: Object, z: Symbol('') }); +JSON.stringify({ x: undefined, y: Object, z: Symbol("") }); // '{}' -JSON.stringify({ [Symbol('foo')]: 'foo' }); +JSON.stringify({ [Symbol("foo")]: "foo" }); // '{}' -JSON.stringify({ [Symbol.for('foo')]: 'foo' }, [Symbol.for('foo')]); +JSON.stringify({ [Symbol.for("foo")]: "foo" }, [Symbol.for("foo")]); // '{}' -JSON.stringify({ [Symbol.for('foo')]: 'foo' }, function(k, v) { - if (typeof k === 'symbol') { - return 'a symbol'; +JSON.stringify({ [Symbol.for("foo")]: "foo" }, function (k, v) { + if (typeof k === "symbol") { + return "a symbol"; } }); // undefined // Propriétés non énumérables -JSON.stringify(Object.create(null, { x: { value: 'x', enumerable: false }, y: { value: 'y', enumerable: true } }) ); +JSON.stringify( + Object.create(null, { + x: { value: "x", enumerable: false }, + y: { value: "y", enumerable: true }, + }), +); // '{"y":"y"}' // Échec avec BigInt -JSON.stringify({x: 2n}); +JSON.stringify({ x: 2n }); // TypeError: BigInt value can't be serialized in JSON ``` @@ -157,7 +178,13 @@ function remplaçant(clé, valeur) { return valeur; } -var toto = {fondation: "Mozilla", modèle: "boîte", semaine: 45, transport: "bus", mois: 7}; +var toto = { + fondation: "Mozilla", + modèle: "boîte", + semaine: 45, + transport: "bus", + mois: 7, +}; console.log(JSON.stringify(toto, remplaçant)); // {"semaine":45, "mois":7} ``` @@ -166,7 +193,7 @@ console.log(JSON.stringify(toto, remplaçant)); // {"semaine":45, "mois":7} Si `remplaçant` est un tableau, les valeurs du tableau indiquent les propriétés de l'objet à inclure dans la chaîne JSON. ```js -JSON.stringify(toto, ['semaine', 'mois']); +JSON.stringify(toto, ["semaine", "mois"]); // '{"semaine":45,"mois":7}', on ne garde que "semaines" et "mois" ``` @@ -178,7 +205,7 @@ L'argument `espace` est utilisé pour contrôler les espacements utilisés dans - Si c'est une chaîne, les dix premiers caractères (ou la chaîne complète si elle est plus courte) ```js -JSON.stringify({ a: 2 }, null, ' '); +JSON.stringify({ a: 2 }, null, " "); // '{ // "a": 2 // }' @@ -187,7 +214,7 @@ JSON.stringify({ a: 2 }, null, ' '); Dans l'exemple suivant on utilise la tabulation pour rendre lisible le résultat : ```js -JSON.stringify({ uno: 1, dos: 2 }, null, '\t'); +JSON.stringify({ uno: 1, dos: 2 }, null, "\t"); // renverra // '{ // "uno": 1, @@ -207,23 +234,23 @@ Ainsi : ```js var obj = { - data: 'data', - toJSON(clef){ - if(clef) { + data: "data", + toJSON(clef) { + if (clef) { return `Un objet imbriqué sous la clef '${clef}'`; } else { return this; } - } + }, }; JSON.stringify(obj); // '{"data":"data"}' -JSON.stringify({ obj }) +JSON.stringify({ obj }); // '{"obj":"Un objet imbriqué sous la clef 'obj'"}' -JSON.stringify([ obj ]) +JSON.stringify([obj]); // '["Un objet imbriqué sous la clef '0'"]' ``` @@ -248,15 +275,15 @@ Par le passé, JSON n'était pas un sous-ensemble strict de JavaScript. En effet Ainsi, si on souhaite avoir une compatibilité avec les anciens moteurs JavaScript, on pourra évaluer ou utiliser les données JSON avec [JSONP](https://fr.wikipedia.org/wiki/JSONP) et la fonction utilitaire suivante : ```js -function jsFriendlyJSONStringify (s) { - return JSON.stringify(s). - replace(/\u2028/g, '\\u2028'). - replace(/\u2029/g, '\\u2029'); +function jsFriendlyJSONStringify(s) { + return JSON.stringify(s) + .replace(/\u2028/g, "\\u2028") + .replace(/\u2029/g, "\\u2029"); } var s = { - a: String.fromCharCode(0x2028), - b: String.fromCharCode(0x2029) + a: String.fromCharCode(0x2028), + b: String.fromCharCode(0x2029), }; // dans Firefox, console.log enlève les échappements @@ -267,9 +294,9 @@ alert(jsFriendlyJSONStringify(s)); // {"a":"\u2028","b":"\u2029"} > **Note :** Les propriétés des objets qui ne sont pas des tableaux ne sont pas transformées en chaînes de caractères selon un ordre particulier. Aussi, l'ordre des données en JSON ne saurait constituer une information utile. ```js -var a = JSON.stringify({toto: "truc", bidule: "machin"}); +var a = JSON.stringify({ toto: "truc", bidule: "machin" }); // '{"toto":"truc","bidule":"machin"}' -var b = JSON.stringify({bidule: "machin", toto: "truc"}); +var b = JSON.stringify({ bidule: "machin", toto: "truc" }); // '{"bidule":"machin","toto":"truc"}' console.log(a !== b); // true ``` @@ -283,23 +310,23 @@ Dans le cas où on souhaite enregistrer un objet créé par l'utilisateur afin d ```js // On crée un objet pour l'exemple var session = { - 'screens' : [], - 'state' : true + screens: [], + state: true, }; -session.screens.push({"name":"screenA", "width":450, "height":250}); -session.screens.push({"name":"screenB", "width":650, "height":350}); -session.screens.push({"name":"screenC", "width":750, "height":120}); -session.screens.push({"name":"screenD", "width":250, "height":60}); -session.screens.push({"name":"screenE", "width":390, "height":120}); -session.screens.push({"name":"screenF", "width":1240, "height":650}); +session.screens.push({ name: "screenA", width: 450, height: 250 }); +session.screens.push({ name: "screenB", width: 650, height: 350 }); +session.screens.push({ name: "screenC", width: 750, height: 120 }); +session.screens.push({ name: "screenD", width: 250, height: 60 }); +session.screens.push({ name: "screenE", width: 390, height: 120 }); +session.screens.push({ name: "screenF", width: 1240, height: 650 }); // On convertit l'objet en une chaîne JSON // et on enregistre cette valeur avec le nom 'session' -localStorage.setItem('session', JSON.stringify(session)); +localStorage.setItem("session", JSON.stringify(session)); // Ici, on reconvertit la chaîne en un objet // JSON.stringify and saved in localStorage in JSON object again -var sessionRestaurée = JSON.parse(localStorage.getItem('session')); +var sessionRestaurée = JSON.parse(localStorage.getItem("session")); // La variable sessionRestaurée contient désormais l'objet précédent // qui avait été sauvegardé dans localStorage diff --git a/files/fr/web/javascript/reference/global_objects/map/@@iterator/index.md b/files/fr/web/javascript/reference/global_objects/map/@@iterator/index.md index 5e3b3127481024..a14988b4e9a818 100644 --- a/files/fr/web/javascript/reference/global_objects/map/@@iterator/index.md +++ b/files/fr/web/javascript/reference/global_objects/map/@@iterator/index.md @@ -13,7 +13,7 @@ La valeur initiale de la propriété **`@@iterator`** est la même fonction que ## Syntaxe ```js -maMap[Symbol.iterator] +maMap[Symbol.iterator]; ``` ### Valeur de retour diff --git a/files/fr/web/javascript/reference/global_objects/map/@@species/index.md b/files/fr/web/javascript/reference/global_objects/map/@@species/index.md index 84939015890205..fe9fd31404f8da 100644 --- a/files/fr/web/javascript/reference/global_objects/map/@@species/index.md +++ b/files/fr/web/javascript/reference/global_objects/map/@@species/index.md @@ -11,7 +11,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/Map/@@species ## Syntaxe ```js -Map[Symbol.species] +Map[Symbol.species]; ``` ## Description @@ -32,7 +32,9 @@ Pour des objets dérivés (par exemple un dictionnaire `MaMap` que vous auriez c class MaMap extends Map { // On surcharge le symbole species de MaMap // avec le constructeur Map parent - static get [Symbol.species]() { return Map; } + static get [Symbol.species]() { + return Map; + } } ``` diff --git a/files/fr/web/javascript/reference/global_objects/map/clear/index.md b/files/fr/web/javascript/reference/global_objects/map/clear/index.md index 3bea46d3aeb9d9..7cedda796d07f1 100644 --- a/files/fr/web/javascript/reference/global_objects/map/clear/index.md +++ b/files/fr/web/javascript/reference/global_objects/map/clear/index.md @@ -29,13 +29,13 @@ var maMap = new Map(); maMap.set("truc", "bidule"); maMap.set(1, "toto"); -maMap.size; // 2 +maMap.size; // 2 maMap.has("truc"); // true maMap.clear(); -maMap.size; // 0 -maMap.has("truc") // false +maMap.size; // 0 +maMap.has("truc"); // false ``` ## Spécifications diff --git a/files/fr/web/javascript/reference/global_objects/map/delete/index.md b/files/fr/web/javascript/reference/global_objects/map/delete/index.md index 31b62f00d9562e..c58e9541042dce 100644 --- a/files/fr/web/javascript/reference/global_objects/map/delete/index.md +++ b/files/fr/web/javascript/reference/global_objects/map/delete/index.md @@ -32,7 +32,7 @@ var maMap = new Map(); maMap.set("truc", "toto"); maMap.delete("truc"); // Renvoie true. La suppression est OK. -maMap.has("truc"); // Renvoie false. "truc" n'est plus présent. +maMap.has("truc"); // Renvoie false. "truc" n'est plus présent. ``` ## Spécifications diff --git a/files/fr/web/javascript/reference/global_objects/map/entries/index.md b/files/fr/web/javascript/reference/global_objects/map/entries/index.md index 10053107433cb2..bb93870d270463 100644 --- a/files/fr/web/javascript/reference/global_objects/map/entries/index.md +++ b/files/fr/web/javascript/reference/global_objects/map/entries/index.md @@ -13,7 +13,7 @@ La méthode **`entries()`** renvoie un objet [`Iterator`](/fr/docs/Web/JavaScrip ## Syntaxe ```js -maMap.entries() +maMap.entries(); ``` ### Valeur de retour diff --git a/files/fr/web/javascript/reference/global_objects/map/foreach/index.md b/files/fr/web/javascript/reference/global_objects/map/foreach/index.md index b924d55ecf4733..d3dc75406cb585 100644 --- a/files/fr/web/javascript/reference/global_objects/map/foreach/index.md +++ b/files/fr/web/javascript/reference/global_objects/map/foreach/index.md @@ -45,15 +45,18 @@ Chacune des valeurs sera traitée une fois sauf si celle-ci a été supprimée p ## Exemples -Le fragment de code suivant enregistre une ligne pour chaque élément d'un objet` Map `: +Le fragment de code suivant enregistre une ligne pour chaque élément d'un objet`Map`: ```js function logMapElements(valeur, clé, map) { - console.log(`map.get('${clé}') = ${value}`); + console.log(`map.get('${clé}') = ${value}`); } - -new Map([["toto", 3], ["truc", {}], ["bidule", undefined]]).forEach(logMapElements); +new Map([ + ["toto", 3], + ["truc", {}], + ["bidule", undefined], +]).forEach(logMapElements); // affichera dans la console : // "map.get('toto') = 3" // "map.get('truc') = [object Object]" diff --git a/files/fr/web/javascript/reference/global_objects/map/get/index.md b/files/fr/web/javascript/reference/global_objects/map/get/index.md index caf3cbbff9dfa1..092bc603ed5b93 100644 --- a/files/fr/web/javascript/reference/global_objects/map/get/index.md +++ b/files/fr/web/javascript/reference/global_objects/map/get/index.md @@ -13,7 +13,7 @@ La méthode **`get()`** renvoie un élément précisé d'un objet `Map`. Si la v ## Syntaxe ```js -maMap.get(clé) +maMap.get(clé); ``` ### Paramètres @@ -31,8 +31,8 @@ L'élément associée à la clé donnée ou {{jsxref("undefined")}} si la clé n var maMap = new Map(); maMap.set("truc", "toto"); -maMap.get("truc"); // Renvoie "toto". -maMap.get("machin"); // Renvoie undefined. +maMap.get("truc"); // Renvoie "toto". +maMap.get("machin"); // Renvoie undefined. ``` ## Spécifications diff --git a/files/fr/web/javascript/reference/global_objects/map/has/index.md b/files/fr/web/javascript/reference/global_objects/map/has/index.md index 760baa530dda50..15ec5b998ffe77 100644 --- a/files/fr/web/javascript/reference/global_objects/map/has/index.md +++ b/files/fr/web/javascript/reference/global_objects/map/has/index.md @@ -31,8 +31,8 @@ Cette méthode renvoie un booléen : `true` si un élément avec cette clé exis var maMap = new Map(); maMap.set("truc", "toto"); -maMap.has("truc"); // renvoie true -maMap.has("machin");// renvoie false +maMap.has("truc"); // renvoie true +maMap.has("machin"); // renvoie false ``` ## Spécifications diff --git a/files/fr/web/javascript/reference/global_objects/map/index.md b/files/fr/web/javascript/reference/global_objects/map/index.md index 1b41ffc8f9858f..70c05e5b20fcb2 100644 --- a/files/fr/web/javascript/reference/global_objects/map/index.md +++ b/files/fr/web/javascript/reference/global_objects/map/index.md @@ -115,10 +115,10 @@ Ainsi, on pourra faire : ```js example-bad const mauvaiseMap = new Map(); -mauvaiseMap['bla'] = 'blaa'; -mauvaiseMap['bla2'] = 'blaaa2'; +mauvaiseMap["bla"] = "blaa"; +mauvaiseMap["bla2"] = "blaaa2"; -console.log(mauvaiseMap); // Map { bla: 'blaa', bla2: 'blaaa2' } +console.log(mauvaiseMap); // Map { bla: 'blaa', bla2: 'blaaa2' } ``` Mais ces instructions n'interagissent pas avec la structure `Map`, elles ne font qu'ajouter des propriétés objet. La valeur associée à la clé `"bla"` n'est pas stockée dans la `Map`. Ainsi, si on utilise les méthodes de `Map`, cela échouera : @@ -133,13 +133,16 @@ Pour stocker des données dans une structure `Map`, on utilisera plutôt la mét ```js example-good const contacts = new Map(); -contacts.set('Jessie', {phone: "01 99 00 12 34", address: "1 Rue de l'avenue"}); -contacts.has('Jessie'); // true -contacts.get('James'); // undefined -contacts.set('James', {phone: "06 39 98 78 89", address: "3 Chemin du Parc"}); -contacts.get('Jessie'); // {phone: "01 99 00 12 34", address: "1 Rue de l'avenue"} -contacts.delete('Miaouss'); // false -contacts.delete('Jessie'); // true +contacts.set("Jessie", { + phone: "01 99 00 12 34", + address: "1 Rue de l'avenue", +}); +contacts.has("Jessie"); // true +contacts.get("James"); // undefined +contacts.set("James", { phone: "06 39 98 78 89", address: "3 Chemin du Parc" }); +contacts.get("Jessie"); // {phone: "01 99 00 12 34", address: "1 Rue de l'avenue"} +contacts.delete("Miaouss"); // false +contacts.delete("Jessie"); // true console.log(contacts.size); // 1 ``` @@ -192,8 +195,8 @@ console.log(contacts.size); // 1 const maMap = new Map(); const objectKey = {}, - functionKey = function () {}, - stringKey = "une chaîne"; + functionKey = function () {}, + stringKey = "une chaîne"; // définir les valeurs maMap.set(stringKey, "valeur associée à 'une chaîne'"); @@ -203,14 +206,14 @@ maMap.set(functionKey, "valeur associée à functionKey"); maMap.size; // 3 // récupérer les valeurs -maMap.get(stringKey); // "valeur associée à 'une chaîne'" -maMap.get(objectKey); // "valeur associée à objetClé" -maMap.get(functionKey); // "valeur associée à fonctionClé" - -maMap.get("une chaîne"); // "valeur associée à 'une chaîne'" - // car chaineClé === 'une chaîne' -maMap.get({}); // indéfini car objetClé !== {} -maMap.get(function() {}); // indéfini car fonctionClé !== function () {} +maMap.get(stringKey); // "valeur associée à 'une chaîne'" +maMap.get(objectKey); // "valeur associée à objetClé" +maMap.get(functionKey); // "valeur associée à fonctionClé" + +maMap.get("une chaîne"); // "valeur associée à 'une chaîne'" +// car chaineClé === 'une chaîne' +maMap.get({}); // indéfini car objetClé !== {} +maMap.get(function () {}); // indéfini car fonctionClé !== function () {} ``` ### Utiliser `NaN` comme clé @@ -266,7 +269,7 @@ for (const [key, value] of maMap.entries()) { Il est aussi possible de parcourir des objets `Map` avec la méthode [`forEach()`](/fr/docs/Web/JavaScript/Reference/Global_Objects/Map/forEach) : ```js -maMap.forEach(function(value, key) { +maMap.forEach(function (value, key) { console.log(`${key} = ${value}`); }); // 0 = zéro @@ -276,7 +279,10 @@ maMap.forEach(function(value, key) { ### Relation avec les objets `Array` ```js -const keyValuePair = [["clé1", "valeur1"], ["clé2", "valeur2"]]; +const keyValuePair = [ + ["clé1", "valeur1"], + ["clé2", "valeur2"], +]; // On utilise le constructeur Map // pour transformer un tableau de clés/valeurs @@ -302,9 +308,7 @@ console.log(Array.from(maMap.keys())); // affichera ["clé1", "clé2"] Il est possible de cloner des `Map` comme on clone des tableaux : ```js -const original = new Map([ - [1, 'un'] -]); +const original = new Map([[1, "un"]]); const clone = new Map(original); @@ -318,14 +322,14 @@ Il est également possible de fusionner deux `Map` en conservant le critère d'u ```js const premier = new Map([ - [1, 'un'], - [2, 'deux'], - [3, 'trois'], + [1, "un"], + [2, "deux"], + [3, "trois"], ]); const second = new Map([ - [1, 'uno'], - [2, 'dos'] + [1, "uno"], + [2, "dos"], ]); // On fusionne les deux maps. C'est la "dernière" version @@ -343,19 +347,19 @@ Il est également possible de fusionner des objets `Map` avec des objets `Array` ```js const premier = new Map([ - [1, 'un'], - [2, 'deux'], - [3, 'trois'], + [1, "un"], + [2, "deux"], + [3, "trois"], ]); const second = new Map([ - [1, 'uno'], - [2, 'dos'] + [1, "uno"], + [2, "dos"], ]); // On peut fusionner des Maps avec un tableau // Là encore c'est le dernier exemplaire de la clé qui l'emporte -const fusion = new Map([...premier, ...second, [1, 'eins']]); +const fusion = new Map([...premier, ...second, [1, "eins"]]); console.log(fusion.get(1)); // eins console.log(fusion.get(2)); // dos diff --git a/files/fr/web/javascript/reference/global_objects/map/keys/index.md b/files/fr/web/javascript/reference/global_objects/map/keys/index.md index 486e47299864dd..0a28d94888b763 100644 --- a/files/fr/web/javascript/reference/global_objects/map/keys/index.md +++ b/files/fr/web/javascript/reference/global_objects/map/keys/index.md @@ -13,7 +13,7 @@ La méthode **`keys()`** renvoie un objet [`Iterator`](/fr/docs/Web/JavaScript/G ## Syntaxe ```js -maMap.keys() +maMap.keys(); ``` ### Valeur de retour diff --git a/files/fr/web/javascript/reference/global_objects/map/map/index.md b/files/fr/web/javascript/reference/global_objects/map/map/index.md index a7c73116c04713..54555981cf34b3 100644 --- a/files/fr/web/javascript/reference/global_objects/map/map/index.md +++ b/files/fr/web/javascript/reference/global_objects/map/map/index.md @@ -11,8 +11,8 @@ Le **constructeur `Map()`** permet de créer des objets [`Map`](/fr/docs/Web/Jav ## Syntaxe ```js -new Map() -new Map(iterable) +new Map(); +new Map(iterable); ``` ### Paramètres @@ -26,9 +26,9 @@ new Map(iterable) ```js let maMap = new Map([ - [1, 'un'], - [2, 'deux'], - [3, 'trois'], + [1, "un"], + [2, "deux"], + [3, "trois"], ]); ``` diff --git a/files/fr/web/javascript/reference/global_objects/map/set/index.md b/files/fr/web/javascript/reference/global_objects/map/set/index.md index 1ed96d98fca18e..c6c917e4de7f8a 100644 --- a/files/fr/web/javascript/reference/global_objects/map/set/index.md +++ b/files/fr/web/javascript/reference/global_objects/map/set/index.md @@ -49,9 +49,7 @@ La méthode `set()` renvoie le même objet `Map` et on peut donc la « chaîner ```js // On ajoute de nouveaux éléments // en enchaînant les appels à set() -maMap.set('truc', 'toto') - .set(1, 'tototruc') - .set(2, 'bidule'); +maMap.set("truc", "toto").set(1, "tototruc").set(2, "bidule"); ``` ## Spécifications diff --git a/files/fr/web/javascript/reference/global_objects/map/size/index.md b/files/fr/web/javascript/reference/global_objects/map/size/index.md index cbfc1f0fee210c..63c2dac7a42133 100644 --- a/files/fr/web/javascript/reference/global_objects/map/size/index.md +++ b/files/fr/web/javascript/reference/global_objects/map/size/index.md @@ -24,7 +24,7 @@ maMap.set("a", "alpha"); maMap.set("b", "beta"); maMap.set("g", "gamma"); -maMap.size // 3 +maMap.size; // 3 ``` ## Spécifications diff --git a/files/fr/web/javascript/reference/global_objects/map/values/index.md b/files/fr/web/javascript/reference/global_objects/map/values/index.md index 16702836007a78..41c52122fe8df5 100644 --- a/files/fr/web/javascript/reference/global_objects/map/values/index.md +++ b/files/fr/web/javascript/reference/global_objects/map/values/index.md @@ -13,7 +13,7 @@ La méthode **`values()`** renvoie un objet [`Iterator`](/fr/docs/Web/JavaScript ## Syntaxe ```js -maMap.values() +maMap.values(); ``` ### Valeur de retour diff --git a/files/fr/web/javascript/reference/global_objects/math/abs/index.md b/files/fr/web/javascript/reference/global_objects/math/abs/index.md index cd7583ad12ee03..598647c3891ba2 100644 --- a/files/fr/web/javascript/reference/global_objects/math/abs/index.md +++ b/files/fr/web/javascript/reference/global_objects/math/abs/index.md @@ -38,16 +38,16 @@ La valeur absolue du nombre passé en argument. Si la méthode est utilisée avec une chaîne de caractères non numérique, avec un tableau à plus d'un élément, sans paramètre ou avec {{jsxref("undefined")}}, la valeur retournée sera {{jsxref("NaN")}}. Si elle est utilisée avec {{jsxref("null")}}, la fonction renverra 0. ```js -Math.abs('-1'); // 1 -Math.abs(-2); // 2 -Math.abs(null); // 0 -Math.abs(''); // 0 -Math.abs([]); // 0 -Math.abs([2]); // 2 -Math.abs([1,2]); // NaN -Math.abs({}); // NaN +Math.abs("-1"); // 1 +Math.abs(-2); // 2 +Math.abs(null); // 0 +Math.abs(""); // 0 +Math.abs([]); // 0 +Math.abs([2]); // 2 +Math.abs([1, 2]); // NaN +Math.abs({}); // NaN Math.abs("string"); // NaN -Math.abs(); // NaN +Math.abs(); // NaN ``` ## Spécifications diff --git a/files/fr/web/javascript/reference/global_objects/math/acos/index.md b/files/fr/web/javascript/reference/global_objects/math/acos/index.md index 30c9096c5c668c..b705230e3b08f7 100644 --- a/files/fr/web/javascript/reference/global_objects/math/acos/index.md +++ b/files/fr/web/javascript/reference/global_objects/math/acos/index.md @@ -15,7 +15,7 @@ La fonction **`Math.acos()`** renvoie l'arc cosinus d'une valeur exprimée en ra ## Syntaxe ```js -Math.acos(x) +Math.acos(x); ``` ### Paramètres @@ -38,12 +38,12 @@ La méthode `acos` renvoie une valeur numérique comprise entre 0 et Pi pour x c ### Utiliser `Math.acos()` ```js -Math.acos(-2); // NaN -Math.acos(-1); // 3.141592653589793 -Math.acos(0); // 1.5707963267948966 +Math.acos(-2); // NaN +Math.acos(-1); // 3.141592653589793 +Math.acos(0); // 1.5707963267948966 Math.acos(0.5); // 1.0471975511965979 -Math.acos(1); // 0 -Math.acos(2); // NaN +Math.acos(1); // 0 +Math.acos(2); // NaN ``` Pour les valeurs (strictement) inférieures à -1 ou supérieures à 1, `Math.acos` renvoie `NaN`. diff --git a/files/fr/web/javascript/reference/global_objects/math/acosh/index.md b/files/fr/web/javascript/reference/global_objects/math/acosh/index.md index 9fa3769faf6a1c..b6c2365cbdd97f 100644 --- a/files/fr/web/javascript/reference/global_objects/math/acosh/index.md +++ b/files/fr/web/javascript/reference/global_objects/math/acosh/index.md @@ -15,7 +15,7 @@ La fonction **`Math.acosh()`** renvoie l'arc cosinus hyperbolique d'un nombre.El ## Syntaxe ```js -Math.acosh(x) +Math.acosh(x); ``` ### Paramètres @@ -36,11 +36,11 @@ L'arc cosinus hyperbolique du nombre en argument. Si le nombre est inférieur à ### Utiliser `Math.acosh()` ```js -Math.acosh(-1); // NaN -Math.acosh(0); // NaN +Math.acosh(-1); // NaN +Math.acosh(0); // NaN Math.acosh(0.5); // NaN -Math.acosh(1); // 0 -Math.acosh(2); // 1.3169578969248166 +Math.acosh(1); // 0 +Math.acosh(2); // 1.3169578969248166 ``` Pour les valeurs strictement inférieures à 1 `Math.acosh` renvoie {{jsxref("NaN")}}. diff --git a/files/fr/web/javascript/reference/global_objects/math/asin/index.md b/files/fr/web/javascript/reference/global_objects/math/asin/index.md index c4d1377c08069d..7ea7b54a3baa75 100644 --- a/files/fr/web/javascript/reference/global_objects/math/asin/index.md +++ b/files/fr/web/javascript/reference/global_objects/math/asin/index.md @@ -15,7 +15,7 @@ La fonction **`Math.asin()`** renvoie l'arc sinus d'un nombre (en radians). Elle ## Syntaxe ```js -Math.asin(x) +Math.asin(x); ``` ### Paramètres @@ -38,12 +38,12 @@ La méthode `Math.asin()` renvoie une valeur numérique comprise entre x(-1,1),Math.atanh(x)=arctanh(x)= le seul y tel quetanh(y)=x\forall x \in \left( -1, 1 \right), \mathtt{\operatorname{Math.atanh}(x)} = \operatorname{arctanh}(x) = \text{ the unique } \; y \; \text{such that} \; \tanh(y) = x +x(-1,1),Math.atanh(x)=arctanh(x)= le seul y tel quetanh(y)=x\forall x \in \left( -1, 1 \right), \mathtt{\operatorname{Math.atanh}(x)} = \operatorname{arctanh}(x) = \text{ the unique } \; y \; \text{such that} \; \tanh(y) = x {{EmbedInteractiveExample("pages/js/math-atanh.html")}} ## Syntaxe ```js -Math.atanh(x) +Math.atanh(x); ``` ### Paramètres @@ -36,12 +36,12 @@ L'arc tangente hyperbolique du nombre passé en argument. ### Utiliser `Math.atanh()` ```js -Math.atanh(-2); // NaN -Math.atanh(-1); // -Infinity -Math.atanh(0); // 0 +Math.atanh(-2); // NaN +Math.atanh(-1); // -Infinity +Math.atanh(0); // 0 Math.atanh(0.5); // 0.5493061443340548 -Math.atanh(1); // Infinity -Math.atanh(2); // NaN +Math.atanh(1); // Infinity +Math.atanh(2); // NaN ``` Pour les valeurs strictement inférieures à -1 ou strictement supérieures à 1, {{jsxref("NaN")}} sera renvoyé. @@ -51,9 +51,11 @@ Pour les valeurs strictement inférieures à -1 ou strictement supérieures à 1 Pour |x|<1\left|x\right| < 1, on a la formule suivante : artanh(x)=12ln(1+x1-x)\operatorname {artanh} (x) = \frac{1}{2}\ln \left( \frac{1 + x}{1 - x} \right)et on peut donc émuler la fonction avec : ```js -Math.atanh = Math.atanh || function(x) { - return Math.log((1+x)/(1-x)) / 2; -}; +Math.atanh = + Math.atanh || + function (x) { + return Math.log((1 + x) / (1 - x)) / 2; + }; ``` ## Spécifications diff --git a/files/fr/web/javascript/reference/global_objects/math/cbrt/index.md b/files/fr/web/javascript/reference/global_objects/math/cbrt/index.md index f56f9787e4fde2..637c2f24b5a100 100644 --- a/files/fr/web/javascript/reference/global_objects/math/cbrt/index.md +++ b/files/fr/web/javascript/reference/global_objects/math/cbrt/index.md @@ -15,7 +15,7 @@ La fonction **`Math.cbrt()`** renvoie la racine cubique (le nom anglais étant _ ## Syntaxe ```js -Math.cbrt(x) +Math.cbrt(x); ``` ### Paramètres @@ -44,7 +44,7 @@ Math.cbrt(0); // 0 Math.cbrt(1); // 1 Math.cbrt(Infinity); // Infinity Math.cbrt(null); // 0 -Math.cbrt(2); // 1.2599210498948732 +Math.cbrt(2); // 1.2599210498948732 ``` ## Spécifications diff --git a/files/fr/web/javascript/reference/global_objects/math/ceil/index.md b/files/fr/web/javascript/reference/global_objects/math/ceil/index.md index 62a6ddb3e60f68..1c93b0d9588038 100644 --- a/files/fr/web/javascript/reference/global_objects/math/ceil/index.md +++ b/files/fr/web/javascript/reference/global_objects/math/ceil/index.md @@ -13,7 +13,7 @@ La fonction **`Math.ceil()`** retourne le plus petit entier supérieur ou égal ## Syntaxe ```js -Math.ceil(x) +Math.ceil(x); ``` ### Paramètres @@ -38,21 +38,20 @@ Le plus petit entier qui est supérieur ou égal au nombre donné. Voici un exemple d'utilisation de `Math.ceil()`. ```js -Math.ceil(.95); // 1 -Math.ceil(4); // 4 -Math.ceil(7.004); // 8 -Math.ceil(-0.95); // -0 -Math.ceil(-4); // -4 +Math.ceil(0.95); // 1 +Math.ceil(4); // 4 +Math.ceil(7.004); // 8 +Math.ceil(-0.95); // -0 +Math.ceil(-4); // -4 Math.ceil(-7.004); // -7 -Math.ceil(null); // 0 +Math.ceil(null); // 0 ``` ### Arrondi décimal ```js // Fermeture -(function(){ - +(function () { /** * Fonction pour arrondir un nombre. * @@ -63,43 +62,42 @@ Math.ceil(null); // 0 */ function decimalAdjust(type, value, exp) { // Si l'exposant vaut undefined ou zero... - if (typeof exp === 'undefined' || +exp === 0) { + if (typeof exp === "undefined" || +exp === 0) { return Math[type](value); } value = +value; exp = +exp; // Si value n'est pas un nombre - // ou si l'exposant n'est pas entier - if (isNaN(value) || !(typeof exp === 'number' && exp % 1 === 0)) { + // ou si l'exposant n'est pas entier + if (isNaN(value) || !(typeof exp === "number" && exp % 1 === 0)) { return NaN; } // Décalage - value = value.toString().split('e'); - value = Math[type](+(value[0] + 'e' + (value[1] ? (+value[1] - exp) : -exp))); + value = value.toString().split("e"); + value = Math[type](+(value[0] + "e" + (value[1] ? +value[1] - exp : -exp))); // Re "calage" - value = value.toString().split('e'); - return +(value[0] + 'e' + (value[1] ? (+value[1] + exp) : exp)); + value = value.toString().split("e"); + return +(value[0] + "e" + (value[1] ? +value[1] + exp : exp)); } // Arrondi décimal if (!Math.round10) { - Math.round10 = function(value, exp) { - return decimalAdjust('round', value, exp); + Math.round10 = function (value, exp) { + return decimalAdjust("round", value, exp); }; } // Arrondi décimal inférieur if (!Math.floor10) { - Math.floor10 = function(value, exp) { - return decimalAdjust('floor', value, exp); + Math.floor10 = function (value, exp) { + return decimalAdjust("floor", value, exp); }; } // Arrondi décimal supérieur if (!Math.ceil10) { - Math.ceil10 = function(value, exp) { - return decimalAdjust('ceil', value, exp); + Math.ceil10 = function (value, exp) { + return decimalAdjust("ceil", value, exp); }; } - })(); // Arrondi décimal diff --git a/files/fr/web/javascript/reference/global_objects/math/clz32/index.md b/files/fr/web/javascript/reference/global_objects/math/clz32/index.md index fb6a61eac3bd62..ed35eb1f29a894 100644 --- a/files/fr/web/javascript/reference/global_objects/math/clz32/index.md +++ b/files/fr/web/javascript/reference/global_objects/math/clz32/index.md @@ -13,7 +13,7 @@ La fonction **`Math.clz32()`** renvoie le nombre de zéros de tête dans la repr ## Syntaxe ```js -Math.clz32(x) +Math.clz32(x); ``` ### Paramètres @@ -38,15 +38,26 @@ Cette fonction est particulièrement utile aux systèmes qui compilent du code J ## Exemples ```js -Math.clz32(1) // 31 -Math.clz32(1000) // 22 -Math.clz32() // 32 - -var liste = [NaN, Infinity, -Infinity, 0, -0, null, undefined, 'machin', {}, []]; -liste.every(n => Math.clz32(n) == 32); // true - -Math.clz32(true) // 31 -Math.clz32(3.5) // 30 +Math.clz32(1); // 31 +Math.clz32(1000); // 22 +Math.clz32(); // 32 + +var liste = [ + NaN, + Infinity, + -Infinity, + 0, + -0, + null, + undefined, + "machin", + {}, + [], +]; +liste.every((n) => Math.clz32(n) == 32); // true + +Math.clz32(true); // 31 +Math.clz32(3.5); // 30 ``` ## Spécifications diff --git a/files/fr/web/javascript/reference/global_objects/math/cos/index.md b/files/fr/web/javascript/reference/global_objects/math/cos/index.md index b8830c10551967..9cc5ef7dbfc965 100644 --- a/files/fr/web/javascript/reference/global_objects/math/cos/index.md +++ b/files/fr/web/javascript/reference/global_objects/math/cos/index.md @@ -13,7 +13,7 @@ La fonction **`Math.cos()`** retourne le [cosinus](https://fr.wikipedia.org/wiki ## Syntaxe ```js -Math.cos(x) +Math.cos(x); ``` ### Paramètres @@ -36,10 +36,10 @@ La méthode `Math.cos()` renvoie une valeur numérique comprise entre -1 et 1. C ### Utiliser `Math.cos()` ```js -Math.cos(0); // 1 -Math.cos(1); // 0.5403023058681398 +Math.cos(0); // 1 +Math.cos(1); // 0.5403023058681398 -Math.cos(Math.PI); // -1 +Math.cos(Math.PI); // -1 Math.cos(2 * Math.PI); // 1 ``` diff --git a/files/fr/web/javascript/reference/global_objects/math/cosh/index.md b/files/fr/web/javascript/reference/global_objects/math/cosh/index.md index c14173983e86c4..ab76487284a04c 100644 --- a/files/fr/web/javascript/reference/global_objects/math/cosh/index.md +++ b/files/fr/web/javascript/reference/global_objects/math/cosh/index.md @@ -17,7 +17,7 @@ La fonction **`Math.cosh()`** renvoie le cosinus hyperbolique d'un nombre, défi ## Syntaxe ```js -Math.cosh(x) +Math.cosh(x); ``` ### Paramètres @@ -38,8 +38,8 @@ Le cosinus hyperbolique du nombre passé en argument. ### Utiliser `Math.cosh()` ```js -Math.cosh(0); // 1 -Math.cosh(1); // 1.5430806348152437 +Math.cosh(0); // 1 +Math.cosh(1); // 1.5430806348152437 Math.cosh(-1); // 1.5430806348152437 ``` @@ -48,18 +48,22 @@ Math.cosh(-1); // 1.5430806348152437 Cette fonction peut être émulée grâce à la fonction {{jsxref("Objets_globaux/Math/exp", "Math.exp()")}} : ```js -Math.cosh = Math.cosh || function(x) { +Math.cosh = + Math.cosh || + function (x) { return (Math.exp(x) + Math.exp(-x)) / 2; -} + }; ``` On peut également utiliser un unique appel à {{jsxref("Objets_globaux/Math/exp", "exp()")}} : ```js -Math.cosh = Math.cosh || function(x) { +Math.cosh = + Math.cosh || + function (x) { var y = Math.exp(x); return (y + 1 / y) / 2; -} + }; ``` ## Spécifications diff --git a/files/fr/web/javascript/reference/global_objects/math/e/index.md b/files/fr/web/javascript/reference/global_objects/math/e/index.md index 2975b0bc705612..8c7d949d57972a 100644 --- a/files/fr/web/javascript/reference/global_objects/math/e/index.md +++ b/files/fr/web/javascript/reference/global_objects/math/e/index.md @@ -24,7 +24,7 @@ La fonction suivante renvoie la valeur de e : ```js function getNapier() { - return Math.E; + return Math.E; } getNapier(); // 2.718281828459045 diff --git a/files/fr/web/javascript/reference/global_objects/math/exp/index.md b/files/fr/web/javascript/reference/global_objects/math/exp/index.md index 458acc71925903..8305233908f14c 100644 --- a/files/fr/web/javascript/reference/global_objects/math/exp/index.md +++ b/files/fr/web/javascript/reference/global_objects/math/exp/index.md @@ -13,7 +13,7 @@ La fonction **`Math.exp()`** renvoie l'exponentielle d'un nombre (donnée par `e ## Syntaxe ```js -Math.exp(x) +Math.exp(x); ``` ### Paramètres @@ -35,8 +35,8 @@ L'exponentielle du nombre passé en argument (`e^x`). ```js Math.exp(-1); // 0.36787944117144233 -Math.exp(0); // 1 -Math.exp(1); // 2.718281828459045 +Math.exp(0); // 1 +Math.exp(1); // 2.718281828459045 ``` ## Spécifications diff --git a/files/fr/web/javascript/reference/global_objects/math/expm1/index.md b/files/fr/web/javascript/reference/global_objects/math/expm1/index.md index c062a6bef3ab8a..f596049e0573c2 100644 --- a/files/fr/web/javascript/reference/global_objects/math/expm1/index.md +++ b/files/fr/web/javascript/reference/global_objects/math/expm1/index.md @@ -13,7 +13,7 @@ La fonction **`Math.expm1()`** renvoie `e^x` - 1, avec `x` l'argument donné et ## Syntaxe ```js -Math.expm1(x) +Math.expm1(x); ``` ### Paramètres @@ -35,8 +35,8 @@ Un nombre qui représente `e^x- 1` où `x` est la valeur passée en argument et ```js Math.expm1(-1); // -0.6321205588285577 -Math.expm1(0); // 0 -Math.expm1(1); // 1.718281828459045 +Math.expm1(0); // 0 +Math.expm1(1); // 1.718281828459045 ``` ## Prothèse d'émulation (_polyfill_) @@ -44,9 +44,11 @@ Math.expm1(1); // 1.718281828459045 Cette fonction peut être émulée en utilisant la fonction {{jsxref("Objets_globaux/Math/exp", "Math.exp()")}} : ```js -Math.expm1 = Math.expm1 || function(x) { +Math.expm1 = + Math.expm1 || + function (x) { return Math.exp(x) - 1; -}; + }; ``` ## Spécifications diff --git a/files/fr/web/javascript/reference/global_objects/math/floor/index.md b/files/fr/web/javascript/reference/global_objects/math/floor/index.md index 2cacbfeda44289..b2626071528007 100644 --- a/files/fr/web/javascript/reference/global_objects/math/floor/index.md +++ b/files/fr/web/javascript/reference/global_objects/math/floor/index.md @@ -13,7 +13,7 @@ La fonction **`Math.floor(x)`** renvoie le plus grand entier qui est inférieur ## Syntaxe ```js -Math.floor(x) +Math.floor(x); ``` ### Paramètres @@ -36,12 +36,12 @@ Un nombre qui représente le plus grand entier inférieur ou égal à la valeur ### Utiliser `Math.floor` ```js -Math.floor( 45.95); // 45 -Math.floor( 45.05); // 45 -Math.floor( 4 ); // 4 +Math.floor(45.95); // 45 +Math.floor(45.05); // 45 +Math.floor(4); // 4 Math.floor(-45.05); // -46 Math.floor(-45.95); // -46 -Math.floor(null); // 0 +Math.floor(null); // 0 ``` ## Spécifications diff --git a/files/fr/web/javascript/reference/global_objects/math/fround/index.md b/files/fr/web/javascript/reference/global_objects/math/fround/index.md index 5b6bbab94e7d40..107ca7b54c4794 100644 --- a/files/fr/web/javascript/reference/global_objects/math/fround/index.md +++ b/files/fr/web/javascript/reference/global_objects/math/fround/index.md @@ -13,7 +13,7 @@ La fonction **`Math.fround()`** renvoie le nombre flottant à [précision simple ## Syntaxe ```js -Math.fround(x) +Math.fround(x); ``` ### Paramètres @@ -38,15 +38,15 @@ Pour résoudre ce problème, on peut utiliser `Math.fround()` afin de transforme ### Utiliser `Math.fround()` ```js -Math.fround(0); // 0 -Math.fround(1); // 1 +Math.fround(0); // 0 +Math.fround(1); // 1 // 1.337 ne peut pas être représenté correctement // sur 32 bits Math.fround(1.337); // 1.3370000123977661 -Math.fround(1.5); // 1.5 -Math.fround(NaN); // NaN +Math.fround(1.5); // 1.5 +Math.fround(NaN); // NaN ``` ## Spécifications diff --git a/files/fr/web/javascript/reference/global_objects/math/hypot/index.md b/files/fr/web/javascript/reference/global_objects/math/hypot/index.md index 6f44f2864e2374..811fb8cf14b47e 100644 --- a/files/fr/web/javascript/reference/global_objects/math/hypot/index.md +++ b/files/fr/web/javascript/reference/global_objects/math/hypot/index.md @@ -40,13 +40,13 @@ Cette fonction permet entre autres de gérer certains cas où, pour les grands n ### Utiliser `Math.hypot()` ```js -Math.hypot(3, 4) // 5 -Math.hypot(3, 4, 5) // 7.0710678118654755 -Math.hypot() // 0 -Math.hypot(NaN) // NaN -Math.hypot(3, 4, "toto") // NaN, +"toto" => NaN -Math.hypot(3, 4, "5") // 7.0710678118654755, +"5" => 5 -Math.hypot(-3) // 3, the same as Math.abs(-3) +Math.hypot(3, 4); // 5 +Math.hypot(3, 4, 5); // 7.0710678118654755 +Math.hypot(); // 0 +Math.hypot(NaN); // NaN +Math.hypot(3, 4, "toto"); // NaN, +"toto" => NaN +Math.hypot(3, 4, "5"); // 7.0710678118654755, +"5" => 5 +Math.hypot(-3); // 3, the same as Math.abs(-3) ``` ## Prothèse d'émulation (_polyfill_) @@ -54,18 +54,20 @@ Math.hypot(-3) // 3, the same as Math.abs(-3) Si elle n'est pas disponible, cette fonction peut être émulée de la façon suivante : ```js -Math.hypot = Math.hypot || function() { +Math.hypot = + Math.hypot || + function () { var y = 0; var length = arguments.length; for (var i = 0; i < length; i++) { - if(arguments[i] === Infinity || arguments[i] === -Infinity) { + if (arguments[i] === Infinity || arguments[i] === -Infinity) { return Infinity; } y += arguments[i] * arguments[i]; } return Math.sqrt(y); -}; + }; ``` Voici une seconde version qui évite les dépassements : diff --git a/files/fr/web/javascript/reference/global_objects/math/imul/index.md b/files/fr/web/javascript/reference/global_objects/math/imul/index.md index bda445db123742..269ac7ead79558 100644 --- a/files/fr/web/javascript/reference/global_objects/math/imul/index.md +++ b/files/fr/web/javascript/reference/global_objects/math/imul/index.md @@ -13,7 +13,7 @@ La fonction **`Math.imul()`** renvoie le résultat de la multiplication de deux ## Syntaxe ```js -Math.imul(a, b) +Math.imul(a, b); ``` ### Paramètres @@ -36,9 +36,9 @@ Le résultat de la multiplication sur 32 bits des valeurs passées en argument ( ### Utiliser `Math.imul()` ```js -Math.imul(2, 4); // 8 -Math.imul(-1, 8); //-8 -Math.imul(-2, -2); // 4 +Math.imul(2, 4); // 8 +Math.imul(-1, 8); //-8 +Math.imul(-2, -2); // 4 Math.imul(0xffffffff, 5); //-5 Math.imul(0xfffffffe, 5); //-10 ``` @@ -48,15 +48,17 @@ Math.imul(0xfffffffe, 5); //-10 Si elle n'est pas disponible, cette fonction peut être émulée de la façon suivante : ```js -Math.imul = Math.imul || function(a, b) { - var ah = (a >>> 16) & 0xffff; - var al = a & 0xffff; - var bh = (b >>> 16) & 0xffff; - var bl = b & 0xffff; - // Le décalage par 0 rétablit le signe de la partie haute - // le |0 final convertit la valeur non-signée en une valeur signée - return ((al * bl) + (((ah * bl + al * bh) << 16) >>> 0)|0); -}; +Math.imul = + Math.imul || + function (a, b) { + var ah = (a >>> 16) & 0xffff; + var al = a & 0xffff; + var bh = (b >>> 16) & 0xffff; + var bl = b & 0xffff; + // Le décalage par 0 rétablit le signe de la partie haute + // le |0 final convertit la valeur non-signée en une valeur signée + return (al * bl + (((ah * bl + al * bh) << 16) >>> 0)) | 0; + }; ``` ## Spécifications diff --git a/files/fr/web/javascript/reference/global_objects/math/ln10/index.md b/files/fr/web/javascript/reference/global_objects/math/ln10/index.md index 33181d830020fc..e9f71bfd48e6bc 100644 --- a/files/fr/web/javascript/reference/global_objects/math/ln10/index.md +++ b/files/fr/web/javascript/reference/global_objects/math/ln10/index.md @@ -24,7 +24,7 @@ La fonction suivante renvoie le logarithme naturel de 10 : ```js function getNatLog10() { - return Math.LN10; + return Math.LN10; } getNatLog10(); // 2.302585092994046 diff --git a/files/fr/web/javascript/reference/global_objects/math/log/index.md b/files/fr/web/javascript/reference/global_objects/math/log/index.md index 9d05dc5f67f088..dc7163d21d50ee 100644 --- a/files/fr/web/javascript/reference/global_objects/math/log/index.md +++ b/files/fr/web/javascript/reference/global_objects/math/log/index.md @@ -15,7 +15,7 @@ La fonction **`Math.log()`** renvoie le logarithme naturel (aussi appelé logari ## Syntaxe ```js -Math.log(x) +Math.log(x); ``` ### Paramètres @@ -39,8 +39,8 @@ Si la valeur de l'argument est négative, la valeur renvoyée sera {{jsxref("NaN ```js Math.log(-1); // NaN, valeur en dehors de l'intervalle de définition -Math.log(0); // -Infinity -Math.log(1); // 0 +Math.log(0); // -Infinity +Math.log(1); // 0 Math.log(10); // 2.302585092994046 ``` @@ -50,7 +50,7 @@ La fonction suivante renvoie le logarithme de `y` en base `x` (c'est-à-dire log ```js function getBaseLog(x, y) { - return Math.log(y) / Math.log(x); + return Math.log(y) / Math.log(x); } ```