pax_global_header00006660000000000000000000000064123215612020014504gustar00rootroot0000000000000052 comment=87098c59c75b192712dd17777e988fd936cdd856 String.prototype.codePointAt-0.2.0/000077500000000000000000000000001232156120200172255ustar00rootroot00000000000000String.prototype.codePointAt-0.2.0/.gitattributes000066400000000000000000000001141232156120200221140ustar00rootroot00000000000000# Automatically normalize line endings for all text-based files * text=auto String.prototype.codePointAt-0.2.0/.gitignore000066400000000000000000000003471232156120200212210ustar00rootroot00000000000000# Coverage report coverage # Installed npm modules node_modules # 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-0.2.0/.travis.yml000066400000000000000000000001061232156120200213330ustar00rootroot00000000000000language: node_js node_js: - "0.10" script: "node tests/tests.js" String.prototype.codePointAt-0.2.0/LICENSE-MIT.txt000066400000000000000000000020641232156120200215010ustar00rootroot00000000000000Copyright 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-0.2.0/README.md000066400000000000000000000034471232156120200205140ustar00rootroot00000000000000# 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 ES3-compatible polyfill for [the `String.prototype.codePointAt` method in ECMAScript 6](http://people.mozilla.org/~jorendorff/es6-draft.html#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 In a browser: ```html ``` 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'); ``` ## Notes [A polyfill + test suite for `String.fromCodePoint`](http://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](http://mathiasbynens.be/) | ## License This polyfill is available under the [MIT](http://mths.be/mit) license. String.prototype.codePointAt-0.2.0/codepointat.js000066400000000000000000000031531232156120200220760ustar00rootroot00000000000000/*! http://mths.be/codepointat v0.2.0 by @mathias */ if (!String.prototype.codePointAt) { (function() { 'use strict'; // needed to support `apply`/`call` with `undefined`/`null` var defineProperty = (function() { // IE 8 only supports `Object.defineProperty` on DOM elements try { var object = {}; var $defineProperty = Object.defineProperty; var result = $defineProperty(object, object, object) && $defineProperty; } catch(error) {} return result; }()); 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 (defineProperty) { defineProperty(String.prototype, 'codePointAt', { 'value': codePointAt, 'configurable': true, 'writable': true }); } else { String.prototype.codePointAt = codePointAt; } }()); } String.prototype.codePointAt-0.2.0/package.json000066400000000000000000000016471232156120200215230ustar00rootroot00000000000000{ "name": "string.prototype.codepointat", "version": "0.2.0", "description": "A robust & optimized `String.prototype.codePointAt` polyfill, based on the ECMAScript 6 specification.", "homepage": "http://mths.be/codepointat", "main": "codepointat.js", "keywords": [ "string", "unicode", "es6", "ecmascript", "polyfill" ], "licenses": [ { "type": "MIT", "url": "http://mths.be/mit" } ], "author": { "name": "Mathias Bynens", "url": "http://mathiasbynens.be/" }, "repository": { "type": "git", "url": "https://github.com/mathiasbynens/String.prototype.codePointAt.git" }, "bugs": { "url": "https://github.com/mathiasbynens/String.prototype.codePointAt/issues" }, "files": [ "LICENSE-MIT.txt", "codepointat.js" ], "directories": { "test": "tests" }, "scripts": { "test": "node tests/tests.js", "cover": "istanbul cover --report html --verbose --dir coverage tests/tests.js" } } String.prototype.codePointAt-0.2.0/tests/000077500000000000000000000000001232156120200203675ustar00rootroot00000000000000String.prototype.codePointAt-0.2.0/tests/tests.js000066400000000000000000000104101232156120200220630ustar00rootroot00000000000000var assert = require('assert'); var assertEquals = assert.equal; var assertThrows = assert['throws']; require('../codepointat.js'); assertEquals(String.prototype.codePointAt.length, 1); assertEquals(String.prototype.propertyIsEnumerable('codePointAt'), false); // String that starts with a BMP symbol assertEquals('abc\uD834\uDF06def'.codePointAt(''), 0x61); assertEquals('abc\uD834\uDF06def'.codePointAt('_'), 0x61); assertEquals('abc\uD834\uDF06def'.codePointAt(), 0x61); assertEquals('abc\uD834\uDF06def'.codePointAt(-Infinity), undefined); assertEquals('abc\uD834\uDF06def'.codePointAt(-1), undefined); assertEquals('abc\uD834\uDF06def'.codePointAt(-0), 0x61); assertEquals('abc\uD834\uDF06def'.codePointAt(0), 0x61); assertEquals('abc\uD834\uDF06def'.codePointAt(3), 0x1D306); assertEquals('abc\uD834\uDF06def'.codePointAt(4), 0xDF06); assertEquals('abc\uD834\uDF06def'.codePointAt(5), 0x64); assertEquals('abc\uD834\uDF06def'.codePointAt(42), undefined); assertEquals('abc\uD834\uDF06def'.codePointAt(Infinity), undefined); assertEquals('abc\uD834\uDF06def'.codePointAt(Infinity), undefined); assertEquals('abc\uD834\uDF06def'.codePointAt(NaN), 0x61); assertEquals('abc\uD834\uDF06def'.codePointAt(false), 0x61); assertEquals('abc\uD834\uDF06def'.codePointAt(null), 0x61); assertEquals('abc\uD834\uDF06def'.codePointAt(undefined), 0x61); // String that starts with an astral symbol assertEquals('\uD834\uDF06def'.codePointAt(''), 0x1D306); assertEquals('\uD834\uDF06def'.codePointAt('1'), 0xDF06); assertEquals('\uD834\uDF06def'.codePointAt('_'), 0x1D306); assertEquals('\uD834\uDF06def'.codePointAt(), 0x1D306); assertEquals('\uD834\uDF06def'.codePointAt(-1), undefined); assertEquals('\uD834\uDF06def'.codePointAt(-0), 0x1D306); assertEquals('\uD834\uDF06def'.codePointAt(0), 0x1D306); assertEquals('\uD834\uDF06def'.codePointAt(1), 0xDF06); assertEquals('\uD834\uDF06def'.codePointAt(42), undefined); assertEquals('\uD834\uDF06def'.codePointAt(false), 0x1D306); assertEquals('\uD834\uDF06def'.codePointAt(null), 0x1D306); assertEquals('\uD834\uDF06def'.codePointAt(undefined), 0x1D306); // Lone high surrogates assertEquals('\uD834abc'.codePointAt(''), 0xD834); assertEquals('\uD834abc'.codePointAt('_'), 0xD834); assertEquals('\uD834abc'.codePointAt(), 0xD834); assertEquals('\uD834abc'.codePointAt(-1), undefined); assertEquals('\uD834abc'.codePointAt(-0), 0xD834); assertEquals('\uD834abc'.codePointAt(0), 0xD834); assertEquals('\uD834abc'.codePointAt(false), 0xD834); assertEquals('\uD834abc'.codePointAt(NaN), 0xD834); assertEquals('\uD834abc'.codePointAt(null), 0xD834); assertEquals('\uD834abc'.codePointAt(undefined), 0xD834); // Lone low surrogates assertEquals('\uDF06abc'.codePointAt(''), 0xDF06); assertEquals('\uDF06abc'.codePointAt('_'), 0xDF06); assertEquals('\uDF06abc'.codePointAt(), 0xDF06); assertEquals('\uDF06abc'.codePointAt(-1), undefined); assertEquals('\uDF06abc'.codePointAt(-0), 0xDF06); assertEquals('\uDF06abc'.codePointAt(0), 0xDF06); assertEquals('\uDF06abc'.codePointAt(false), 0xDF06); assertEquals('\uDF06abc'.codePointAt(NaN), 0xDF06); assertEquals('\uDF06abc'.codePointAt(null), 0xDF06); assertEquals('\uDF06abc'.codePointAt(undefined), 0xDF06); assertThrows(function() { String.prototype.codePointAt.call(undefined); }, TypeError); assertThrows(function() { String.prototype.codePointAt.call(undefined, 4); }, TypeError); assertThrows(function() { String.prototype.codePointAt.call(null); }, TypeError); assertThrows(function() { String.prototype.codePointAt.call(null, 4); }, TypeError); assertEquals(String.prototype.codePointAt.call(42, 0), 0x34); assertEquals(String.prototype.codePointAt.call(42, 1), 0x32); assertEquals(String.prototype.codePointAt.call({ 'toString': function() { return 'abc'; } }, 2), 0x63); assertThrows(function() { String.prototype.codePointAt.apply(undefined); }, TypeError); assertThrows(function() { String.prototype.codePointAt.apply(undefined, [4]); }, TypeError); assertThrows(function() { String.prototype.codePointAt.apply(null); }, TypeError); assertThrows(function() { String.prototype.codePointAt.apply(null, [4]); }, TypeError); assertEquals(String.prototype.codePointAt.apply(42, [0]), 0x34); assertEquals(String.prototype.codePointAt.apply(42, [1]), 0x32); assertEquals(String.prototype.codePointAt.apply({ 'toString': function() { return 'abc'; } }, [2]), 0x63);