From 95aca4b4d8fa62815d4bd412fff1a364f842814a Mon Sep 17 00:00:00 2001 From: Ryan Johnson Date: Thu, 29 Apr 2021 16:16:42 -0700 Subject: remove retired locales (#699) --- .../global_objects/string/codepointat/index.html | 142 --------------------- 1 file changed, 142 deletions(-) delete mode 100644 files/uk/web/javascript/reference/global_objects/string/codepointat/index.html (limited to 'files/uk/web/javascript/reference/global_objects/string/codepointat') diff --git a/files/uk/web/javascript/reference/global_objects/string/codepointat/index.html b/files/uk/web/javascript/reference/global_objects/string/codepointat/index.html deleted file mode 100644 index 0a917f5885..0000000000 --- a/files/uk/web/javascript/reference/global_objects/string/codepointat/index.html +++ /dev/null @@ -1,142 +0,0 @@ ---- -title: String.prototype.codePointAt() -slug: Web/JavaScript/Reference/Global_Objects/String/codePointAt -tags: - - ECMAScript 2015 - - JavaScript - - String - - метод -translation_of: Web/JavaScript/Reference/Global_Objects/String/codePointAt ---- -
{{JSRef}}
- -

Метод codePointAt() вертає невід'ємне ціле число, яке є значенням коду символу Юнікоду.

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

Синтаксис

- -
str.codePointAt(pos)
- -

Параметри

- -
-
pos
-
Позиція елемента у str, код символа з якої треба повернути.
-
- -

Значення, що повертається

- -

Число, що відображає значення коду символу з наданої позиції pos. Якщо на позиції pos немає елемента, вертається {{jsxref("undefined")}}.

- -

Опис

- -

Якщо на вказаній позиції немає елемента, повертається {{jsxref("undefined")}}. Якщо на позиції pos не починається сурогатна пара UTF-16, то повертається кодова одиниця позиції pos.

- -

Приклади

- -

Використання codePointAt()

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

Цикл з codePointAt()

- -
for (let codePoint of '\ud83d\udc0e\ud83d\udc71\u2764') {
-   console.log(codePoint.codePointAt(0).toString(16))
-}
-// '1f40e', '1f471', '2764' 
-
- -

Поліфіл

- -

Наступний код додає у рядки функцію codePointAt() згідно специфікації ECMAScript 2015 для переглядачів без вбудованої підтримки.

- -
/*! https://mths.be/codepointat v0.2.0 автор @mathias */
-if (!String.prototype.codePointAt) {
-  (function() {
-    'use strict'; // необхідно для підтримки `apply`/`call` з `undefined`/`null`
-    var defineProperty = (function() {
-     // IE 8 підтримує `Object.defineProperty` лише на DOM-елементах
-      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) { // краще `isNaN`
-        index = 0;
-      }
-      // Врахування індексів за межами існуючих значень:
-      if (index < 0 || index >= size) {
-        return undefined;
-      }
-      // Отримати першу кодову одиницю
-      var first = string.charCodeAt(index);
-      var second;
-      if ( // перевірити, чи вона є початком сурогатної пари
-        first >= 0xD800 && first <= 0xDBFF && // високий сурогат
-        size > index + 1 // існує наступна кодова одиниця
-      ) {
-        second = string.charCodeAt(index + 1);
-        if (second >= 0xDC00 && second <= 0xDFFF) { // низький сурогат
-          // 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;
-    }
-  }());
-}
-
- -

Специфікації

- - - - - - - - - - -
Специфікація
{{SpecName('ESDraft', '#sec-string.prototype.codepointat', 'String.prototype.codePointAt')}}
- -

Сумісність з веб-переглядачами

- - - -

{{Compat("javascript.builtins.String.codePointAt")}}

- -

Див. також

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