pax_global_header 0000666 0000000 0000000 00000000064 13661577303 0014525 g ustar 00root root 0000000 0000000 52 comment=15e01b62e9afcf36c9b945359872d3f6640bfc63
String.prototype.codePointAt-1.0.0/ 0000775 0000000 0000000 00000000000 13661577303 0017245 5 ustar 00root root 0000000 0000000 String.prototype.codePointAt-1.0.0/.editorconfig 0000664 0000000 0000000 00000000121 13661577303 0021714 0 ustar 00root root 0000000 0000000 root = true
[*]
indent_style = tab
end_of_line = lf
insert_final_newline = true
String.prototype.codePointAt-1.0.0/.gitattributes 0000664 0000000 0000000 00000000114 13661577303 0022134 0 ustar 00root root 0000000 0000000 # Automatically normalize line endings for all text-based files
* text=auto
String.prototype.codePointAt-1.0.0/.gitignore 0000664 0000000 0000000 00000000371 13661577303 0021236 0 ustar 00root root 0000000 0000000 # Coverage report
coverage
# Installed npm modules
node_modules
package-lock.json
# Folder view configuration files
.DS_Store
Desktop.ini
# Thumbnail cache files
._*
Thumbs.db
# Files that might appear on external disks
.Spotlight-V100
.Trashes
String.prototype.codePointAt-1.0.0/.npmrc 0000664 0000000 0000000 00000000023 13661577303 0020360 0 ustar 00root root 0000000 0000000 package-lock=false
String.prototype.codePointAt-1.0.0/.travis.yml 0000664 0000000 0000000 00000000175 13661577303 0021361 0 ustar 00root root 0000000 0000000 version: ~> 1.0
language: node_js
os:
- linux
import:
- ljharb/travis-ci:node/all.yml
- ljharb/travis-ci:node/pretest.yml
String.prototype.codePointAt-1.0.0/LICENSE-MIT.txt 0000664 0000000 0000000 00000002065 13661577303 0021522 0 ustar 00root root 0000000 0000000 Copyright Mathias Bynens
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
String.prototype.codePointAt-1.0.0/README.md 0000664 0000000 0000000 00000004336 13661577303 0020532 0 ustar 00root root 0000000 0000000 # ES6 `String.prototype.codePointAt` polyfill [](https://travis-ci.org/mathiasbynens/String.prototype.codePointAt)
A robust & optimized polyfill for [the `String.prototype.codePointAt` method in ECMAScript 6](http://people.mozilla.org/~jorendorff/es6-draft.html#sec-string.prototype.codepointat).
This package implements the [es-shim API](https://github.com/es-shims/api) interface. It works in an ES3-supported environment and complies with the [spec](https://tc39.es/ecma262/#sec-string.prototype.codepointat).
Other polyfills for `String.prototype.codePointAt` are available:
* by [Norbert Lindenberg](http://norbertlindenberg.com/) (fails some tests)
* by [Steven Levithan](http://stevenlevithan.com/) (fails some tests)
* by [Paul Miller](http://paulmillr.com/) (~~[fails some tests](https://github.com/paulmillr/es6-shim/issues/166)~~ passes all tests)
## Installation
Via [npm](http://npmjs.org/):
```bash
npm install string.prototype.codepointat
```
Then, in [Node.js](http://nodejs.org/):
```js
require('string.prototype.codepointat');
// On Windows and on Mac systems with default settings, case doesn’t matter,
// which allows you to do this instead:
require('String.prototype.codePointAt');
```
In a browser:
```html
```
> **NOTE**: It's recommended that you install this module using a package manager
> such as `npm`, because loading multiple polyfills from a CDN (such as `bundle.run`)
> will lead to duplicated code.
## Notes
[A polyfill + test suite for `String.fromCodePoint`](https://mths.be/fromcodepoint) is available, too.
## Author
| [](https://twitter.com/mathias "Follow @mathias on Twitter") |
|---|
| [Mathias Bynens](https://mathiasbynens.be/) |
## License
This polyfill is available under the [MIT](https://mths.be/mit) license.
String.prototype.codePointAt-1.0.0/auto.js 0000664 0000000 0000000 00000000114 13661577303 0020547 0 ustar 00root root 0000000 0000000 /*! https://mths.be/codepointat v1.0.0 by @mathias */
require('./shim')();
String.prototype.codePointAt-1.0.0/implementation.js 0000664 0000000 0000000 00000002242 13661577303 0022630 0 ustar 00root root 0000000 0000000 /*! https://mths.be/codepointat v1.0.0 by @mathias */
'use strict';
var callBound = require('es-abstract/helpers/callBound');
var RequireObjectCoercible = require('es-abstract/2019/RequireObjectCoercible');
var ToString = require('es-abstract/2019/ToString');
var ToInteger = require('es-abstract/2019/ToInteger');
var StringCharCodeAt = callBound('String.prototype.charCodeAt');
module.exports = function codePointAt(position) {
var O = RequireObjectCoercible(this);
var string = ToString(O);
var size = string.length;
var index = ToInteger(position);
// Account for out-of-bounds indices:
if (index < 0 || index >= size) {
return undefined;
}
// Get the first code unit
var first = StringCharCodeAt(string, 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 = StringCharCodeAt(string, 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;
};
String.prototype.codePointAt-1.0.0/index.js 0000664 0000000 0000000 00000000740 13661577303 0020713 0 ustar 00root root 0000000 0000000 /*! https://mths.be/codepointat v1.0.0 by @mathias */
'use strict';
var callBind = require('es-abstract/helpers/callBind');
var define = require('define-properties');
var implementation = require('./implementation');
var getPolyfill = require('./polyfill');
var shim = require('./shim');
var boundCodePointAt = callBind(getPolyfill());
define(boundCodePointAt, {
getPolyfill: getPolyfill,
implementation: implementation,
shim: shim
});
module.exports = boundCodePointAt;
String.prototype.codePointAt-1.0.0/package.json 0000664 0000000 0000000 00000002417 13661577303 0021537 0 ustar 00root root 0000000 0000000 {
"name": "string.prototype.codepointat",
"version": "1.0.0",
"description": "A robust & optimized `String.prototype.codePointAt` polyfill, based on the ECMAScript 6 specification.",
"homepage": "https://mths.be/codepointat",
"main": "index.js",
"exports": {
".": "./index.js",
"./auto": "./auto.js",
"./shim": "./shim.js",
"./getPolyfill": "./getPolyfill.js",
"./implementation": "./implementation.js",
"./package.json": "./package.json"
},
"keywords": [
"string",
"unicode",
"es6",
"ecmascript",
"polyfill"
],
"license": "MIT",
"author": {
"name": "Mathias Bynens",
"url": "https://mathiasbynens.be/"
},
"repository": {
"type": "git",
"url": "https://github.com/mathiasbynens/String.prototype.codePointAt.git"
},
"bugs": "https://github.com/mathiasbynens/String.prototype.codePointAt/issues",
"scripts": {
"pretest": "es-shim-api --bound",
"test": "npm run tests-only",
"tests-only": "tape 'tests/*.js'",
"cover": "istanbul cover --report html --verbose --dir coverage tape 'tests/*.js'"
},
"dependencies": {
"es-abstract": "^1.17.5"
},
"devDependencies": {
"@es-shims/api": "^2.1.2",
"define-properties": "^1.1.3",
"function-bind": "^1.1.1",
"functions-have-names": "^1.2.1",
"istanbul": "^0.4.5",
"tape": "^5.0.0"
}
}
String.prototype.codePointAt-1.0.0/polyfill.js 0000664 0000000 0000000 00000000336 13661577303 0021437 0 ustar 00root root 0000000 0000000 /*! https://mths.be/codepointat v1.0.0 by @mathias */
'use strict';
var implementation = require('./implementation');
module.exports = function getPolyfill() {
return String.prototype.codePointAt || implementation;
};
String.prototype.codePointAt-1.0.0/shim.js 0000664 0000000 0000000 00000000553 13661577303 0020546 0 ustar 00root root 0000000 0000000 /*! https://mths.be/codepointat v1.0.0 by @mathias */
'use strict';
var define = require('define-properties');
var getPolyfill = require('./polyfill');
module.exports = function shimCodePointAt() {
var polyfill = getPolyfill();
if (String.prototype.codePointAt !== polyfill) {
define(String.prototype, { codePointAt: polyfill });
}
return polyfill;
}
String.prototype.codePointAt-1.0.0/tests/ 0000775 0000000 0000000 00000000000 13661577303 0020407 5 ustar 00root root 0000000 0000000 String.prototype.codePointAt-1.0.0/tests/index.js 0000664 0000000 0000000 00000000301 13661577303 0022046 0 ustar 00root root 0000000 0000000 'use strict';
var codePointAt = require('../');
var test = require('tape');
var runTests = require('./tests');
test('as a function', function (t) {
runTests(codePointAt, t);
t.end();
});
String.prototype.codePointAt-1.0.0/tests/shimmed.js 0000664 0000000 0000000 00000001706 13661577303 0022377 0 ustar 00root root 0000000 0000000 'use strict';
var codePointAt = require('../');
codePointAt.shim();
var test = require('tape');
var defineProperties = require('define-properties');
var bind = require('function-bind');
var isEnumerable = Object.prototype.propertyIsEnumerable;
var functionsHaveNames = require('functions-have-names')();
var runTests = require('./tests');
test('shimmed', function (t) {
t.equal(String.prototype.codePointAt.length, 1, 'String#codePointAt has a length of 1');
t.test('Function name', { skip: !functionsHaveNames }, function (st) {
st.equal(String.prototype.codePointAt.name, 'codePointAt', 'String#codePointAt has name "codePointAt"');
st.end();
});
t.test('enumerability', { skip: !defineProperties.supportsDescriptors }, function (et) {
et.equal(false, isEnumerable.call(String.prototype, 'codePointAt'), 'String#codePointAt is not enumerable');
et.end();
});
runTests(bind.call(Function.call, String.prototype.codePointAt), t);
t.end();
});
String.prototype.codePointAt-1.0.0/tests/tests.js 0000664 0000000 0000000 00000010157 13661577303 0022113 0 ustar 00root root 0000000 0000000 'use strict';
module.exports = function (codePointAt, t) {
t.test('String that starts with a BMP symbol', function (st) {
st.equal(codePointAt('abc\uD834\uDF06def', -1), undefined);
st.equal(codePointAt('abc\uD834\uDF06def', -0), 0x61);
st.equal(codePointAt('abc\uD834\uDF06def', 0), 0x61);
st.equal(codePointAt('abc\uD834\uDF06def', 3), 0x1D306);
st.equal(codePointAt('abc\uD834\uDF06def', 4), 0xDF06);
st.equal(codePointAt('abc\uD834\uDF06def', 5), 0x64);
st.equal(codePointAt('abc\uD834\uDF06def', 42), undefined);
st.end();
});
t.test('String that starts with a BMP symbol - cast position', function (st) {
st.equal(codePointAt('abc\uD834\uDF06def', ''), 0x61);
st.equal(codePointAt('abc\uD834\uDF06def', '_'), 0x61);
st.equal(codePointAt('abc\uD834\uDF06def'), 0x61);
st.equal(codePointAt('abc\uD834\uDF06def', -Infinity), undefined);
st.equal(codePointAt('abc\uD834\uDF06def', Infinity), undefined);
st.equal(codePointAt('abc\uD834\uDF06def', Infinity), undefined);
st.equal(codePointAt('abc\uD834\uDF06def', NaN), 0x61);
st.equal(codePointAt('abc\uD834\uDF06def', false), 0x61);
st.equal(codePointAt('abc\uD834\uDF06def', null), 0x61);
st.equal(codePointAt('abc\uD834\uDF06def', undefined), 0x61);
st.end();
});
t.test('String that starts with an astral symbol', function (st) {
st.equal(codePointAt('\uD834\uDF06def', -1), undefined);
st.equal(codePointAt('\uD834\uDF06def', -0), 0x1D306);
st.equal(codePointAt('\uD834\uDF06def', 0), 0x1D306);
st.equal(codePointAt('\uD834\uDF06def', 1), 0xDF06);
st.equal(codePointAt('\uD834\uDF06def', 42), undefined);
st.end();
});
t.test('String that starts with an astral symbol - cast position', function (st) {
st.equal(codePointAt('\uD834\uDF06def', ''), 0x1D306);
st.equal(codePointAt('\uD834\uDF06def', '1'), 0xDF06);
st.equal(codePointAt('\uD834\uDF06def', '_'), 0x1D306);
st.equal(codePointAt('\uD834\uDF06def'), 0x1D306);
st.equal(codePointAt('\uD834\uDF06def', false), 0x1D306);
st.equal(codePointAt('\uD834\uDF06def', null), 0x1D306);
st.equal(codePointAt('\uD834\uDF06def', undefined), 0x1D306);
st.end();
});
t.test('Lone high surrogates', function (st) {
st.equal(codePointAt('\uD834abc', -1), undefined);
st.equal(codePointAt('\uD834abc', -0), 0xD834);
st.equal(codePointAt('\uD834abc', 0), 0xD834);
st.end();
});
t.test('Lone high surrogates - cast position', function (st) {
st.equal(codePointAt('\uD834abc', ''), 0xD834);
st.equal(codePointAt('\uD834abc', '_'), 0xD834);
st.equal(codePointAt('\uD834abc'), 0xD834);
st.equal(codePointAt('\uD834abc', false), 0xD834);
st.equal(codePointAt('\uD834abc', NaN), 0xD834);
st.equal(codePointAt('\uD834abc', null), 0xD834);
st.equal(codePointAt('\uD834abc', undefined), 0xD834);
st.end();
});
t.test('Lone low surrogates', function (st) {
st.equal(codePointAt('\uDF06abc', -1), undefined);
st.equal(codePointAt('\uDF06abc', -0), 0xDF06);
st.equal(codePointAt('\uDF06abc', 0), 0xDF06);
st.end();
});
t.test('Lone low surrogates - cast position', function (st) {
st.equal(codePointAt('\uDF06abc', ''), 0xDF06);
st.equal(codePointAt('\uDF06abc', '_'), 0xDF06);
st.equal(codePointAt('\uDF06abc'), 0xDF06);
st.equal(codePointAt('\uDF06abc', false), 0xDF06);
st.equal(codePointAt('\uDF06abc', NaN), 0xDF06);
st.equal(codePointAt('\uDF06abc', null), 0xDF06);
st.equal(codePointAt('\uDF06abc', undefined), 0xDF06);
st.end();
});
var supportsStrictMode = (function () { return typeof this === 'undefined'; }());
t.test('bad string/this value', { skip: !supportsStrictMode }, function (st) {
st['throws'](function () { return codePointAt(undefined, 'a'); }, TypeError, 'undefined is not an object');
st['throws'](function () { return codePointAt(null, 'a'); }, TypeError, 'null is not an object');
st.end();
});
t.test('cast this value', function (st) {
st.equal(codePointAt(42, 0), 0x34);
st.equal(codePointAt(42, 1), 0x32);
st.equal(codePointAt({ 'toString': function() { return 'abc'; } }, 2), 0x63);
var tmp = 0;
st.equal(codePointAt({ 'toString': function() { ++tmp; return String(tmp); } }, 0), 0x31);
st.equal(tmp, 1);
st.end();
});
};