@schukai/monster 3.110.1 → 3.110.3

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.
@@ -12,7 +12,7 @@
12
12
  * SPDX-License-Identifier: AGPL-3.0
13
13
  */
14
14
 
15
- export { parseBracketedKeyValueHash, createBracketedKeyValueHash };
15
+ export {parseBracketedKeyValueHash, createBracketedKeyValueHash};
16
16
 
17
17
  /**
18
18
  * Parses a string containing bracketed key-value pairs and returns an object representing the parsed result.
@@ -51,155 +51,155 @@ export { parseBracketedKeyValueHash, createBracketedKeyValueHash };
51
51
  * @return {Object} - An object representing the parsed result, with keys representing the selectors and values representing the key-value pairs associated with each selector.
52
52
  * - Returns an empty object if there was an error during parsing. */
53
53
  function parseBracketedKeyValueHash(hashString) {
54
- const selectors = {};
55
- //const selectorStack = [];
56
- //const keyValueStack = [];
57
-
58
- const trimmedHashString = hashString.trim();
59
- const cleanedHashString =
60
- trimmedHashString.charAt(0) === "#"
61
- ? trimmedHashString.slice(1)
62
- : trimmedHashString;
63
-
64
- //const selectors = (keyValueStack.length > 0) ? result[selectorStack[selectorStack.length - 1]] : result;
65
- let currentSelector = "";
66
-
67
- function addToResult(key, value) {
68
- if (currentSelector && key) {
69
- if (!selectors[currentSelector]) {
70
- selectors[currentSelector] = {};
71
- }
72
-
73
- selectors[currentSelector][key] = value;
74
- }
75
- }
76
-
77
- let currentKey = "";
78
- let currentValue = "";
79
- let inKey = true;
80
- let inValue = false;
81
- let inQuotedValue = false;
82
- let inSelector = true;
83
- let escaped = false;
84
- let quotedValueStartChar = "";
85
-
86
- for (let i = 0; i < cleanedHashString.length; i++) {
87
- const c = cleanedHashString[i];
88
- const nextChar = cleanedHashString?.[i + 1];
89
-
90
- if (c === "\\" && !escaped) {
91
- escaped = true;
92
- continue;
93
- }
94
-
95
- if (escaped) {
96
- if (inSelector) {
97
- currentSelector += c;
98
- } else if (inKey) {
99
- currentKey += c;
100
- } else if (inValue) {
101
- currentValue += c;
102
- }
103
- escaped = false;
104
- continue;
105
- }
106
-
107
- if (inQuotedValue && quotedValueStartChar !== c) {
108
- if (inSelector) {
109
- currentSelector += c;
110
- } else if (inKey) {
111
- currentKey += c;
112
- } else if (inValue) {
113
- currentValue += c;
114
- }
115
-
116
- continue;
117
- }
118
-
119
- if (c === ";" && inSelector) {
120
- inSelector = true;
121
- currentSelector = "";
122
- continue;
123
- }
124
-
125
- if (inSelector === true && c !== "(") {
126
- currentSelector += c;
127
- continue;
128
- }
129
-
130
- if (c === "(" && inSelector) {
131
- inSelector = false;
132
- inKey = true;
133
-
134
- currentKey = "";
135
- continue;
136
- }
137
-
138
- if (inKey === true && c !== "=") {
139
- currentKey += c;
140
- continue;
141
- }
142
-
143
- if (c === "=" && inKey) {
144
- inKey = false;
145
- inValue = true;
146
-
147
- if (nextChar === '"' || nextChar === "'") {
148
- inQuotedValue = true;
149
- quotedValueStartChar = nextChar;
150
- i++;
151
- continue;
152
- }
153
-
154
- currentValue = "";
155
- continue;
156
- }
157
-
158
- if (inValue === true) {
159
- if (inQuotedValue) {
160
- if (c === quotedValueStartChar) {
161
- inQuotedValue = false;
162
- continue;
163
- }
164
-
165
- currentValue += c;
166
- continue;
167
- }
168
-
169
- if (c === ",") {
170
- inValue = false;
171
- inKey = true;
172
- const decodedCurrentValue = decodeURIComponent(currentValue);
173
- addToResult(currentKey, decodedCurrentValue);
174
- currentKey = "";
175
- currentValue = "";
176
- continue;
177
- }
178
-
179
- if (c === ")") {
180
- inValue = false;
181
- //inKey = true;
182
- inSelector = true;
183
-
184
- const decodedCurrentValue = decodeURIComponent(currentValue);
185
- addToResult(currentKey, decodedCurrentValue);
186
- currentKey = "";
187
- currentValue = "";
188
- currentSelector = "";
189
- continue;
190
- }
191
-
192
- currentValue += c;
193
-
194
- continue;
195
- }
196
- }
197
-
198
- if (inSelector) {
199
- return selectors;
200
- }
201
-
202
- return {};
54
+ const selectors = {};
55
+ //const selectorStack = [];
56
+ //const keyValueStack = [];
57
+
58
+ const trimmedHashString = hashString.trim();
59
+ const cleanedHashString =
60
+ trimmedHashString.charAt(0) === "#"
61
+ ? trimmedHashString.slice(1)
62
+ : trimmedHashString;
63
+
64
+ //const selectors = (keyValueStack.length > 0) ? result[selectorStack[selectorStack.length - 1]] : result;
65
+ let currentSelector = "";
66
+
67
+ function addToResult(key, value) {
68
+ if (currentSelector && key) {
69
+ if (!selectors[currentSelector]) {
70
+ selectors[currentSelector] = {};
71
+ }
72
+
73
+ selectors[currentSelector][key] = value;
74
+ }
75
+ }
76
+
77
+ let currentKey = "";
78
+ let currentValue = "";
79
+ let inKey = true;
80
+ let inValue = false;
81
+ let inQuotedValue = false;
82
+ let inSelector = true;
83
+ let escaped = false;
84
+ let quotedValueStartChar = "";
85
+
86
+ for (let i = 0; i < cleanedHashString.length; i++) {
87
+ const c = cleanedHashString[i];
88
+ const nextChar = cleanedHashString?.[i + 1];
89
+
90
+ if (c === "\\" && !escaped) {
91
+ escaped = true;
92
+ continue;
93
+ }
94
+
95
+ if (escaped) {
96
+ if (inSelector) {
97
+ currentSelector += c;
98
+ } else if (inKey) {
99
+ currentKey += c;
100
+ } else if (inValue) {
101
+ currentValue += c;
102
+ }
103
+ escaped = false;
104
+ continue;
105
+ }
106
+
107
+ if (inQuotedValue && quotedValueStartChar !== c) {
108
+ if (inSelector) {
109
+ currentSelector += c;
110
+ } else if (inKey) {
111
+ currentKey += c;
112
+ } else if (inValue) {
113
+ currentValue += c;
114
+ }
115
+
116
+ continue;
117
+ }
118
+
119
+ if (c === ";" && inSelector) {
120
+ inSelector = true;
121
+ currentSelector = "";
122
+ continue;
123
+ }
124
+
125
+ if (inSelector === true && c !== "(") {
126
+ currentSelector += c;
127
+ continue;
128
+ }
129
+
130
+ if (c === "(" && inSelector) {
131
+ inSelector = false;
132
+ inKey = true;
133
+
134
+ currentKey = "";
135
+ continue;
136
+ }
137
+
138
+ if (inKey === true && c !== "=") {
139
+ currentKey += c;
140
+ continue;
141
+ }
142
+
143
+ if (c === "=" && inKey) {
144
+ inKey = false;
145
+ inValue = true;
146
+
147
+ if (nextChar === '"' || nextChar === "'") {
148
+ inQuotedValue = true;
149
+ quotedValueStartChar = nextChar;
150
+ i++;
151
+ continue;
152
+ }
153
+
154
+ currentValue = "";
155
+ continue;
156
+ }
157
+
158
+ if (inValue === true) {
159
+ if (inQuotedValue) {
160
+ if (c === quotedValueStartChar) {
161
+ inQuotedValue = false;
162
+ continue;
163
+ }
164
+
165
+ currentValue += c;
166
+ continue;
167
+ }
168
+
169
+ if (c === ",") {
170
+ inValue = false;
171
+ inKey = true;
172
+ const decodedCurrentValue = decodeURIComponent(currentValue);
173
+ addToResult(currentKey, decodedCurrentValue);
174
+ currentKey = "";
175
+ currentValue = "";
176
+ continue;
177
+ }
178
+
179
+ if (c === ")") {
180
+ inValue = false;
181
+ //inKey = true;
182
+ inSelector = true;
183
+
184
+ const decodedCurrentValue = decodeURIComponent(currentValue);
185
+ addToResult(currentKey, decodedCurrentValue);
186
+ currentKey = "";
187
+ currentValue = "";
188
+ currentSelector = "";
189
+ continue;
190
+ }
191
+
192
+ currentValue += c;
193
+
194
+ continue;
195
+ }
196
+ }
197
+
198
+ if (inSelector) {
199
+ return selectors;
200
+ }
201
+
202
+ return {};
203
203
  }
