You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Nov 19, 2020. It is now read-only.
Note: This proposal was not upstreamed into the ECMAScript specification! This repository is kept for historical purposes. Years later, in November 2020, a distinct proposal adds String.prototype.at with different semantics.
NOTE: Returns a single-element String containing the code point at element position pos in the String value resulting from converting the this object to a String. If there is no element at that position, the result is the empty String. The result is a String value, not a String object.
When the at method is called with one argument pos, the following steps are taken:
Let O be RequireObjectCoercible(this value).
Let S be ToString(O).
ReturnIfAbrupt(S).
Let position be ToInteger(pos).
ReturnIfAbrupt(position).
Let size be the number of elements in S.
If position < 0 or position ≥ size, return the empty String.
Let first be the code unit at index position in the String S.
Let cuFirst be the code unit value of the element at index 0 in the String first.
If cuFirst < 0xD800 or cuFirst > 0xDBFF or position + 1 = size, then return first.
Let cuSecond be the code unit value of the element at index position + 1 in the String S.
If cuSecond < 0xDC00 or cuSecond > 0xDFFF, then return first.
Let second be the code unit at index position + 1 in the string S.
Let cp be (first – 0xD800) × 0x400 + (second – 0xDC00) + 0x10000.
Return the elements of the UTF-16 Encoding (clause 6) of cp.
NOTE: The at function is intentionally generic; it does not require that its this value be a String object. Therefore it can be transferred to other kinds of objects for use as a method.
require('string.prototype.at');// On Windows and on Mac systems with default settings, case doesn’t matter,// which allows you to do this instead:require('String.prototype.at');