structured-fw 1.7.7 → 1.7.8
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/build/system/Util.d.ts
CHANGED
|
@@ -20,12 +20,13 @@ export declare function fromSerializableValue(data: SerializableUint8Array): Uin
|
|
|
20
20
|
export declare function fromSerializableValue(data: Serializable): any;
|
|
21
21
|
export declare function serializableObject(data: LooseObject): LooseObject;
|
|
22
22
|
export declare function deserializeObject(data: LooseObject): LooseObject;
|
|
23
|
+
export declare function escapeAttributeValue(value: string): string;
|
|
24
|
+
export declare function unescapeAttributeValue(str: string): string;
|
|
23
25
|
export declare function attributeValueToString(key: string, value: any): string;
|
|
24
26
|
export declare function attributeValueFromString(attributeValue: string): string | {
|
|
25
27
|
key: string;
|
|
26
28
|
value: any;
|
|
27
29
|
};
|
|
28
|
-
export declare function attributeValueEscape(str: string): string;
|
|
29
30
|
export declare function isObject(value: any): boolean;
|
|
30
31
|
export declare function equalDeep(a: LooseObject, b: LooseObject): boolean;
|
|
31
32
|
export declare function mergeDeep(target: any, ...sources: Array<any>): LooseObject;
|
package/build/system/Util.js
CHANGED
|
@@ -226,33 +226,24 @@ export function stripTags(contentWithHTML, keepTags = []) {
|
|
|
226
226
|
return sub.replaceAll('<', '<').replaceAll('>', '>');
|
|
227
227
|
});
|
|
228
228
|
}
|
|
229
|
-
function base64ToBytes(base64) {
|
|
230
|
-
const binString = atob(base64);
|
|
231
|
-
return Uint8Array.from(binString, (m) => m.codePointAt(0));
|
|
232
|
-
}
|
|
233
|
-
function bytesToBase64(bytes) {
|
|
234
|
-
return btoa(bytes.reduce((prev, curr) => {
|
|
235
|
-
return prev + String.fromCharCode(curr);
|
|
236
|
-
}, ''));
|
|
237
|
-
}
|
|
238
229
|
export function toSerializableValue(value) {
|
|
239
230
|
if (value instanceof Date) {
|
|
240
231
|
return {
|
|
241
|
-
|
|
232
|
+
__sv: 1,
|
|
242
233
|
type: 'date',
|
|
243
234
|
value: value.toISOString(),
|
|
244
235
|
};
|
|
245
236
|
}
|
|
246
237
|
if (typeof value === 'bigint') {
|
|
247
238
|
return {
|
|
248
|
-
|
|
239
|
+
__sv: 1,
|
|
249
240
|
type: 'bigint',
|
|
250
241
|
value: value.toString(),
|
|
251
242
|
};
|
|
252
243
|
}
|
|
253
244
|
if (value instanceof RegExp) {
|
|
254
245
|
return {
|
|
255
|
-
|
|
246
|
+
__sv: 1,
|
|
256
247
|
type: 'regexp',
|
|
257
248
|
value: {
|
|
258
249
|
source: value.source,
|
|
@@ -262,20 +253,20 @@ export function toSerializableValue(value) {
|
|
|
262
253
|
}
|
|
263
254
|
if (value instanceof Map) {
|
|
264
255
|
return {
|
|
265
|
-
|
|
256
|
+
__sv: 1,
|
|
266
257
|
type: 'map',
|
|
267
258
|
value: [...value.entries()],
|
|
268
259
|
};
|
|
269
260
|
}
|
|
270
261
|
if (value instanceof Uint8Array) {
|
|
271
262
|
return {
|
|
272
|
-
|
|
263
|
+
__sv: 1,
|
|
273
264
|
type: 'uint8array',
|
|
274
265
|
value: Array.from(value),
|
|
275
266
|
};
|
|
276
267
|
}
|
|
277
268
|
return {
|
|
278
|
-
|
|
269
|
+
__sv: 1,
|
|
279
270
|
value,
|
|
280
271
|
};
|
|
281
272
|
}
|
|
@@ -316,7 +307,7 @@ export function deserializeObject(data) {
|
|
|
316
307
|
const copy = {};
|
|
317
308
|
objectEach(data, (key, val) => {
|
|
318
309
|
if (typeof val === 'object' && val !== null && val !== undefined) {
|
|
319
|
-
if ('
|
|
310
|
+
if ('__sv' in val) {
|
|
320
311
|
copy[key] = fromSerializableValue(val);
|
|
321
312
|
}
|
|
322
313
|
else {
|
|
@@ -329,17 +320,26 @@ export function deserializeObject(data) {
|
|
|
329
320
|
});
|
|
330
321
|
return copy;
|
|
331
322
|
}
|
|
323
|
+
export function escapeAttributeValue(value) {
|
|
324
|
+
return value
|
|
325
|
+
.replace(/~/g, '~~')
|
|
326
|
+
.replace(/"/g, '~q');
|
|
327
|
+
}
|
|
328
|
+
export function unescapeAttributeValue(str) {
|
|
329
|
+
const tempToken = `--${randomString(10)}--`;
|
|
330
|
+
return str
|
|
331
|
+
.split('~~').join(tempToken)
|
|
332
|
+
.split('~q').join('"')
|
|
333
|
+
.split(tempToken).join('~');
|
|
334
|
+
}
|
|
332
335
|
export function attributeValueToString(key, value) {
|
|
333
336
|
const data = serializableObject({ key, data: value });
|
|
334
|
-
return
|
|
337
|
+
return escapeAttributeValue(JSON.stringify(data));
|
|
335
338
|
}
|
|
336
339
|
export function attributeValueFromString(attributeValue) {
|
|
337
|
-
if (attributeValue.indexOf('
|
|
340
|
+
if (attributeValue.indexOf('{') === 0) {
|
|
338
341
|
try {
|
|
339
|
-
const decoded =
|
|
340
|
-
if (decoded.indexOf('{') !== 0) {
|
|
341
|
-
return attributeValue;
|
|
342
|
-
}
|
|
342
|
+
const decoded = unescapeAttributeValue(attributeValue);
|
|
343
343
|
const valObj = deserializeObject(JSON.parse(decoded));
|
|
344
344
|
if (!('key' in valObj)) {
|
|
345
345
|
return decoded;
|
|
@@ -355,9 +355,6 @@ export function attributeValueFromString(attributeValue) {
|
|
|
355
355
|
}
|
|
356
356
|
return attributeValue;
|
|
357
357
|
}
|
|
358
|
-
export function attributeValueEscape(str) {
|
|
359
|
-
return str.replaceAll('"', '"');
|
|
360
|
-
}
|
|
361
358
|
export function isObject(value) {
|
|
362
359
|
if (value === null || typeof value !== 'object')
|
|
363
360
|
return false;
|
|
@@ -40,16 +40,16 @@ export type ComponentEvents = {
|
|
|
40
40
|
ready: undefined;
|
|
41
41
|
};
|
|
42
42
|
export type Serializable = {
|
|
43
|
-
|
|
43
|
+
__sv: 1;
|
|
44
44
|
value: any;
|
|
45
45
|
};
|
|
46
46
|
export type SerializableDate = {
|
|
47
|
-
|
|
47
|
+
__sv: 1;
|
|
48
48
|
type: 'date';
|
|
49
49
|
value: string;
|
|
50
50
|
};
|
|
51
51
|
export type SerializableRegExp = {
|
|
52
|
-
|
|
52
|
+
__sv: 1;
|
|
53
53
|
type: 'regexp';
|
|
54
54
|
value: {
|
|
55
55
|
source: string;
|
|
@@ -57,17 +57,17 @@ export type SerializableRegExp = {
|
|
|
57
57
|
};
|
|
58
58
|
};
|
|
59
59
|
export type SerializableMap = {
|
|
60
|
-
|
|
60
|
+
__sv: 1;
|
|
61
61
|
type: 'map';
|
|
62
62
|
value: Array<[any, any]>;
|
|
63
63
|
};
|
|
64
64
|
export type SerializableBigInt = {
|
|
65
|
-
|
|
65
|
+
__sv: 1;
|
|
66
66
|
type: 'bigint';
|
|
67
67
|
value: string;
|
|
68
68
|
};
|
|
69
69
|
export type SerializableUint8Array = {
|
|
70
|
-
|
|
70
|
+
__sv: 1;
|
|
71
71
|
type: 'uint8array';
|
|
72
72
|
value: Array<number>;
|
|
73
73
|
};
|
package/package.json
CHANGED
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"license": "MIT",
|
|
20
20
|
"type": "module",
|
|
21
21
|
"main": "build/index",
|
|
22
|
-
"version": "1.7.
|
|
22
|
+
"version": "1.7.8",
|
|
23
23
|
"scripts": {
|
|
24
24
|
"develop": "tsc --watch",
|
|
25
25
|
"startDev": "cd build && nodemon --watch '../app/**/*' --watch '../build/**/*' -e js,html,hbs,css index.js",
|