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.4.1 to 0.5.0

10

compile.js

@@ -26,5 +26,9 @@ var modes = ["XML", "HTML4", "HTML5"];

function sortDesc(a, b){
return a < b ? 1 : -1;
}
function getReplacer(obj){
var keys = Object.keys(obj).sort();
var re = keys.join("|").replace(/(\w+)\|\1;/g, "$1;?");
var keys = Object.keys(obj).sort(sortDesc);
var re = keys.join("|")//.replace(/(\w+);\|\1/g, "$1;?");

@@ -38,3 +42,3 @@ // also match hex and char codes

function getStrictReplacer(obj){
var keys = Object.keys(obj).sort().filter(RegExp.prototype.test, /;$/);
var keys = Object.keys(obj).sort(sortDesc).filter(RegExp.prototype.test, /;$/);
var re = keys.map(function(name){

@@ -41,0 +45,0 @@ return name.slice(0, -1); //remove trailing semicolon

@@ -43,5 +43,5 @@ var compiled = require("./compile.js"),

if(name.charAt(2).toLowerCase() === "x"){
return String.fromCharCode(parseInt(name.substr(3), 16));
return codePointToSymbol(parseInt(name.substr(3), 16));
}
return String.fromCharCode(parseInt(name.substr(2), 10));
return codePointToSymbol(parseInt(name.substr(2), 10));
}

@@ -52,2 +52,6 @@ return obj[name.substr(1)];

function codePointToSymbol(entity){
return String.fromCharCode(entity); //TODO
}
function getStrictReplacer(obj){

@@ -54,0 +58,0 @@ return function strictReplacer(name){

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

@@ -5,0 +5,0 @@ "author": "Felix Boehm <me@feedic.com>",

@@ -1,5 +0,6 @@

var assert = require("assert");
var entities = require('../');
var assert = require("assert"),
path = require("path"),
entities = require('../');
describe("Encode->decode test", function() {
describe("Encode->decode test", function(){
var testcases = [

@@ -20,20 +21,31 @@ {

var encodedXML = entities.encodeXML(tc.input);
it("should XML encode " + tc.input, function() {
it("should XML encode " + tc.input, function(){
assert.equal(encodedXML, tc.xml);
});
it("should XML decode " + encodedXML, function() {
it("should default to XML encode " + tc.input, function(){
assert.equal(entities.encode(tc.input), tc.xml);
});
it("should XML decode " + encodedXML, function(){
assert.equal(entities.decodeXML(encodedXML), tc.input);
});
it("should default to XML encode " + encodedXML, function(){
assert.equal(entities.decode(encodedXML), tc.input);
});
it("should default strict to XML encode " + encodedXML, function(){
assert.equal(entities.decodeStrict(encodedXML), tc.input);
});
var encodedHTML4 = entities.encodeHTML4(tc.input);
it("should HTML4 encode " + tc.input, function() {
it("should HTML4 encode " + tc.input, function(){
assert.equal(encodedHTML4, tc.html4);
});
it("should HTML4 decode " + encodedHTML4, function() {
it("should HTML4 decode " + encodedHTML4, function(){
assert.equal(entities.decodeHTML4(encodedHTML4), tc.input);
});
var encodedHTML5 = entities.encodeHTML5(tc.input);
it("should HTML5 encode " + tc.input, function() {
it("should HTML5 encode " + tc.input, function(){
assert.equal(encodedHTML5, tc.html5);
});
it("should HTML5 decode " + encodedHTML5, function() {
it("should HTML5 decode " + encodedHTML5, function(){
assert.equal(entities.decodeHTML5(encodedHTML5), tc.input);

@@ -44,3 +56,3 @@ });

describe("Decode test", function() {
describe("Decode test", function(){
var testcases = [

@@ -60,9 +72,9 @@ { input: "&amp;amp;", output: "&amp;" },

testcases.forEach(function(tc) {
it("should XML decode " + tc.input, function() {
it("should XML decode " + tc.input, function(){
assert.equal(entities.decodeXML(tc.input), tc.output);
});
it("should HTML4 decode " + tc.input, function() {
it("should HTML4 decode " + tc.input, function(){
assert.equal(entities.decodeHTML4(tc.input), tc.output);
});
it("should HTML5 decode " + tc.input, function() {
it("should HTML5 decode " + tc.input, function(){
assert.equal(entities.decodeHTML5(tc.input), tc.output);

@@ -72,1 +84,61 @@ });

});
var levels = ["xml", "html4", "html5"];
describe("Documents", function(){
levels
.map(function(n){ return path.join("..", "entities", n); })
.map(require)
.forEach(function(doc, i){
describe("Decode", function(){
it(levels[i], function(){
Object.keys(doc).forEach(function(e){
for(var l = i; l < levels.length; l++){
assert.equal(entities.decode("&" + e, l), doc[e]);
}
});
});
});
describe("Decode strict", function(){
it(levels[i], function(){
Object.keys(doc).forEach(function(e){
if(e.substr(-1) !== ";"){
assert.equal(entities.decodeStrict("&" + e, i), "&" + e);
return;
}
for(var l = i; l < levels.length; l++){
assert.equal(entities.decodeStrict("&" + e, l), doc[e]);
}
});
});
});
describe("Encode", function(){
it(levels[i], function(){
Object.keys(doc).forEach(function(e){
if(e.substr(-1) !== ";") return;
for(var l = i; l < levels.length; l++){
assert.equal(entities.decode(entities.encode(doc[e], l), l), doc[e]);
}
});
});
});
});
});
var astral = {
"1D306": "\uD834\uDF06",
"1D11E": "\uD834\uDD1E"
};
describe("Astral entities", function(){
Object.keys(astral).forEach(function(c){
/*it("should decode " + astral[c], function(){
assert.equal(entities.decode("&#x" + c + ";"), astral[c]);
});*/
it("should encode " + astral[c], function(){
assert.equal(entities.encode(astral[c]), "&#x" + c + ";");
});
});
});
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