[Pkg-javascript-commits] [node-entities] 40/63: added decodeCodePoint function

Wolfgang Borgert debacle at moszumanska.debian.org
Mon Sep 22 08:15:47 UTC 2014


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

debacle pushed a commit to branch master
in repository node-entities.

commit 85d89e7c76b86ba76f3d4b29a1a6a9f4d3997053
Author: fb55 <me at feedic.com>
Date:   Mon Mar 17 19:49:31 2014 +0100

    added decodeCodePoint function
---
 decode_codepoint.js | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)

diff --git a/decode_codepoint.js b/decode_codepoint.js
new file mode 100644
index 0000000..ff0e23e
--- /dev/null
+++ b/decode_codepoint.js
@@ -0,0 +1,25 @@
+var decodeMap = require("./entities/decode.json");
+
+module.exports = decodeCodePoint;
+
+// modified version of https://github.com/mathiasbynens/he/blob/master/src/he.js#L94-L119
+function decodeCodePoint(codePoint){
+	var output = "";
+
+	if((codePoint >= 0xD800 && codePoint <= 0xDFFF) || codePoint > 0x10FFFF){
+		return "\uFFFD";
+	}
+
+	if(codePoint in decodeMap){
+		codePoint = decodeMap[codePoint];
+	}
+
+	if(codePoint > 0xFFFF){
+		codePoint -= 0x10000;
+		output += String.fromCharCode(codePoint >>> 10 & 0x3FF | 0xD800);
+		codePoint = 0xDC00 | codePoint & 0x3FF;
+	}
+
+	output += String.fromCharCode(codePoint);
+	return output;
+}

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



More information about the Pkg-javascript-commits mailing list