From 844f5103992238c0c23203286dad16a466e89c97 Mon Sep 17 00:00:00 2001 From: julieng Date: Tue, 3 Aug 2021 08:03:09 +0200 Subject: move *.html to *.md --- .../global_objects/string/codepointat/index.html | 141 --------------------- .../global_objects/string/codepointat/index.md | 141 +++++++++++++++++++++ 2 files changed, 141 insertions(+), 141 deletions(-) delete mode 100644 files/fr/web/javascript/reference/global_objects/string/codepointat/index.html create mode 100644 files/fr/web/javascript/reference/global_objects/string/codepointat/index.md (limited to 'files/fr/web/javascript/reference/global_objects/string/codepointat') diff --git a/files/fr/web/javascript/reference/global_objects/string/codepointat/index.html b/files/fr/web/javascript/reference/global_objects/string/codepointat/index.html deleted file mode 100644 index d461d2917d..0000000000 --- a/files/fr/web/javascript/reference/global_objects/string/codepointat/index.html +++ /dev/null @@ -1,141 +0,0 @@ ---- -title: String.prototype.codePointAt() -slug: Web/JavaScript/Reference/Global_Objects/String/codePointAt -tags: - - ECMAScript 2015 - - JavaScript - - Méthode - - Prototype - - Reference - - String - - polyfill -translation_of: Web/JavaScript/Reference/Global_Objects/String/codePointAt -original_slug: Web/JavaScript/Reference/Objets_globaux/String/codePointAt ---- -
{{JSRef}}
- -

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.

- -
{{EmbedInteractiveExample("pages/js/string-codepointat.html")}}
- -

Syntaxe

- -
str.codePointAt(pos)
- -

Paramètres

- -
-
pos
-
La position de l'élément dans la chaîne de caractères dont on souhaite obtenir la valeur du codet.
-
- -

Valeur de retour

- -

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.

- -

Description

- -

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é.

- -

Exemples

- -
'ABC'.codePointAt(1);          // 66
-'\uD800\uDC00'.codePointAt(0); // 65536
-
-'XYZ'.codePointAt(42); // undefined
-
- -

Prothèse d'émulation (polyfill)

- -

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.

- -
/*! https://mths.be/codepointat v0.2.0 by @mathias */
-if (!String.prototype.codePointAt) {
-  (function() {
-    'use strict'; // needed to support `apply`/`call` with `undefined`/`null`
-    var defineProperty = (function() {
-      // IE 8 only supports `Object.defineProperty` on DOM elements
-      try {
-        var object = {};
-        var $defineProperty = Object.defineProperty;
-        var result = $defineProperty(object, object, object) && $defineProperty;
-      } catch(error) {}
-      return result;
-    }());
-    var codePointAt = function(position) {
-      if (this == null) {
-        throw TypeError();
-      }
-      var string = String(this);
-      var size = string.length;
-      // `ToInteger`
-      var index = position ? Number(position) : 0;
-      if (index != index) { // better `isNaN`
-        index = 0;
-      }
-      // Account for out-of-bounds indices:
-      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
-      ) {
-        second = string.charCodeAt(index + 1);
-        if (second >= 0xDC00 && second <= 0xDFFF) { // low surrogate
-          // https://mathiasbynens.be/notes/javascript-encoding#surrogate-formulae
-          return (first - 0xD800) * 0x400 + second - 0xDC00 + 0x10000;
-        }
-      }
-      return first;
-    };
-    if (defineProperty) {
-      defineProperty(String.prototype, 'codePointAt', {
-        'value': codePointAt,
-        'configurable': true,
-        'writable': true
-      });
-    } else {
-      String.prototype.codePointAt = codePointAt;
-    }
-  }());
-}
-
- -

Spécifications

- - - - - - - - - - - - - - - - - - - -
SpécificationÉtatCommentaires
{{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

- - 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 new file mode 100644 index 0000000000..d461d2917d --- /dev/null +++ b/files/fr/web/javascript/reference/global_objects/string/codepointat/index.md @@ -0,0 +1,141 @@ +--- +title: String.prototype.codePointAt() +slug: Web/JavaScript/Reference/Global_Objects/String/codePointAt +tags: + - ECMAScript 2015 + - JavaScript + - Méthode + - Prototype + - Reference + - String + - polyfill +translation_of: Web/JavaScript/Reference/Global_Objects/String/codePointAt +original_slug: Web/JavaScript/Reference/Objets_globaux/String/codePointAt +--- +
{{JSRef}}
+ +

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.

+ +
{{EmbedInteractiveExample("pages/js/string-codepointat.html")}}
+ +

Syntaxe

+ +
str.codePointAt(pos)
+ +

Paramètres

+ +
+
pos
+
La position de l'élément dans la chaîne de caractères dont on souhaite obtenir la valeur du codet.
+
+ +

Valeur de retour

+ +

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.

+ +

Description

+ +

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é.

+ +

Exemples

+ +
'ABC'.codePointAt(1);          // 66
+'\uD800\uDC00'.codePointAt(0); // 65536
+
+'XYZ'.codePointAt(42); // undefined
+
+ +

Prothèse d'émulation (polyfill)

+ +

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.

+ +
/*! https://mths.be/codepointat v0.2.0 by @mathias */
+if (!String.prototype.codePointAt) {
+  (function() {
+    'use strict'; // needed to support `apply`/`call` with `undefined`/`null`
+    var defineProperty = (function() {
+      // IE 8 only supports `Object.defineProperty` on DOM elements
+      try {
+        var object = {};
+        var $defineProperty = Object.defineProperty;
+        var result = $defineProperty(object, object, object) && $defineProperty;
+      } catch(error) {}
+      return result;
+    }());
+    var codePointAt = function(position) {
+      if (this == null) {
+        throw TypeError();
+      }
+      var string = String(this);
+      var size = string.length;
+      // `ToInteger`
+      var index = position ? Number(position) : 0;
+      if (index != index) { // better `isNaN`
+        index = 0;
+      }
+      // Account for out-of-bounds indices:
+      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
+      ) {
+        second = string.charCodeAt(index + 1);
+        if (second >= 0xDC00 && second <= 0xDFFF) { // low surrogate
+          // https://mathiasbynens.be/notes/javascript-encoding#surrogate-formulae
+          return (first - 0xD800) * 0x400 + second - 0xDC00 + 0x10000;
+        }
+      }
+      return first;
+    };
+    if (defineProperty) {
+      defineProperty(String.prototype, 'codePointAt', {
+        'value': codePointAt,
+        'configurable': true,
+        'writable': true
+      });
+    } else {
+      String.prototype.codePointAt = codePointAt;
+    }
+  }());
+}
+
+ +

Spécifications

+ + + + + + + + + + + + + + + + + + + +
SpécificationÉtatCommentaires
{{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

+ + -- cgit v1.2.3-54-g00ecf