Initial commit
This commit is contained in:
11
node_modules/entities/LICENSE
generated
vendored
Normal file
11
node_modules/entities/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
Copyright (c) Felix Böhm
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
||||
|
||||
Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
||||
|
||||
Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
|
||||
THIS IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS,
|
||||
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
33
node_modules/entities/index.js
generated
vendored
Normal file
33
node_modules/entities/index.js
generated
vendored
Normal file
@@ -0,0 +1,33 @@
|
||||
var encode = require("./lib/encode.js"),
|
||||
decode = require("./lib/decode.js");
|
||||
|
||||
exports.decode = function(data, level){
|
||||
return (!level || level <= 0 ? decode.XML : decode.HTML)(data);
|
||||
};
|
||||
|
||||
exports.decodeStrict = function(data, level){
|
||||
return (!level || level <= 0 ? decode.XML : decode.HTMLStrict)(data);
|
||||
};
|
||||
|
||||
exports.encode = function(data, level){
|
||||
return (!level || level <= 0 ? encode.XML : encode.HTML)(data);
|
||||
};
|
||||
|
||||
exports.encodeXML = encode.XML;
|
||||
|
||||
exports.encodeHTML4 =
|
||||
exports.encodeHTML5 =
|
||||
exports.encodeHTML = encode.HTML;
|
||||
|
||||
exports.decodeXML =
|
||||
exports.decodeXMLStrict = decode.XML;
|
||||
|
||||
exports.decodeHTML4 =
|
||||
exports.decodeHTML5 =
|
||||
exports.decodeHTML = decode.HTML;
|
||||
|
||||
exports.decodeHTML4Strict =
|
||||
exports.decodeHTML5Strict =
|
||||
exports.decodeHTMLStrict = decode.HTMLStrict;
|
||||
|
||||
exports.escape = encode.escape;
|
||||
72
node_modules/entities/lib/decode.js
generated
vendored
Normal file
72
node_modules/entities/lib/decode.js
generated
vendored
Normal file
@@ -0,0 +1,72 @@
|
||||
var entityMap = require("../maps/entities.json"),
|
||||
legacyMap = require("../maps/legacy.json"),
|
||||
xmlMap = require("../maps/xml.json"),
|
||||
decodeCodePoint = require("./decode_codepoint.js");
|
||||
|
||||
var decodeXMLStrict = getStrictDecoder(xmlMap),
|
||||
decodeHTMLStrict = getStrictDecoder(entityMap);
|
||||
|
||||
function getStrictDecoder(map){
|
||||
var keys = Object.keys(map).join("|"),
|
||||
replace = getReplacer(map);
|
||||
|
||||
keys += "|#[xX][\\da-fA-F]+|#\\d+";
|
||||
|
||||
var re = new RegExp("&(?:" + keys + ");", "g");
|
||||
|
||||
return function(str){
|
||||
return String(str).replace(re, replace);
|
||||
};
|
||||
}
|
||||
|
||||
var decodeHTML = (function(){
|
||||
var legacy = Object.keys(legacyMap)
|
||||
.sort(sorter);
|
||||
|
||||
var keys = Object.keys(entityMap)
|
||||
.sort(sorter);
|
||||
|
||||
for(var i = 0, j = 0; i < keys.length; i++){
|
||||
if(legacy[j] === keys[i]){
|
||||
keys[i] += ";?";
|
||||
j++;
|
||||
} else {
|
||||
keys[i] += ";";
|
||||
}
|
||||
}
|
||||
|
||||
var re = new RegExp("&(?:" + keys.join("|") + "|#[xX][\\da-fA-F]+;?|#\\d+;?)", "g"),
|
||||
replace = getReplacer(entityMap);
|
||||
|
||||
function replacer(str){
|
||||
if(str.substr(-1) !== ";") str += ";";
|
||||
return replace(str);
|
||||
}
|
||||
|
||||
//TODO consider creating a merged map
|
||||
return function(str){
|
||||
return String(str).replace(re, replacer);
|
||||
};
|
||||
}());
|
||||
|
||||
function sorter(a, b){
|
||||
return a < b ? 1 : -1;
|
||||
}
|
||||
|
||||
function getReplacer(map){
|
||||
return function replace(str){
|
||||
if(str.charAt(1) === "#"){
|
||||
if(str.charAt(2) === "X" || str.charAt(2) === "x"){
|
||||
return decodeCodePoint(parseInt(str.substr(3), 16));
|
||||
}
|
||||
return decodeCodePoint(parseInt(str.substr(2), 10));
|
||||
}
|
||||
return map[str.slice(1, -1)];
|
||||
};
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
XML: decodeXMLStrict,
|
||||
HTML: decodeHTML,
|
||||
HTMLStrict: decodeHTMLStrict
|
||||
};
|
||||
26
node_modules/entities/lib/decode_codepoint.js
generated
vendored
Normal file
26
node_modules/entities/lib/decode_codepoint.js
generated
vendored
Normal file
@@ -0,0 +1,26 @@
|
||||
var decodeMap = require("../maps/decode.json");
|
||||
|
||||
module.exports = decodeCodePoint;
|
||||
|
||||
// modified version of https://github.com/mathiasbynens/he/blob/master/src/he.js#L94-L119
|
||||
function decodeCodePoint(codePoint){
|
||||
|
||||
if((codePoint >= 0xD800 && codePoint <= 0xDFFF) || codePoint > 0x10FFFF){
|
||||
return "\uFFFD";
|
||||
}
|
||||
|
||||
if(codePoint in decodeMap){
|
||||
codePoint = decodeMap[codePoint];
|
||||
}
|
||||
|
||||
var output = "";
|
||||
|
||||
if(codePoint > 0xFFFF){
|
||||
codePoint -= 0x10000;
|
||||
output += String.fromCharCode(codePoint >>> 10 & 0x3FF | 0xD800);
|
||||
codePoint = 0xDC00 | codePoint & 0x3FF;
|
||||
}
|
||||
|
||||
output += String.fromCharCode(codePoint);
|
||||
return output;
|
||||
}
|
||||
73
node_modules/entities/lib/encode.js
generated
vendored
Normal file
73
node_modules/entities/lib/encode.js
generated
vendored
Normal file
@@ -0,0 +1,73 @@
|
||||
var inverseXML = getInverseObj(require("../maps/xml.json")),
|
||||
xmlReplacer = getInverseReplacer(inverseXML);
|
||||
|
||||
exports.XML = getInverse(inverseXML, xmlReplacer);
|
||||
|
||||
var inverseHTML = getInverseObj(require("../maps/entities.json")),
|
||||
htmlReplacer = getInverseReplacer(inverseHTML);
|
||||
|
||||
exports.HTML = getInverse(inverseHTML, htmlReplacer);
|
||||
|
||||
function getInverseObj(obj){
|
||||
return Object.keys(obj).sort().reduce(function(inverse, name){
|
||||
inverse[obj[name]] = "&" + name + ";";
|
||||
return inverse;
|
||||
}, {});
|
||||
}
|
||||
|
||||
function getInverseReplacer(inverse){
|
||||
var single = [],
|
||||
multiple = [];
|
||||
|
||||
Object.keys(inverse).forEach(function(k){
|
||||
if(k.length === 1){
|
||||
single.push("\\" + k);
|
||||
} else {
|
||||
multiple.push(k);
|
||||
}
|
||||
});
|
||||
|
||||
//TODO add ranges
|
||||
multiple.unshift("[" + single.join("") + "]");
|
||||
|
||||
return new RegExp(multiple.join("|"), "g");
|
||||
}
|
||||
|
||||
var re_nonASCII = /[^\0-\x7F]/g,
|
||||
re_astralSymbols = /[\uD800-\uDBFF][\uDC00-\uDFFF]/g;
|
||||
|
||||
function singleCharReplacer(c){
|
||||
return "&#x" + c.charCodeAt(0).toString(16).toUpperCase() + ";";
|
||||
}
|
||||
|
||||
function astralReplacer(c){
|
||||
// http://mathiasbynens.be/notes/javascript-encoding#surrogate-formulae
|
||||
var high = c.charCodeAt(0);
|
||||
var low = c.charCodeAt(1);
|
||||
var codePoint = (high - 0xD800) * 0x400 + low - 0xDC00 + 0x10000;
|
||||
return "&#x" + codePoint.toString(16).toUpperCase() + ";";
|
||||
}
|
||||
|
||||
function getInverse(inverse, re){
|
||||
function func(name){
|
||||
return inverse[name];
|
||||
}
|
||||
|
||||
return function(data){
|
||||
return data
|
||||
.replace(re, func)
|
||||
.replace(re_astralSymbols, astralReplacer)
|
||||
.replace(re_nonASCII, singleCharReplacer);
|
||||
};
|
||||
}
|
||||
|
||||
var re_xmlChars = getInverseReplacer(inverseXML);
|
||||
|
||||
function escapeXML(data){
|
||||
return data
|
||||
.replace(re_xmlChars, singleCharReplacer)
|
||||
.replace(re_astralSymbols, astralReplacer)
|
||||
.replace(re_nonASCII, singleCharReplacer);
|
||||
}
|
||||
|
||||
exports.escape = escapeXML;
|
||||
1
node_modules/entities/maps/decode.json
generated
vendored
Normal file
1
node_modules/entities/maps/decode.json
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"0":65533,"128":8364,"130":8218,"131":402,"132":8222,"133":8230,"134":8224,"135":8225,"136":710,"137":8240,"138":352,"139":8249,"140":338,"142":381,"145":8216,"146":8217,"147":8220,"148":8221,"149":8226,"150":8211,"151":8212,"152":732,"153":8482,"154":353,"155":8250,"156":339,"158":382,"159":376}
|
||||
1
node_modules/entities/maps/entities.json
generated
vendored
Normal file
1
node_modules/entities/maps/entities.json
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
1
node_modules/entities/maps/legacy.json
generated
vendored
Normal file
1
node_modules/entities/maps/legacy.json
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"Aacute":"\u00C1","aacute":"\u00E1","Acirc":"\u00C2","acirc":"\u00E2","acute":"\u00B4","AElig":"\u00C6","aelig":"\u00E6","Agrave":"\u00C0","agrave":"\u00E0","amp":"&","AMP":"&","Aring":"\u00C5","aring":"\u00E5","Atilde":"\u00C3","atilde":"\u00E3","Auml":"\u00C4","auml":"\u00E4","brvbar":"\u00A6","Ccedil":"\u00C7","ccedil":"\u00E7","cedil":"\u00B8","cent":"\u00A2","copy":"\u00A9","COPY":"\u00A9","curren":"\u00A4","deg":"\u00B0","divide":"\u00F7","Eacute":"\u00C9","eacute":"\u00E9","Ecirc":"\u00CA","ecirc":"\u00EA","Egrave":"\u00C8","egrave":"\u00E8","ETH":"\u00D0","eth":"\u00F0","Euml":"\u00CB","euml":"\u00EB","frac12":"\u00BD","frac14":"\u00BC","frac34":"\u00BE","gt":">","GT":">","Iacute":"\u00CD","iacute":"\u00ED","Icirc":"\u00CE","icirc":"\u00EE","iexcl":"\u00A1","Igrave":"\u00CC","igrave":"\u00EC","iquest":"\u00BF","Iuml":"\u00CF","iuml":"\u00EF","laquo":"\u00AB","lt":"<","LT":"<","macr":"\u00AF","micro":"\u00B5","middot":"\u00B7","nbsp":"\u00A0","not":"\u00AC","Ntilde":"\u00D1","ntilde":"\u00F1","Oacute":"\u00D3","oacute":"\u00F3","Ocirc":"\u00D4","ocirc":"\u00F4","Ograve":"\u00D2","ograve":"\u00F2","ordf":"\u00AA","ordm":"\u00BA","Oslash":"\u00D8","oslash":"\u00F8","Otilde":"\u00D5","otilde":"\u00F5","Ouml":"\u00D6","ouml":"\u00F6","para":"\u00B6","plusmn":"\u00B1","pound":"\u00A3","quot":"\"","QUOT":"\"","raquo":"\u00BB","reg":"\u00AE","REG":"\u00AE","sect":"\u00A7","shy":"\u00AD","sup1":"\u00B9","sup2":"\u00B2","sup3":"\u00B3","szlig":"\u00DF","THORN":"\u00DE","thorn":"\u00FE","times":"\u00D7","Uacute":"\u00DA","uacute":"\u00FA","Ucirc":"\u00DB","ucirc":"\u00FB","Ugrave":"\u00D9","ugrave":"\u00F9","uml":"\u00A8","Uuml":"\u00DC","uuml":"\u00FC","Yacute":"\u00DD","yacute":"\u00FD","yen":"\u00A5","yuml":"\u00FF"}
|
||||
1
node_modules/entities/maps/xml.json
generated
vendored
Normal file
1
node_modules/entities/maps/xml.json
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"amp":"&","apos":"'","gt":">","lt":"<","quot":"\""}
|
||||
41
node_modules/entities/package.json
generated
vendored
Normal file
41
node_modules/entities/package.json
generated
vendored
Normal file
@@ -0,0 +1,41 @@
|
||||
{
|
||||
"name": "entities",
|
||||
"version": "1.1.1",
|
||||
"description": "Encode & decode XML/HTML entities with ease",
|
||||
"author": "Felix Boehm <me@feedic.com>",
|
||||
"main": "./index.js",
|
||||
"directories": {
|
||||
"test": "test"
|
||||
},
|
||||
"devDependencies": {
|
||||
"mocha": "1",
|
||||
"mocha-lcov-reporter": "*",
|
||||
"coveralls": "*",
|
||||
"istanbul": "*",
|
||||
"jshint": "2"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/fb55/node-entities.git"
|
||||
},
|
||||
"license": "BSD-like",
|
||||
"jshintConfig": {
|
||||
"eqeqeq": true,
|
||||
"freeze": true,
|
||||
"latedef": "nofunc",
|
||||
"noarg": true,
|
||||
"nonbsp": true,
|
||||
"quotmark": "double",
|
||||
"undef": true,
|
||||
"unused": true,
|
||||
"trailing": true,
|
||||
"eqnull": true,
|
||||
"proto": true,
|
||||
"smarttabs": true,
|
||||
"node": true,
|
||||
"globals": {
|
||||
"describe": true,
|
||||
"it": true
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user