source: trip-planner-front/node_modules/html-entities/lib/xml-entities.js@ fa375fe

Last change on this file since fa375fe was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 3.7 KB
Line 
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3var surrogate_pairs_1 = require("./surrogate-pairs");
4var ALPHA_INDEX = {
5 '&lt': '<',
6 '&gt': '>',
7 '&quot': '"',
8 '&apos': '\'',
9 '&amp': '&',
10 '&lt;': '<',
11 '&gt;': '>',
12 '&quot;': '"',
13 '&apos;': '\'',
14 '&amp;': '&'
15};
16var CHAR_INDEX = {
17 60: 'lt',
18 62: 'gt',
19 34: 'quot',
20 39: 'apos',
21 38: 'amp'
22};
23var CHAR_S_INDEX = {
24 '<': '&lt;',
25 '>': '&gt;',
26 '"': '&quot;',
27 '\'': '&apos;',
28 '&': '&amp;'
29};
30var XmlEntities = /** @class */ (function () {
31 function XmlEntities() {
32 }
33 XmlEntities.prototype.encode = function (str) {
34 if (!str || !str.length) {
35 return '';
36 }
37 return str.replace(/[<>"'&]/g, function (s) {
38 return CHAR_S_INDEX[s];
39 });
40 };
41 XmlEntities.encode = function (str) {
42 return new XmlEntities().encode(str);
43 };
44 XmlEntities.prototype.decode = function (str) {
45 if (!str || !str.length) {
46 return '';
47 }
48 return str.replace(/&#?[0-9a-zA-Z]+;?/g, function (s) {
49 if (s.charAt(1) === '#') {
50 var code = s.charAt(2).toLowerCase() === 'x' ?
51 parseInt(s.substr(3), 16) :
52 parseInt(s.substr(2));
53 if (!isNaN(code) || code >= -32768) {
54 if (code <= 65535) {
55 return String.fromCharCode(code);
56 }
57 else {
58 return surrogate_pairs_1.fromCodePoint(code);
59 }
60 }
61 return '';
62 }
63 return ALPHA_INDEX[s] || s;
64 });
65 };
66 XmlEntities.decode = function (str) {
67 return new XmlEntities().decode(str);
68 };
69 XmlEntities.prototype.encodeNonUTF = function (str) {
70 if (!str || !str.length) {
71 return '';
72 }
73 var strLength = str.length;
74 var result = '';
75 var i = 0;
76 while (i < strLength) {
77 var c = str.charCodeAt(i);
78 var alpha = CHAR_INDEX[c];
79 if (alpha) {
80 result += "&" + alpha + ";";
81 i++;
82 continue;
83 }
84 if (c < 32 || c > 126) {
85 if (c >= surrogate_pairs_1.highSurrogateFrom && c <= surrogate_pairs_1.highSurrogateTo) {
86 result += '&#' + surrogate_pairs_1.getCodePoint(str, i) + ';';
87 i++;
88 }
89 else {
90 result += '&#' + c + ';';
91 }
92 }
93 else {
94 result += str.charAt(i);
95 }
96 i++;
97 }
98 return result;
99 };
100 XmlEntities.encodeNonUTF = function (str) {
101 return new XmlEntities().encodeNonUTF(str);
102 };
103 XmlEntities.prototype.encodeNonASCII = function (str) {
104 if (!str || !str.length) {
105 return '';
106 }
107 var strLength = str.length;
108 var result = '';
109 var i = 0;
110 while (i < strLength) {
111 var c = str.charCodeAt(i);
112 if (c <= 255) {
113 result += str[i++];
114 continue;
115 }
116 if (c >= surrogate_pairs_1.highSurrogateFrom && c <= surrogate_pairs_1.highSurrogateTo) {
117 result += '&#' + surrogate_pairs_1.getCodePoint(str, i) + ';';
118 i++;
119 }
120 else {
121 result += '&#' + c + ';';
122 }
123 i++;
124 }
125 return result;
126 };
127 XmlEntities.encodeNonASCII = function (str) {
128 return new XmlEntities().encodeNonASCII(str);
129 };
130 return XmlEntities;
131}());
132exports.XmlEntities = XmlEntities;
Note: See TracBrowser for help on using the repository browser.