diff options
author | Florian Dieminger <me@fiji-flo.de> | 2021-02-11 18:20:58 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-02-11 18:20:58 +0100 |
commit | 2318b37e3fd17a3e76a29b9be7d1ce82f040c3bb (patch) | |
tree | 5e640d40fd69dc380b04e01de981a345e0141ffa /files/es/web/javascript/reference/global_objects/string/codepointat/index.html | |
parent | 6aa6274d2ad3e22e7f5e69b1d7531a5eaeaf5666 (diff) | |
parent | 8a5554c6fae83e92b10c8dbe5b82108cb44fad6c (diff) | |
download | translated-content-2318b37e3fd17a3e76a29b9be7d1ce82f040c3bb.tar.gz translated-content-2318b37e3fd17a3e76a29b9be7d1ce82f040c3bb.tar.bz2 translated-content-2318b37e3fd17a3e76a29b9be7d1ce82f040c3bb.zip |
Merge pull request #53 from fiji-flo/unslugging-es
Unslugging es
Diffstat (limited to 'files/es/web/javascript/reference/global_objects/string/codepointat/index.html')
-rw-r--r-- | files/es/web/javascript/reference/global_objects/string/codepointat/index.html | 128 |
1 files changed, 128 insertions, 0 deletions
diff --git a/files/es/web/javascript/reference/global_objects/string/codepointat/index.html b/files/es/web/javascript/reference/global_objects/string/codepointat/index.html new file mode 100644 index 0000000000..fabd85a657 --- /dev/null +++ b/files/es/web/javascript/reference/global_objects/string/codepointat/index.html @@ -0,0 +1,128 @@ +--- +title: String.prototype.codePointAt() +slug: Web/JavaScript/Reference/Global_Objects/String/codePointAt +translation_of: Web/JavaScript/Reference/Global_Objects/String/codePointAt +original_slug: Web/JavaScript/Referencia/Objetos_globales/String/codePointAt +--- +<div>{{JSRef}}</div> + +<div> </div> + +<div>El método <strong><code>codePointAt() </code></strong><code>d</code>evuelve un entero no negativo que equivale al valor Unicode code point del carácter.</div> + +<h2 id="Sintaxis">Sintaxis</h2> + +<pre class="syntaxbox"><code><var>str</var>.codePointAt(<var>indice</var>)</code></pre> + +<h3 id="Parámetros">Parámetros</h3> + +<dl> + <dt><code>indice</code></dt> + <dd>Índice del carácter en la cadena del que se quiere obtener el valor del Unicode code point.</dd> +</dl> + +<h3 id="Valor_de_retorno">Valor de retorno</h3> + +<p>Un número que equivale al valor code point del carácter especificado en el índice de la cadena; devuelve {{jsxref("undefined")}} si no se encuentra carácter en la posición especifica.</p> + +<h2 id="Description">Description</h2> + +<p>If there is no element at the specified position, {{jsxref("undefined")}} is returned. If no UTF-16 surrogate pair begins at <code>pos</code>, the code unit at <code>pos</code> is returned.</p> + +<h2 id="Examples">Examples</h2> + +<h3 id="Using_codePointAt()">Using <code>codePointAt()</code></h3> + +<pre class="brush: js">'ABC'.codePointAt(1); // 66 +'\uD800\uDC00'.codePointAt(0); // 65536 + +'XYZ'.codePointAt(42); // undefined +</pre> + +<h2 id="Polyfill">Polyfill</h2> + +<p>The following extends Strings to include the <code>codePointAt()</code> function as specified in ECMAScript 2015 for browsers not supporting it natively.</p> + +<pre class="brush: js">/*! http://mths.be/codepointat v0.1.0 by @mathias */ +if (!String.prototype.codePointAt) { + (function() { + 'use strict'; // needed to support `apply`/`call` with `undefined`/`null` + 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 + // http://mathiasbynens.be/notes/javascript-encoding#surrogate-formulae + return (first - 0xD800) * 0x400 + second - 0xDC00 + 0x10000; + } + } + return first; + }; + if (Object.defineProperty) { + Object.defineProperty(String.prototype, 'codePointAt', { + 'value': codePointAt, + 'configurable': true, + 'writable': true + }); + } else { + String.prototype.codePointAt = codePointAt; + } + }()); +} +</pre> + +<h2 id="Specifications">Specifications</h2> + +<table class="standard-table"> + <tbody> + <tr> + <th scope="col">Specification</th> + <th scope="col">Status</th> + <th scope="col">Comment</th> + </tr> + <tr> + <td>{{SpecName('ES2015', '#sec-string.prototype.codepointat', 'String.prototype.codePointAt')}}</td> + <td>{{Spec2('ES2015')}}</td> + <td>Initial definition.</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="Browser_compatibility">Browser compatibility</h2> + +<p class="hidden">The compatibility table in this page is generated from structured data. If you'd like to contribute to the data, please check out <a href="https://github.com/mdn/browser-compat-data">https://github.com/mdn/browser-compat-data</a> and send us a pull request.</p> + +<p>{{Compat("javascript.builtins.String.codePointAt")}}</p> + +<h2 id="See_also">See also</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> |