pax_global_header00006660000000000000000000000064136615773030014525gustar00rootroot0000000000000052 comment=15e01b62e9afcf36c9b945359872d3f6640bfc63 String.prototype.codePointAt-1.0.0/000077500000000000000000000000001366157730300172455ustar00rootroot00000000000000String.prototype.codePointAt-1.0.0/.editorconfig000066400000000000000000000001211366157730300217140ustar00rootroot00000000000000root = true [*] indent_style = tab end_of_line = lf insert_final_newline = true String.prototype.codePointAt-1.0.0/.gitattributes000066400000000000000000000001141366157730300221340ustar00rootroot00000000000000# Automatically normalize line endings for all text-based files * text=auto String.prototype.codePointAt-1.0.0/.gitignore000066400000000000000000000003711366157730300212360ustar00rootroot00000000000000# 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/.npmrc000066400000000000000000000000231366157730300203600ustar00rootroot00000000000000package-lock=false String.prototype.codePointAt-1.0.0/.travis.yml000066400000000000000000000001751366157730300213610ustar00rootroot00000000000000version: ~> 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.txt000066400000000000000000000020651366157730300215220ustar00rootroot00000000000000Copyright 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.md000066400000000000000000000043361366157730300205320ustar00rootroot00000000000000# ES6 `String.prototype.codePointAt` polyfill [![Build status](https://travis-ci.org/mathiasbynens/String.prototype.codePointAt.svg?branch=master)](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 | [![twitter/mathias](https://gravatar.com/avatar/24e08a9ea84deb17ae121074d0f17125?s=70)](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.js000066400000000000000000000001141366157730300205470ustar00rootroot00000000000000/*! https://mths.be/codepointat v1.0.0 by @mathias */ require('./shim')(); String.prototype.codePointAt-1.0.0/implementation.js000066400000000000000000000022421366157730300226300ustar00rootroot00000000000000/*! 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.js000066400000000000000000000007401366157730300207130ustar00rootroot00000000000000/*! 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.json000066400000000000000000000024171366157730300215370ustar00rootroot00000000000000{ "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.js000066400000000000000000000003361366157730300214370ustar00rootroot00000000000000/*! 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.js000066400000000000000000000005531366157730300205460ustar00rootroot00000000000000/*! 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/000077500000000000000000000000001366157730300204075ustar00rootroot00000000000000String.prototype.codePointAt-1.0.0/tests/index.js000066400000000000000000000003011366157730300220460ustar00rootroot00000000000000'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.js000066400000000000000000000017061366157730300223770ustar00rootroot00000000000000'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.js000066400000000000000000000101571366157730300221130ustar00rootroot00000000000000'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(); }); };