204
204
 
205
205
  /**
@@ -211,37 +211,41 @@ function parseBracketedKeyValueHash(hashString) {
211
211
  * @since 3.37.0
212
212
  */
213
213
  function createBracketedKeyValueHash(object, addHashPrefix = true) {
214
- if (!object) {
215
- return addHashPrefix ? "#" : "";
216
- }
217
-
218
- let hashString = "";
219
-
220
- function encodeKeyValue(key, value) {
221
- return encodeURIComponent(key) + "=" + encodeURIComponent(value);
222
- }
223
-
224
- for (const selector in object) {
225
- if (object.hasOwnProperty(selector)) {
226
- const keyValuePairs = object[selector];
227
- let selectorString = selector;
228
- let keyValueString = "";
229
-
230
- for (const key in keyValuePairs) {
231
- if (keyValuePairs.hasOwnProperty(key)) {
232
- const value = keyValuePairs[key];
233
- keyValueString += keyValueString.length === 0 ? "" : ",";
234
- keyValueString += encodeKeyValue(key, value);
235
- }
236
- }
237
-
238
- if (keyValueString.length > 0) {
239
- selectorString += "(" + keyValueString + ")";
240
- hashString += hashString.length === 0 ? "" : ";";
241
- hashString += selectorString;
242
- }
243
- }
244
- }
245
-
246
- return addHashPrefix ? "#" + hashString : hashString;
214
+ if (!object) {
215
+ return addHashPrefix ? "#" : "";
216
+ }
217
+
218
+ let hashString = "";
219
+
220
+ function encodeKeyValue(key, value) {
221
+ return encodeURIComponent(key) + "=" + encodeURIComponent(value);
222
+ }
223
+
224
+ for (const selector in object) {
225
+ if (object.hasOwnProperty(selector)) {
226
+ const keyValuePairs = object[selector];
227
+ let selectorString = selector;
228
+ let keyValueString = "";
229
+
230
+ for (const key in keyValuePairs) {
231
+ if (keyValuePairs.hasOwnProperty(key)) {
232
+ const value = keyValuePairs[key];
233
+ keyValueString += keyValueString.length === 0 ? "" : ",";
234
+ keyValueString += encodeKeyValue(key, value);
235
+ }
236
+ }
237
+
238
+ if (keyValueString.length > 0) {
239
+ selectorString += "(" + keyValueString + ")";
240
+ hashString += hashString.length === 0 ? "" : ";";
241
+ hashString += selectorString;
242
+ }
243
+ }
244
+ }
245
+
246
+ if (hashString.length>0 && addHashPrefix) {
247
+ hashString = "#" + hashString;
248
+ }
249
+
250
+ return hashString;
247
251
  }
