Last change
on this file since 1ad8e64 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago |
initial commit
|
-
Property mode
set to
100644
|
File size:
1.2 KB
|
Line | |
---|
1 | var toInteger = require('../internals/to-integer');
|
---|
2 | var toString = require('../internals/to-string');
|
---|
3 | var requireObjectCoercible = require('../internals/require-object-coercible');
|
---|
4 |
|
---|
5 | // `String.prototype.codePointAt` methods implementation
|
---|
6 | var createMethod = function (CONVERT_TO_STRING) {
|
---|
7 | return function ($this, pos) {
|
---|
8 | var S = toString(requireObjectCoercible($this));
|
---|
9 | var position = toInteger(pos);
|
---|
10 | var size = S.length;
|
---|
11 | var first, second;
|
---|
12 | if (position < 0 || position >= size) return CONVERT_TO_STRING ? '' : undefined;
|
---|
13 | first = S.charCodeAt(position);
|
---|
14 | return first < 0xD800 || first > 0xDBFF || position + 1 === size
|
---|
15 | || (second = S.charCodeAt(position + 1)) < 0xDC00 || second > 0xDFFF
|
---|
16 | ? CONVERT_TO_STRING ? S.charAt(position) : first
|
---|
17 | : CONVERT_TO_STRING ? S.slice(position, position + 2) : (first - 0xD800 << 10) + (second - 0xDC00) + 0x10000;
|
---|
18 | };
|
---|
19 | };
|
---|
20 |
|
---|
21 | module.exports = {
|
---|
22 | // `String.prototype.codePointAt` method
|
---|
23 | // https://tc39.es/ecma262/#sec-string.prototype.codepointat
|
---|
24 | codeAt: createMethod(false),
|
---|
25 | // `String.prototype.at` method
|
---|
26 | // https://github.com/mathiasbynens/String.prototype.at
|
---|
27 | charAt: createMethod(true)
|
---|
28 | };
|
---|
Note:
See
TracBrowser
for help on using the repository browser.