Comparing version 0.1.0 to 1.0.0
14
index.js
@@ -5,6 +5,12 @@ var punycode = require('punycode'); | ||
exports.encode = function (str) { | ||
exports.encode = function (str, opts) { | ||
if (typeof str !== 'string') { | ||
throw new TypeError('Expected a String'); | ||
} | ||
var special = { | ||
'"': true, "'": true, | ||
'<': true, '>': true, | ||
'&': true | ||
}; | ||
if (!opts) opts = {}; | ||
@@ -14,9 +20,9 @@ return str.split('').map(function (c) { | ||
var e = revEntities[cc]; | ||
if (e) { | ||
if (e && (cc >= 127 || special[c]) && !opts.numeric) { | ||
return '&' + (e.match(/;$/) ? e : e + ';'); | ||
} | ||
else if (c.match(/\s/)) { | ||
else if (/\s/.test(c)) { | ||
return c; | ||
} | ||
else if (cc < 32 || cc >= 127) { | ||
else if (cc < 32 || cc >= 127 || special[c]) { | ||
return '&#' + cc + ';'; | ||
@@ -23,0 +29,0 @@ } |
{ | ||
"name" : "ent", | ||
"description" : "Encode and decode HTML entities", | ||
"version" : "0.1.0", | ||
"version" : "1.0.0", | ||
"repository" : "https://github.com/substack/node-ent.git", | ||
@@ -18,3 +18,3 @@ "author" : "James Halliday <mail@substack.net> (http://substack.net)", | ||
"scripts" : { | ||
"test" : "tap test/*.js", | ||
"test" : "tape test/*.js", | ||
"prepublish" : "node build/index.js" | ||
@@ -24,14 +24,13 @@ }, | ||
"files" : "test/*.js", | ||
"browsers" : { | ||
"ie" : [ 6, 7, 8, 9 ], | ||
"ff" : [ 3.5, 10, 15.0 ], | ||
"chrome" : [ 10, 22 ], | ||
"safari" : [ 5.1 ], | ||
"opera" : [ 12 ] | ||
} | ||
"browsers" : [ | ||
"ie/6..latest", | ||
"ff/3.5", "ff/latest", | ||
"chrome/10", "chrome/latest", | ||
"safari/latest", | ||
"opera/latest" | ||
] | ||
}, | ||
"devDependencies" : { | ||
"tap" : "~0.4.3", | ||
"tape" : "~1.0.4" | ||
"tape" : "~2.3.2" | ||
} | ||
} |
@@ -40,33 +40,2 @@ var test = require('tape'); | ||
test('hex', function (t) { | ||
for (var i = 0; i < 32; i++) { | ||
var a = String.fromCharCode(i); | ||
if (a.match(/\s/)) { | ||
t.equal(ent.decode(a), a); | ||
} | ||
else { | ||
var b = '&#x' + i.toString(16) + ';'; | ||
t.equal(ent.decode(b), a); | ||
t.equal(ent.encode(a), '&#' + i + ';'); | ||
} | ||
} | ||
for (var i = 127; i < 2000; i++) { | ||
var a = String.fromCharCode(i); | ||
var b = '&#x' + i.toString(16) + ';'; | ||
var c = '&#X' + i.toString(16) + ';'; | ||
t.equal(ent.decode(b), a); | ||
t.equal(ent.decode(c), a); | ||
var encoded = ent.encode(a); | ||
var encoded2 = ent.encode(a + a); | ||
if (!encoded.match(/^&\w+;/)) { | ||
t.equal(encoded, '&#' + i + ';'); | ||
t.equal(encoded2, '&#' + i + ';&#' + i + ';'); | ||
} | ||
} | ||
t.end(); | ||
}); | ||
test('astral num', function (t) { | ||
@@ -73,0 +42,0 @@ var a = punycode.ucs2.encode([0x1d306]); |
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
95748
1
12
3688
1
53
0