ent
Advanced tools
Comparing version 0.0.2 to 0.0.3
@@ -24,3 +24,6 @@ var fs = require('fs'); | ||
} | ||
else if (cc > 127) { | ||
else if (c.match(/\s/)) { | ||
return c; | ||
} | ||
else if (cc < 32 || cc >= 127) { | ||
return '&#' + cc + ';'; | ||
@@ -43,2 +46,5 @@ } | ||
}) | ||
.replace(/&#[xX]([A-Fa-f0-9]+);?/, function (_, hex) { | ||
return String.fromCharCode(parseInt(hex, 16)); | ||
}) | ||
.replace(/&([^;\W]+;?)/g, function (m, e) { | ||
@@ -45,0 +51,0 @@ var ee = e.replace(/;$/, ''); |
{ | ||
"name": "ent", | ||
"description": "Encode and decode HTML entities", | ||
"version": "0.0.2", | ||
"version": "0.0.3", | ||
"repository": "https://github.com/substack/node-ent.git", | ||
@@ -16,2 +16,3 @@ "author": "James Halliday <mail@substack.net> (http://substack.net)", | ||
], | ||
"license" : "perl", | ||
"scripts": { | ||
@@ -18,0 +19,0 @@ "test": "expresso" |
@@ -24,1 +24,29 @@ var assert = require('assert'); | ||
}; | ||
exports.hex = function () { | ||
for (var i = 0; i < 32; i++) { | ||
var a = String.fromCharCode(i); | ||
if (a.match(/\s/)) { | ||
assert.equal(ent.decode(a), a); | ||
} | ||
else { | ||
var b = '&#x' + i.toString(16) + ';'; | ||
assert.equal(ent.decode(b), a); | ||
assert.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) + ';'; | ||
assert.equal(ent.decode(b), a); | ||
assert.equal(ent.decode(c), a); | ||
var encoded = ent.encode(a); | ||
if (!encoded.match(/^&\w+;/)) { | ||
assert.equal(encoded, '&#' + i + ';'); | ||
} | ||
} | ||
}; |
No License Found
License(Experimental) License information could not be found
Found 1 instance in 1 package
9278
7
1
361