@mavogel/awscdk-rootmail 0.1.11 → 0.1.12

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.
@@ -1,254 +0,0 @@
1
- /*! https://mths.be/he by @mathias | MIT license */
2
-
3
- import {
4
- decodeMap,
5
- decodeMapLegacy,
6
- decodeMapNumeric,
7
- encodeMap,
8
- invalidReferenceCodePoints,
9
- regexAsciiWhitelist,
10
- regexAstralSymbols,
11
- regexBmpWhitelist,
12
- regexDecode,
13
- regexEncodeNonAscii,
14
- regexInvalidRawCodePoint,
15
- } from './data.mjs';
16
-
17
- const regexEscape = /["&'<>`]/g;
18
- const escapeMap = new Map([
19
- ['"', '&quot;'],
20
- ['&', '&amp;'],
21
- ["'", '&#x27;'],
22
- ['<', '&lt;'],
23
- // See https://mathiasbynens.be/notes/ambiguous-ampersands: in HTML, the
24
- // following is not strictly necessary unless it’s part of a tag or an
25
- // unquoted attribute value. We’re only escaping it to support those
26
- // situations, and for XML support.
27
- ['>', '&gt;'],
28
- // In Internet Explorer ≤ 8, the backtick character can be used
29
- // to break out of (un)quoted attribute values or HTML comments.
30
- // See http://html5sec.org/#102, http://html5sec.org/#108, and
31
- // http://html5sec.org/#133.
32
- ['`', '&#x60;'],
33
- ]);
34
-
35
- const regexInvalidEntity = /&#(?:[xX][^a-fA-F0-9]|[^0-9xX])/;
36
-
37
- /*--------------------------------------------------------------------------*/
38
-
39
- const has = (object, propertyName) => Object.hasOwn(object, propertyName);
40
-
41
- const merge = (options, defaults) => {
42
- if (!options) {
43
- return defaults;
44
- }
45
- const result = {};
46
- for (const key in defaults) {
47
- // A `hasOwnProperty` check is not needed here, since only recognized
48
- // option names are used anyway. Any others are ignored.
49
- result[key] = has(options, key) ? options[key] : defaults[key];
50
- }
51
- return result;
52
- };
53
-
54
- const parseError = (message) => {
55
- throw new Error(`Parse error: ${message}`);
56
- };
57
-
58
- // Converts a code point to a symbol, applying the HTML spec’s rules for
59
- // numeric character references.
60
- const codePointToSymbol = (codePoint, strict) => {
61
- if ((codePoint >= 0xd800 && codePoint <= 0xdfff) || codePoint > 0x10ffff) {
62
- // See issue #4:
63
- // “Otherwise, if the number is in the range 0xD800 to 0xDFFF or is
64
- // greater than 0x10FFFF, then this is a parse error. Return a U+FFFD
65
- // REPLACEMENT CHARACTER.”
66
- if (strict) {
67
- parseError('character reference outside the permissible Unicode range');
68
- }
69
- return '\uFFFD';
70
- }
71
- if (decodeMapNumeric.has(codePoint)) {
72
- if (strict) {
73
- parseError('disallowed character reference');
74
- }
75
- return decodeMapNumeric.get(codePoint);
76
- }
77
- if (strict && invalidReferenceCodePoints.has(codePoint)) {
78
- parseError('disallowed character reference');
79
- }
80
- return String.fromCodePoint(codePoint);
81
- };
82
-
83
- const hexEscape = (codePoint) => {
84
- return `&#x${codePoint.toString(16).toUpperCase()};`;
85
- };
86
-
87
- const decEscape = (codePoint) => {
88
- return `&#${codePoint};`;
89
- };
90
-
91
- /*--------------------------------------------------------------------------*/
92
-
93
- const encode = (string, options) => {
94
- options = merge(options, encode.options);
95
- const strict = options.strict;
96
- if (strict && regexInvalidRawCodePoint.test(string)) {
97
- parseError('forbidden code point');
98
- }
99
- const encodeEverything = options.encodeEverything;
100
- const useNamedReferences = options.useNamedReferences;
101
- const allowUnsafeSymbols = options.allowUnsafeSymbols;
102
- const escapeCodePoint = options.decimal ? decEscape : hexEscape;
103
-
104
- const escapeBmpSymbol = (symbol) => {
105
- return escapeCodePoint(symbol.charCodeAt(0));
106
- };
107
-
108
- if (encodeEverything) {
109
- // Encode ASCII symbols.
110
- string = string.replace(regexAsciiWhitelist, (symbol) => {
111
- // Use named references if requested & possible.
112
- if (useNamedReferences && encodeMap.has(symbol)) {
113
- return `&${encodeMap.get(symbol)};`;
114
- }
115
- return escapeBmpSymbol(symbol);
116
- });
117
- // Shorten a few escapes that represent two symbols, of which at least one
118
- // is within the ASCII range.
119
- if (useNamedReferences) {
120
- string = string
121
- .replace(/&gt;\u20D2/g, '&nvgt;')
122
- .replace(/&lt;\u20D2/g, '&nvlt;')
123
- .replace(/&#x66;&#x6A;/g, '&fjlig;');
124
- }
125
- // Encode non-ASCII symbols.
126
- if (useNamedReferences) {
127
- // Encode non-ASCII symbols that can be replaced with a named reference.
128
- string = string.replace(regexEncodeNonAscii, (string) => {
129
- // Note: there is no need to check `encodeMap.has(string)` here.
130
- return `&${encodeMap.get(string)};`;
131
- });
132
- }
133
- // Note: any remaining non-ASCII symbols are handled outside of the `if`.
134
- } else if (useNamedReferences) {
135
- // Apply named character references.
136
- // Encode `<>"'&` using named character references.
137
- if (!allowUnsafeSymbols) {
138
- string = string.replace(regexEscape, (string) => {
139
- // Note: there is no need to check `encodeMap.has(string)` here.
140
- return `&${encodeMap.get(string)};`;
141
- });
142
- }
143
- // Shorten escapes that represent two symbols, of which at least one is
144
- // `<>"'&`.
145
- string = string
146
- .replace(/&gt;\u20D2/g, '&nvgt;')
147
- .replace(/&lt;\u20D2/g, '&nvlt;');
148
- // Encode non-ASCII symbols that can be replaced with a named reference.
149
- string = string.replace(regexEncodeNonAscii, (string) => {
150
- // Note: there is no need to check `encodeMap.has(string)` here.
151
- return `&${encodeMap.get(string)};`;
152
- });
153
- } else if (!allowUnsafeSymbols) {
154
- // Encode `<>"'&` using hexadecimal escapes, now that they’re not handled
155
- // using named character references.
156
- string = string.replace(regexEscape, escapeBmpSymbol);
157
- }
158
- return (
159
- string
160
- // Encode astral symbols.
161
- .replace(regexAstralSymbols, ($0) => {
162
- // https://mathiasbynens.be/notes/javascript-encoding#surrogate-formulae
163
- const high = $0.charCodeAt(0);
164
- const low = $0.charCodeAt(1);
165
- const codePoint = (high - 0xd800) * 0x400 + low - 0xdc00 + 0x10000;
166
- return escapeCodePoint(codePoint);
167
- })
168
- // Encode any remaining BMP symbols that are not printable ASCII symbols
169
- // using a hexadecimal escape.
170
- .replace(regexBmpWhitelist, escapeBmpSymbol)
171
- );
172
- };
173
- // Expose default options (so they can be overridden globally).
174
- encode.options = {
175
- allowUnsafeSymbols: false,
176
- encodeEverything: false,
177
- strict: false,
178
- useNamedReferences: false,
179
- decimal: false,
180
- };
181
-
182
- const decode = (html, options) => {
183
- options = merge(options, decode.options);
184
- const strict = options.strict;
185
- if (strict && regexInvalidEntity.test(html)) {
186
- parseError('malformed character reference');
187
- }
188
- return html.replace(regexDecode, ($0, $1, $2, $3, $4, $5, $6, $7) => {
189
- if ($1) {
190
- // Note: there is no need to check `decodeMap.has($1)`.
191
- return decodeMap.get($1);
192
- }
193
-
194
- if ($2) {
195
- // Decode named character references without trailing `;`, e.g. `&amp`.
196
- // This is only a parse error if it gets converted to `&`, or if it is
197
- // followed by `=` in an attribute context.
198
- const reference = $2;
199
- const next = $3;
200
- if (next && options.isAttributeValue) {
201
- if (strict && next == '=') {
202
- parseError('`&` did not start a character reference');
203
- }
204
- return $0;
205
- }
206
- if (strict) {
207
- parseError(
208
- 'named character reference was not terminated by a semicolon',
209
- );
210
- }
211
- // Note: there is no need to check `decodeMapLegacy.has(reference)`.
212
- return decodeMapLegacy.get(reference) + (next || '');
213
- }
214
-
215
- if ($4) {
216
- // Decode decimal escapes, e.g. `&#119558;`.
217
- const semicolon = $5;
218
- if (strict && !semicolon) {
219
- parseError('character reference was not terminated by a semicolon');
220
- }
221
- return codePointToSymbol(parseInt($4, 10), strict);
222
- }
223
-
224
- if ($6) {
225
- // Decode hexadecimal escapes, e.g. `&#x1D306;`.
226
- const semicolon = $7;
227
- if (strict && !semicolon) {
228
- parseError('character reference was not terminated by a semicolon');
229
- }
230
- return codePointToSymbol(parseInt($6, 16), strict);
231
- }
232
-
233
- // If we’re still here, the ambiguous ampersand group matched; it’s an
234
- // ambiguous ampersand for sure. https://mths.be/notes/ambiguous-ampersands
235
- if (strict) {
236
- parseError('named character reference was not recognized');
237
- }
238
- return $0;
239
- });
240
- };
241
- // Expose default options (so they can be overridden globally).
242
- decode.options = {
243
- isAttributeValue: false,
244
- strict: false,
245
- };
246
-
247
- const escape = (string) => {
248
- return string.replace(regexEscape, ($0) => {
249
- // Note: there is no need to check `escapeMap.has($0)` here.
250
- return escapeMap.get($0);
251
- });
252
- };
253
-
254
- export { decode, encode, escape, decode as unescape };