@ungap/processing-instruction 0.0.4 → 0.0.5
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/index.js +4 -12
- package/package.json +10 -2
package/index.js
CHANGED
|
@@ -1,18 +1,10 @@
|
|
|
1
|
+
import { escape, unescape } from 'html-escaper';
|
|
2
|
+
|
|
1
3
|
const { defineProperty } = Object;
|
|
2
4
|
const { prototype } = ProcessingInstruction;
|
|
3
5
|
const attributes = /(\S+?)=("|')([^\2]*?)\2/g;
|
|
4
6
|
const attribute = name => new RegExp(`(\\s*)\\b${name}\\b=("|')([^\\2]*?)\\2`);
|
|
5
7
|
|
|
6
|
-
// borrowed from html-escaper
|
|
7
|
-
const es = /[&<>"']/g;
|
|
8
|
-
const cape = c => {
|
|
9
|
-
if (c === '&') return '&';
|
|
10
|
-
if (c === '<') return '<';
|
|
11
|
-
if (c === '>') return '>';
|
|
12
|
-
if (c === '"') return '"';
|
|
13
|
-
return ''';
|
|
14
|
-
};
|
|
15
|
-
|
|
16
8
|
for (const [key, value] of [
|
|
17
9
|
['hasAttribute', function hasAttribute(name) {
|
|
18
10
|
return attribute(name).test(this.data);
|
|
@@ -21,7 +13,7 @@ for (const [key, value] of [
|
|
|
21
13
|
return !![...this.data.matchAll(attributes)].length;
|
|
22
14
|
}],
|
|
23
15
|
['getAttribute', function getAttribute(name) {
|
|
24
|
-
return attribute(name).test(this.data) ? RegExp.$3 : null;
|
|
16
|
+
return attribute(name).test(this.data) ? unescape(RegExp.$3) : null;
|
|
25
17
|
}],
|
|
26
18
|
['getAttributeNames', function getAttributeNames() {
|
|
27
19
|
return [...this.data.matchAll(attributes)].map(([_, name]) => name);
|
|
@@ -31,7 +23,7 @@ for (const [key, value] of [
|
|
|
31
23
|
}],
|
|
32
24
|
['setAttribute', function setAttribute(name, value) {
|
|
33
25
|
const { data } = this;
|
|
34
|
-
value =
|
|
26
|
+
value = escape(value);
|
|
35
27
|
if (attribute(name).test(data)) {
|
|
36
28
|
const { $1, $2, $3 } = RegExp, prefix = $1 + name + '=' + $2;
|
|
37
29
|
this.data = data.replace(prefix + $3, prefix + value);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ungap/processing-instruction",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.5",
|
|
4
4
|
"description": "A polyfill for ProcessingInstruction attributes",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"module": "index.js",
|
|
@@ -13,11 +13,19 @@
|
|
|
13
13
|
"polyfill",
|
|
14
14
|
"shim"
|
|
15
15
|
],
|
|
16
|
+
"files": [
|
|
17
|
+
"index.js",
|
|
18
|
+
"README.md",
|
|
19
|
+
"LICENSE"
|
|
20
|
+
],
|
|
16
21
|
"author": "Andrea Giammarchi",
|
|
17
22
|
"license": "MIT",
|
|
18
23
|
"type": "module",
|
|
19
24
|
"bugs": {
|
|
20
25
|
"url": "https://github.com/ungap/processing-instruction/issues"
|
|
21
26
|
},
|
|
22
|
-
"homepage": "https://github.com/ungap/processing-instruction#readme"
|
|
27
|
+
"homepage": "https://github.com/ungap/processing-instruction#readme",
|
|
28
|
+
"dependencies": {
|
|
29
|
+
"html-escaper": "^3.0.3"
|
|
30
|
+
}
|
|
23
31
|
}
|