[Pkg-javascript-commits] [node-string.prototype.codepointat] 01/03: Import Upstream version 0.2.0

Paolo Greppi paolog-guest at moszumanska.debian.org
Tue Nov 29 11:23:00 UTC 2016


This is an automated email from the git hooks/post-receive script.

paolog-guest pushed a commit to branch master
in repository node-string.prototype.codepointat.

commit 5e8d2946afd3ec72dacca34b89bc944305c2e964
Author: Paolo Greppi <paolo.greppi at libpf.com>
Date:   Tue Nov 29 11:18:05 2016 +0000

    Import Upstream version 0.2.0
---
 .gitattributes  |  2 ++
 .gitignore      | 17 ++++++++++++
 .travis.yml     |  5 ++++
 LICENSE-MIT.txt | 20 ++++++++++++++
 README.md       | 47 +++++++++++++++++++++++++++++++++
 codepointat.js  | 54 ++++++++++++++++++++++++++++++++++++++
 package.json    | 42 ++++++++++++++++++++++++++++++
 tests/tests.js  | 81 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 8 files changed, 268 insertions(+)

diff --git a/.gitattributes b/.gitattributes
new file mode 100644
index 0000000..0a91f75
--- /dev/null
+++ b/.gitattributes
@@ -0,0 +1,2 @@
+# Automatically normalize line endings for all text-based files
+* text=auto
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..444ec4d
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,17 @@
+# 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
diff --git a/.travis.yml b/.travis.yml
new file mode 100644
index 0000000..a65a2e1
--- /dev/null
+++ b/.travis.yml
@@ -0,0 +1,5 @@
+language: node_js
+node_js:
+  - "0.10"
+script:
+  "node tests/tests.js"
diff --git a/LICENSE-MIT.txt b/LICENSE-MIT.txt
new file mode 100644
index 0000000..97067e5
--- /dev/null
+++ b/LICENSE-MIT.txt
@@ -0,0 +1,20 @@
+Copyright Mathias Bynens <http://mathiasbynens.be/>
+
+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.
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..bf09dab
--- /dev/null
+++ b/README.md
@@ -0,0 +1,47 @@
+# 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:
+
+* <http://norbertlindenberg.com/2012/05/ecmascript-supplementary-characters/#String> by [Norbert Lindenberg](http://norbertlindenberg.com/) (fails some tests)
+* <https://gist.github.com/slevithan/2290602> by [Steven Levithan](http://stevenlevithan.com/) (fails some tests)
+* <https://github.com/paulmillr/es6-shim/blob/8e570a4b425a80f9b13ff027dbd28d65f201a319/es6-shim.js#L171-L183> 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
+<script src="codepointat.js"></script>
+```
+
+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.
diff --git a/codepointat.js b/codepointat.js
new file mode 100644
index 0000000..b41f702
--- /dev/null
+++ b/codepointat.js
@@ -0,0 +1,54 @@
+/*! 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;
+		}
+	}());
+}
diff --git a/package.json b/package.json
new file mode 100644
index 0000000..046edb5
--- /dev/null
+++ b/package.json
@@ -0,0 +1,42 @@
+{
+	"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"
+	}
+}
diff --git a/tests/tests.js b/tests/tests.js
new file mode 100644
index 0000000..0beeec0
--- /dev/null
+++ b/tests/tests.js
@@ -0,0 +1,81 @@
+var 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);

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-string.prototype.codepointat.git



More information about the Pkg-javascript-commits mailing list