@@ -156,7 +156,7 @@ function getMonsterVersion() {
156
156
  }
157
157
 
158
158
  /** don't touch, replaced by make with package.json version */
159
- monsterVersion = new Version("3.107.0");
159
+ monsterVersion = new Version("3.110.2");
160
160
 
161
161
  return monsterVersion;
162
162
  }
@@ -7,7 +7,7 @@ describe('Monster', function () {
7
7
  let monsterVersion
8
8
 
9
9
  /** don´t touch, replaced by make with package.json version */
10
- monsterVersion = new Version("3.107.0")
10
+ monsterVersion = new Version("3.110.2")
11
11
 
12
12
  let m = getMonsterVersion();
13
13
 
@@ -9,8 +9,8 @@
9
9
  </head>
10
10
  <body>
11
11
  <div id="headline" style="display: flex;align-items: center;justify-content: center;flex-direction: column;">
12
- <h1 style='margin-bottom: 0.1em;'>Monster 3.107.0</h1>
13
- <div id="lastupdate" style='font-size:0.7em'>last update Di 11. Feb 14:09:24 CET 2025</div>
12
+ <h1 style='margin-bottom: 0.1em;'>Monster 3.110.2</h1>
13
+ <div id="lastupdate" style='font-size:0.7em'>last update Mi 19. Feb 22:20:07 CET 2025</div>
14
14
  </div>
15
15
  <div id="mocha-errors"
16
16
  style="color: red;font-weight: bold;display: flex;align-items: center;justify-content: center;flex-direction: column;margin:20px;"></div>