entities 1.1.2 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +33 -0
- package/lib/decode.d.ts +7 -0
- package/lib/decode.d.ts.map +1 -0
- package/lib/decode.js +27 -43
- package/lib/decode_codepoint.d.ts +2 -0
- package/lib/decode_codepoint.d.ts.map +1 -0
- package/lib/decode_codepoint.js +10 -10
- package/lib/encode.d.ts +4 -0
- package/lib/encode.d.ts.map +1 -0
- package/lib/encode.js +43 -58
- package/lib/index.d.ts +6 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +33 -0
- package/lib/maps/decode.json +1 -0
- package/lib/maps/entities.json +1 -0
- package/lib/maps/legacy.json +1 -0
- package/lib/maps/xml.json +1 -0
- package/lib/src/decode.d.ts +7 -0
- package/lib/src/decode.d.ts.map +1 -0
- package/lib/src/decode.js +54 -0
- package/lib/src/decode_codepoint.d.ts +2 -0
- package/lib/src/decode_codepoint.d.ts.map +1 -0
- package/lib/src/decode_codepoint.js +25 -0
- package/lib/src/encode.d.ts +4 -0
- package/lib/src/encode.d.ts.map +1 -0
- package/lib/src/encode.js +67 -0
- package/lib/src/index.d.ts +6 -0
- package/lib/src/index.d.ts.map +1 -0
- package/lib/src/index.js +36 -0
- package/package.json +63 -54
- package/.travis.yml +0 -5
- package/index.js +0 -26
- package/maps/decode.json +0 -1
- package/maps/entities.json +0 -1
- package/maps/legacy.json +0 -1
- package/maps/xml.json +0 -1
- package/readme.md +0 -27
- package/test/mocha.opts +0 -2
- package/test/test.js +0 -170
package/test/test.js
DELETED
|
@@ -1,170 +0,0 @@
|
|
|
1
|
-
var assert = require("assert"),
|
|
2
|
-
path = require("path"),
|
|
3
|
-
entities = require("../");
|
|
4
|
-
|
|
5
|
-
describe("Encode->decode test", function() {
|
|
6
|
-
var testcases = [
|
|
7
|
-
{
|
|
8
|
-
input: "asdf & ÿ ü '",
|
|
9
|
-
xml: "asdf & ÿ ü '",
|
|
10
|
-
html: "asdf & ÿ ü '"
|
|
11
|
-
},
|
|
12
|
-
{
|
|
13
|
-
input: "&",
|
|
14
|
-
xml: "&",
|
|
15
|
-
html: "&"
|
|
16
|
-
}
|
|
17
|
-
];
|
|
18
|
-
testcases.forEach(function(tc) {
|
|
19
|
-
var encodedXML = entities.encodeXML(tc.input);
|
|
20
|
-
it("should XML encode " + tc.input, function() {
|
|
21
|
-
assert.equal(encodedXML, tc.xml);
|
|
22
|
-
});
|
|
23
|
-
it("should default to XML encode " + tc.input, function() {
|
|
24
|
-
assert.equal(entities.encode(tc.input), tc.xml);
|
|
25
|
-
});
|
|
26
|
-
it("should XML decode " + encodedXML, function() {
|
|
27
|
-
assert.equal(entities.decodeXML(encodedXML), tc.input);
|
|
28
|
-
});
|
|
29
|
-
it("should default to XML encode " + encodedXML, function() {
|
|
30
|
-
assert.equal(entities.decode(encodedXML), tc.input);
|
|
31
|
-
});
|
|
32
|
-
it("should default strict to XML encode " + encodedXML, function() {
|
|
33
|
-
assert.equal(entities.decodeStrict(encodedXML), tc.input);
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
var encodedHTML5 = entities.encodeHTML5(tc.input);
|
|
37
|
-
it("should HTML5 encode " + tc.input, function() {
|
|
38
|
-
assert.equal(encodedHTML5, tc.html);
|
|
39
|
-
});
|
|
40
|
-
it("should HTML5 decode " + encodedHTML5, function() {
|
|
41
|
-
assert.equal(entities.decodeHTML(encodedHTML5), tc.input);
|
|
42
|
-
});
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
it("should encode data URIs (issue 16)", function() {
|
|
46
|
-
var data = "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAALAAABAAEAAAIBRAA7";
|
|
47
|
-
assert.equal(entities.decode(entities.encode(data)), data);
|
|
48
|
-
});
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
describe("Decode test", function() {
|
|
52
|
-
var testcases = [
|
|
53
|
-
{ input: "&", output: "&" },
|
|
54
|
-
{ input: "&", output: "&" },
|
|
55
|
-
{ input: "&", output: "&" },
|
|
56
|
-
{ input: "&", output: "&" },
|
|
57
|
-
{ input: "&", output: "&" },
|
|
58
|
-
{ input: "&", output: "&" },
|
|
59
|
-
{ input: "&", output: "&" },
|
|
60
|
-
{ input: ":", output: ":" },
|
|
61
|
-
{ input: ":", output: ":" },
|
|
62
|
-
{ input: ":", output: ":" },
|
|
63
|
-
{ input: ":", output: ":" }
|
|
64
|
-
];
|
|
65
|
-
testcases.forEach(function(tc) {
|
|
66
|
-
it("should XML decode " + tc.input, function() {
|
|
67
|
-
assert.equal(entities.decodeXML(tc.input), tc.output);
|
|
68
|
-
});
|
|
69
|
-
it("should HTML4 decode " + tc.input, function() {
|
|
70
|
-
assert.equal(entities.decodeHTML(tc.input), tc.output);
|
|
71
|
-
});
|
|
72
|
-
it("should HTML5 decode " + tc.input, function() {
|
|
73
|
-
assert.equal(entities.decodeHTML(tc.input), tc.output);
|
|
74
|
-
});
|
|
75
|
-
});
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
var levels = ["xml", "entities"];
|
|
79
|
-
|
|
80
|
-
describe("Documents", function() {
|
|
81
|
-
levels
|
|
82
|
-
.map(function(n) {
|
|
83
|
-
return path.join("..", "maps", n);
|
|
84
|
-
})
|
|
85
|
-
.map(require)
|
|
86
|
-
.forEach(function(doc, i) {
|
|
87
|
-
describe("Decode", function() {
|
|
88
|
-
it(levels[i], function() {
|
|
89
|
-
Object.keys(doc).forEach(function(e) {
|
|
90
|
-
for (var l = i; l < levels.length; l++) {
|
|
91
|
-
assert.equal(entities.decode("&" + e + ";", l), doc[e]);
|
|
92
|
-
}
|
|
93
|
-
});
|
|
94
|
-
});
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
describe("Decode strict", function() {
|
|
98
|
-
it(levels[i], function() {
|
|
99
|
-
Object.keys(doc).forEach(function(e) {
|
|
100
|
-
for (var l = i; l < levels.length; l++) {
|
|
101
|
-
assert.equal(entities.decodeStrict("&" + e + ";", l), doc[e]);
|
|
102
|
-
}
|
|
103
|
-
});
|
|
104
|
-
});
|
|
105
|
-
});
|
|
106
|
-
|
|
107
|
-
describe("Encode", function() {
|
|
108
|
-
it(levels[i], function() {
|
|
109
|
-
Object.keys(doc).forEach(function(e) {
|
|
110
|
-
for (var l = i; l < levels.length; l++) {
|
|
111
|
-
assert.equal(entities.decode(entities.encode(doc[e], l), l), doc[e]);
|
|
112
|
-
}
|
|
113
|
-
});
|
|
114
|
-
});
|
|
115
|
-
});
|
|
116
|
-
});
|
|
117
|
-
|
|
118
|
-
var legacy = require("../maps/legacy.json");
|
|
119
|
-
|
|
120
|
-
describe("Legacy", function() {
|
|
121
|
-
it("should decode", runLegacy);
|
|
122
|
-
});
|
|
123
|
-
|
|
124
|
-
function runLegacy() {
|
|
125
|
-
Object.keys(legacy).forEach(function(e) {
|
|
126
|
-
assert.equal(entities.decodeHTML("&" + e), legacy[e]);
|
|
127
|
-
});
|
|
128
|
-
}
|
|
129
|
-
});
|
|
130
|
-
|
|
131
|
-
var astral = {
|
|
132
|
-
"1D306": "\uD834\uDF06",
|
|
133
|
-
"1D11E": "\uD834\uDD1E"
|
|
134
|
-
};
|
|
135
|
-
|
|
136
|
-
var astralSpecial = {
|
|
137
|
-
"80": "\u20AC",
|
|
138
|
-
"110000": "\uFFFD"
|
|
139
|
-
};
|
|
140
|
-
|
|
141
|
-
describe("Astral entities", function() {
|
|
142
|
-
Object.keys(astral).forEach(function(c) {
|
|
143
|
-
it("should decode " + astral[c], function() {
|
|
144
|
-
assert.equal(entities.decode("&#x" + c + ";"), astral[c]);
|
|
145
|
-
});
|
|
146
|
-
|
|
147
|
-
it("should encode " + astral[c], function() {
|
|
148
|
-
assert.equal(entities.encode(astral[c]), "&#x" + c + ";");
|
|
149
|
-
});
|
|
150
|
-
|
|
151
|
-
it("should escape " + astral[c], function() {
|
|
152
|
-
assert.equal(entities.escape(astral[c]), "&#x" + c + ";");
|
|
153
|
-
});
|
|
154
|
-
});
|
|
155
|
-
|
|
156
|
-
Object.keys(astralSpecial).forEach(function(c) {
|
|
157
|
-
it("special should decode \\u" + c, function() {
|
|
158
|
-
assert.equal(entities.decode("&#x" + c + ";"), astralSpecial[c]);
|
|
159
|
-
});
|
|
160
|
-
});
|
|
161
|
-
});
|
|
162
|
-
|
|
163
|
-
describe("Escape", function() {
|
|
164
|
-
it("should always decode ASCII chars", function() {
|
|
165
|
-
for (var i = 0; i < 0x7f; i++) {
|
|
166
|
-
var c = String.fromCharCode(i);
|
|
167
|
-
assert.equal(entities.decodeXML(entities.escape(c)), c);
|
|
168
|
-
}
|
|
169
|
-
});
|
|
170
|
-
});
|