Comparing version 1.0.0 to 2.0.0
12
index.js
@@ -16,14 +16,18 @@ var punycode = require('punycode'); | ||
var numeric = true; | ||
if (opts.named) numeric = false; | ||
if (opts.numeric !== undefined) numeric = opts.numeric; | ||
return str.split('').map(function (c) { | ||
var cc = c.charCodeAt(0); | ||
var e = revEntities[cc]; | ||
if (e && (cc >= 127 || special[c]) && !opts.numeric) { | ||
if (e && (cc >= 127 || special[c]) && !numeric) { | ||
return '&' + (e.match(/;$/) ? e : e + ';'); | ||
} | ||
else if (cc < 32 || cc >= 127 || special[c]) { | ||
return '&#' + cc + ';'; | ||
} | ||
else if (/\s/.test(c)) { | ||
return c; | ||
} | ||
else if (cc < 32 || cc >= 127 || special[c]) { | ||
return '&#' + cc + ';'; | ||
} | ||
else { | ||
@@ -30,0 +34,0 @@ return c; |
{ | ||
"name" : "ent", | ||
"description" : "Encode and decode HTML entities", | ||
"version" : "1.0.0", | ||
"version" : "2.0.0", | ||
"repository" : "https://github.com/substack/node-ent.git", | ||
@@ -6,0 +6,0 @@ "author" : "James Halliday <mail@substack.net> (http://substack.net)", |
@@ -7,3 +7,3 @@ var test = require('tape'); | ||
var a = 'a & b & c'; | ||
var b = 'a & b & c'; | ||
var b = 'a & b & c'; | ||
t.equal(ent.encode(a), b); | ||
@@ -16,3 +16,3 @@ t.equal(ent.decode(b), a); | ||
var a = '<html> © π " \''; | ||
var b = '<html> © π " ''; | ||
var b = '<html> © π " ''; | ||
t.equal(ent.encode(a), b); | ||
@@ -23,5 +23,13 @@ t.equal(ent.decode(b), a); | ||
test('html named', function (t) { | ||
var a = '<html> © π " \''; | ||
var b = '<html> © π " ''; | ||
t.equal(ent.encode(a, { named: true }), b); | ||
t.equal(ent.decode(b), a); | ||
t.end(); | ||
}); | ||
test('entities', function (t) { | ||
var a = '\u2124'; | ||
var b = 'ℤ'; | ||
var b = 'ℤ'; | ||
t.equal(ent.encode(a), b); | ||
@@ -32,2 +40,10 @@ t.equal(ent.decode(b), a); | ||
test('entities named', function (t) { | ||
var a = '\u2124'; | ||
var b = 'ℤ'; | ||
t.equal(ent.encode(a, { named: true }), b); | ||
t.equal(ent.decode(b), a); | ||
t.end(); | ||
}); | ||
test('num', function (t) { | ||
@@ -34,0 +50,0 @@ var a = String.fromCharCode(1337); |
@@ -10,5 +10,5 @@ var test = require('tape'); | ||
t.equal(ent.encode(a, { numeric: true }), ax); | ||
t.equal(ent.encode(b, { numeric: true }), bx); | ||
t.equal(ent.encode(a), ax); | ||
t.equal(ent.encode(b), bx); | ||
t.end(); | ||
}); |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
96307
3705
55