diff options
author | julieng <julien.gattelier@gmail.com> | 2021-08-03 08:03:23 +0200 |
---|---|---|
committer | SphinxKnight <SphinxKnight@users.noreply.github.com> | 2021-09-03 08:08:25 +0200 |
commit | bf8e099b9c8b3c60d60b3712b4fc97b052c39887 (patch) | |
tree | c101746d082c9581c94f5937519c7d0e2f4af8cb /files/fr/web/javascript/reference/global_objects/string/codepointat | |
parent | 844f5103992238c0c23203286dad16a466e89c97 (diff) | |
download | translated-content-bf8e099b9c8b3c60d60b3712b4fc97b052c39887.tar.gz translated-content-bf8e099b9c8b3c60d60b3712b4fc97b052c39887.tar.bz2 translated-content-bf8e099b9c8b3c60d60b3712b4fc97b052c39887.zip |
convert content to md
Diffstat (limited to 'files/fr/web/javascript/reference/global_objects/string/codepointat')
-rw-r--r-- | files/fr/web/javascript/reference/global_objects/string/codepointat/index.md | 105 |
1 files changed, 44 insertions, 61 deletions
diff --git a/files/fr/web/javascript/reference/global_objects/string/codepointat/index.md b/files/fr/web/javascript/reference/global_objects/string/codepointat/index.md index d461d2917d..8f6b9a9827 100644 --- a/files/fr/web/javascript/reference/global_objects/string/codepointat/index.md +++ b/files/fr/web/javascript/reference/global_objects/string/codepointat/index.md @@ -12,44 +12,44 @@ tags: translation_of: Web/JavaScript/Reference/Global_Objects/String/codePointAt original_slug: Web/JavaScript/Reference/Objets_globaux/String/codePointAt --- -<div>{{JSRef}}</div> +{{JSRef}} -<p>La méthode <code><strong>codePointAt()</strong></code> renvoie un entier positif qui correspond au code Unicode (<em>code point</em>) du caractère de la chaîne à la position donnée.</p> +La méthode **`codePointAt()`** renvoie un entier positif qui correspond au code Unicode (_code point_) du caractère de la chaîne à la position donnée. -<div>{{EmbedInteractiveExample("pages/js/string-codepointat.html")}}</div> +{{EmbedInteractiveExample("pages/js/string-codepointat.html")}} -<h2 id="Syntaxe">Syntaxe</h2> +## Syntaxe -<pre class="syntaxbox"><var>str</var>.codePointAt(<var>pos</var>)</pre> + str.codePointAt(pos) -<h3 id="Paramètres">Paramètres</h3> +### Paramètres -<dl> - <dt><code>pos</code></dt> - <dd>La position de l'élément dans la chaîne de caractères dont on souhaite obtenir la valeur du codet.</dd> -</dl> +- `pos` + - : La position de l'élément dans la chaîne de caractères dont on souhaite obtenir la valeur du codet. -<h3 id="Valeur_de_retour">Valeur de retour</h3> +### Valeur de retour -<p>Un nombre qui représente la valeur du point de code du caractère à la position indiqué. C'est la valeur {{jsxref("undefined")}} qui est renvoyée s'il n'y aucun élément à <code>pos</code>.</p> +Un nombre qui représente la valeur du point de code du caractère à la position indiqué. C'est la valeur {{jsxref("undefined")}} qui est renvoyée s'il n'y aucun élément à `pos`. -<h2 id="Description">Description</h2> +## Description -<p>S'il n'y a pas d'élément à la position donnée, la valeur renvoyée sera {{jsxref("undefined")}}. Si ce n'est pas un élément représenté sur deux demi-codets (<em>surrogate pair</em>) UTF-16 et qui commence à <code>pos</code>, le codet de l'élément à l'indice <code>pos</code> est renvoyé.</p> +S'il n'y a pas d'élément à la position donnée, la valeur renvoyée sera {{jsxref("undefined")}}. Si ce n'est pas un élément représenté sur deux demi-codets (_surrogate pair_) UTF-16 et qui commence à `pos`, le codet de l'élément à l'indice `pos` est renvoyé. -<h2 id="Exemples">Exemples</h2> +## Exemples -<pre class="brush: js">'ABC'.codePointAt(1); // 66 +```js +'ABC'.codePointAt(1); // 66 '\uD800\uDC00'.codePointAt(0); // 65536 'XYZ'.codePointAt(42); // undefined -</pre> +``` -<h2 id="Prothèse_d'émulation_(polyfill)">Prothèse d'émulation (<em>polyfill</em>)</h2> +## Prothèse d'émulation (_polyfill_) -<p>Le fragment de code suivant permet d'ajouter la méthode <code>codePointAt()</code> pour les chaînes de caractères (<code>String</code>). En effet, cette méthode fait partie de ECMAScript 2015 et certains navigateurs peuvent ne pas proposer cette fonction nativement.</p> +Le fragment de code suivant permet d'ajouter la méthode `codePointAt()` pour les chaînes de caractères (`String`). En effet, cette méthode fait partie de ECMAScript 2015 et certains navigateurs peuvent ne pas proposer cette fonction nativement. -<pre class="brush:js">/*! https://mths.be/codepointat v0.2.0 by @mathias */ +```js +/*! https://mths.be/codepointat v0.2.0 by @mathias */ if (!String.prototype.codePointAt) { (function() { 'use strict'; // needed to support `apply`/`call` with `undefined`/`null` @@ -58,7 +58,7 @@ if (!String.prototype.codePointAt) { try { var object = {}; var $defineProperty = Object.defineProperty; - var result = $defineProperty(object, object, object) && $defineProperty; + var result = $defineProperty(object, object, object) && $defineProperty; } catch(error) {} return result; }()); @@ -74,18 +74,18 @@ if (!String.prototype.codePointAt) { index = 0; } // Account for out-of-bounds indices: - if (index < 0 || index >= size) { + if (index < 0 || index >= size) { return undefined; } // Get the first code unit var first = string.charCodeAt(index); var second; if ( // check if it’s the start of a surrogate pair - first >= 0xD800 && first <= 0xDBFF && // high surrogate - size > index + 1 // there is a next code unit + first >= 0xD800 && first <= 0xDBFF && // high surrogate + size > index + 1 // there is a next code unit ) { second = string.charCodeAt(index + 1); - if (second >= 0xDC00 && second <= 0xDFFF) { // low surrogate + if (second >= 0xDC00 && second <= 0xDFFF) { // low surrogate // https://mathiasbynens.be/notes/javascript-encoding#surrogate-formulae return (first - 0xD800) * 0x400 + second - 0xDC00 + 0x10000; } @@ -103,39 +103,22 @@ if (!String.prototype.codePointAt) { } }()); } -</pre> - -<h2 id="Spécifications">Spécifications</h2> - -<table class="standard-table"> - <tbody> - <tr> - <th scope="col">Spécification</th> - <th scope="col">État</th> - <th scope="col">Commentaires</th> - </tr> - <tr> - <td>{{SpecName('ES2015', '#sec-string.prototype.codepointat', 'String.prototype.codePointAt')}}</td> - <td>{{Spec2('ES2015')}}</td> - <td>Définition initiale.</td> - </tr> - <tr> - <td>{{SpecName('ESDraft', '#sec-string.prototype.codepointat', 'String.prototype.codePointAt')}}</td> - <td>{{Spec2('ESDraft')}}</td> - <td> </td> - </tr> - </tbody> -</table> - -<h2 id="Compatibilité_des_navigateurs">Compatibilité des navigateurs</h2> - -<p>{{Compat("javascript.builtins.String.codePointAt")}}</p> - -<h2 id="Voir_aussi">Voir aussi</h2> - -<ul> - <li>{{jsxref("String.fromCodePoint()")}}</li> - <li>{{jsxref("String.fromCharCode()")}}</li> - <li>{{jsxref("String.prototype.charCodeAt()")}}</li> - <li>{{jsxref("String.prototype.charAt()")}}</li> -</ul> +``` + +## Spécifications + +| Spécification | État | Commentaires | +| ---------------------------------------------------------------------------------------------------------------------------- | ---------------------------- | -------------------- | +| {{SpecName('ES2015', '#sec-string.prototype.codepointat', 'String.prototype.codePointAt')}} | {{Spec2('ES2015')}} | Définition initiale. | +| {{SpecName('ESDraft', '#sec-string.prototype.codepointat', 'String.prototype.codePointAt')}} | {{Spec2('ESDraft')}} | | + +## Compatibilité des navigateurs + +{{Compat("javascript.builtins.String.codePointAt")}} + +## Voir aussi + +- {{jsxref("String.fromCodePoint()")}} +- {{jsxref("String.fromCharCode()")}} +- {{jsxref("String.prototype.charCodeAt()")}} +- {{jsxref("String.prototype.charAt()")}} |