Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

entities

Package Overview
Dependencies
Maintainers
1
Versions
30
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

entities - npm Package Compare versions

Comparing version 0.2.1 to 0.2.2

test/mocha.opts

42

index.js

@@ -1,15 +0,6 @@

var re_hex = /&#x[\da-f]+;?/gi,
re_strictHex = /&#x[\da-f]+;/gi,
re_charCode = /&#\d+;?/g,
re_strictCharCode = /&#\d+;/g,
re_notUTF8 = /[\u00c0-\u00d6\u00d8-\u00f6\u00f8-\u02ff\u0370-\u037d\u037f-\u1fff\u200c\u200d\u2070-\u218f\u2c00-\u2fef\u3001-\ud7ff\uf900-\ufdcf\ufdf0-\ufffd]/g,
fromCharCode = String.fromCharCode,
num_func = function(num){return fromCharCode(parseInt(num.substr(2), 10));},
hex_func = function(hex){return fromCharCode(parseInt(hex.substr(3), 16));},
strictNum_func = function(num){return fromCharCode(num.slice(2, -1));},
strictHex_func = function(num){return fromCharCode(parseInt(num.slice(3, -1), 16));},
charCode_func = function(c){ return "&#" +c.charCodeAt(0) +";";};
var re_notUTF8 = /[\u00c0-\u00d6\u00d8-\u00f6\u00f8-\u02ff\u0370-\u037d\u037f-\u1fff\u200c\u200d\u2070-\u218f\u2c00-\u2fef\u3001-\ud7ff\uf900-\ufdcf\ufdf0-\ufffd]/g,
charCode_func = function(c){ return "&#" + c.charCodeAt(0) + ";";};
var fetch = function(filename, inherits){
var obj = require("./entities/" +filename +".json");
var obj = require("./entities/" + filename + ".json");

@@ -19,8 +10,17 @@ if(inherits) for(var name in inherits) obj[name] = inherits[name];

var re = Object.keys(obj).sort().join("|").replace(/(\w+)\|\1;/g, "$1;?");
// also match hex and char codes
re += "|#[xX][0-9a-fA-F]+;?|#\\d+;?";
return {
func: function(name){
if (name.charAt(1) === "#") {
if (name.charAt(2).toLowerCase() === "x") {
return String.fromCharCode(parseInt(name.substr(3), 16));
}
return String.fromCharCode(parseInt(name.substr(2), 10));
}
return obj[name.substr(1)];
},
re: new RegExp("&(?:" +re +")", "g"),
re: new RegExp("&(?:" + re + ")", "g"),
obj: obj

@@ -37,4 +37,4 @@ };

return {
func: function(name){ return "&" +reverse[name]; },
re: new RegExp("\\" +Object.keys(reverse).sort().join("|\\"), "g")
func: function(name){ return "&" + reverse[name]; },
re: new RegExp("\\" + Object.keys(reverse).sort().join("|\\"), "g")
};

@@ -48,7 +48,7 @@ };

if(!modes[level]) level = 0;
return module.exports["decode" +modes[level]](data);
return module.exports["decode" + modes[level]](data);
},
encode: function(data, level){
if(!modes[level]) level = 0;
return module.exports["encode" +modes[level]](data);
return module.exports["encode" + modes[level]](data);
}

@@ -66,7 +66,5 @@ };

module.exports["decode" +name] = function(data){
module.exports["decode" + name] = function(data){
return data
.replace(regex, func)
.replace(re_hex, hex_func)
.replace(re_charCode, num_func);
.replace(regex, func);
};

@@ -78,3 +76,3 @@

module.exports["encode" +name] = function(data){
module.exports["encode" + name] = function(data){
return data

@@ -81,0 +79,0 @@ .replace(reverse_re, reverse_func)

{
"name": "entities",
"version": "0.2.1",
"version": "0.2.2",
"description": "Encode & decode XML/HTML entities with ease",

@@ -8,2 +8,11 @@ "author": "Felix Boehm <me@feedic.com>",

"main": "./index.js",
"directories": {
"test": "test"
},
"devDependencies": {
"mocha": "~1.9.0"
},
"scripts": {
"test": "mocha"
},
"repository": {

@@ -10,0 +19,0 @@ "type": "git"

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc