@oscarpalmer/toretto 0.33.0 → 0.34.0
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/dist/toretto.full.js +17 -99
- package/package.json +2 -2
package/dist/toretto.full.js
CHANGED
|
@@ -34,19 +34,6 @@ function isPlainObject(value) {
|
|
|
34
34
|
const prototype = Object.getPrototypeOf(value);
|
|
35
35
|
return prototype === null || prototype === Object.prototype || Object.getPrototypeOf(prototype) === null;
|
|
36
36
|
}
|
|
37
|
-
new Set([
|
|
38
|
-
Int8Array,
|
|
39
|
-
Uint8Array,
|
|
40
|
-
Uint8ClampedArray,
|
|
41
|
-
Int16Array,
|
|
42
|
-
Uint16Array,
|
|
43
|
-
Int32Array,
|
|
44
|
-
Uint32Array,
|
|
45
|
-
Float32Array,
|
|
46
|
-
Float64Array,
|
|
47
|
-
BigInt64Array,
|
|
48
|
-
BigUint64Array
|
|
49
|
-
]);
|
|
50
37
|
function compact(array, strict) {
|
|
51
38
|
if (!Array.isArray(array)) return [];
|
|
52
39
|
if (strict === true) return array.filter(Boolean);
|
|
@@ -66,16 +53,12 @@ function getString(value) {
|
|
|
66
53
|
const asString = String(value.valueOf?.() ?? value);
|
|
67
54
|
return asString.startsWith("[object ") ? JSON.stringify(value) : asString;
|
|
68
55
|
}
|
|
69
|
-
function ignoreKey(key) {
|
|
70
|
-
return EXPRESSION_IGNORED.test(key);
|
|
71
|
-
}
|
|
72
56
|
function join(value, delimiter) {
|
|
73
57
|
return compact(value).map(getString).join(typeof delimiter === "string" ? delimiter : "");
|
|
74
58
|
}
|
|
75
59
|
function words(value) {
|
|
76
60
|
return typeof value === "string" ? value.match(EXPRESSION_WORDS) ?? [] : [];
|
|
77
61
|
}
|
|
78
|
-
var EXPRESSION_IGNORED = /(^|\.)(__proto__|constructor|prototype)(\.|$)/i;
|
|
79
62
|
var EXPRESSION_WORDS = /[^\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\x7f]+/g;
|
|
80
63
|
function isNullableOrWhitespace(value) {
|
|
81
64
|
return value == null || EXPRESSION_WHITESPACE$1.test(getString(value));
|
|
@@ -357,7 +340,7 @@ function memoize(callback, options) {
|
|
|
357
340
|
}
|
|
358
341
|
var DEFAULT_CACHE_SIZE = 1024;
|
|
359
342
|
function camelCase(value) {
|
|
360
|
-
return toCase(
|
|
343
|
+
return toCase("camel", value, true, false);
|
|
361
344
|
}
|
|
362
345
|
function capitalize(value) {
|
|
363
346
|
if (typeof value !== "string" || value.length === 0) return "";
|
|
@@ -365,7 +348,7 @@ function capitalize(value) {
|
|
|
365
348
|
return memoizedCapitalize.run(value);
|
|
366
349
|
}
|
|
367
350
|
function kebabCase(value) {
|
|
368
|
-
return toCase(
|
|
351
|
+
return toCase("kebab", value, false, false);
|
|
369
352
|
}
|
|
370
353
|
function toCase(type, value, capitalizeAny, capitalizeFirst) {
|
|
371
354
|
memoizers[type] ??= memoize(toCaseCallback.bind({
|
|
@@ -401,15 +384,11 @@ function toCaseCallback(value) {
|
|
|
401
384
|
var EXPRESSION_CAMEL_CASE = /(\p{Ll})(\p{Lu})/gu;
|
|
402
385
|
var EXPRESSION_ACRONYM = /(\p{Lu}*)(\p{Lu})(\p{Ll}+)/gu;
|
|
403
386
|
var REPLACEMENT_CAMEL_CASE = "$1-$2";
|
|
404
|
-
var TYPE_CAMEL = "camel";
|
|
405
|
-
var TYPE_KEBAB = "kebab";
|
|
406
|
-
var TYPE_PASCAL = "pascal";
|
|
407
|
-
var TYPE_SNAKE = "snake";
|
|
408
387
|
var delimiters = {
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
388
|
+
camel: "",
|
|
389
|
+
kebab: "-",
|
|
390
|
+
pascal: "",
|
|
391
|
+
snake: "_"
|
|
413
392
|
};
|
|
414
393
|
var memoizers = {};
|
|
415
394
|
var memoizedCapitalize;
|
|
@@ -420,67 +399,6 @@ function parse(value, reviver) {
|
|
|
420
399
|
return;
|
|
421
400
|
}
|
|
422
401
|
}
|
|
423
|
-
function findKey(needle, haystack) {
|
|
424
|
-
const keys = Object.keys(haystack);
|
|
425
|
-
const index = keys.map((key) => key.toLowerCase()).indexOf(needle.toLowerCase());
|
|
426
|
-
return index > -1 ? keys[index] : needle;
|
|
427
|
-
}
|
|
428
|
-
function getPaths(path, lowercase) {
|
|
429
|
-
const normalized = lowercase ? path.toLowerCase() : path;
|
|
430
|
-
if (!EXPRESSION_NESTED.test(normalized)) return normalized;
|
|
431
|
-
return normalized.replace(EXPRESSION_BRACKET, ".$1").replace(EXPRESSION_DOTS, "").split(".");
|
|
432
|
-
}
|
|
433
|
-
function handleValue(data, path, value, get, ignoreCase) {
|
|
434
|
-
if (typeof data === "object" && data !== null && !ignoreKey(path)) {
|
|
435
|
-
const key = ignoreCase ? findKey(path, data) : path;
|
|
436
|
-
if (get) return data[key];
|
|
437
|
-
data[key] = value;
|
|
438
|
-
}
|
|
439
|
-
}
|
|
440
|
-
var EXPRESSION_BRACKET = /\[(\w+)\]/g;
|
|
441
|
-
var EXPRESSION_DOTS = /^\.|\.$/g;
|
|
442
|
-
var EXPRESSION_NESTED = /\.|\[\w+\]/;
|
|
443
|
-
function getValue(data, path, ignoreCase) {
|
|
444
|
-
if (typeof data !== "object" || data === null || typeof path !== "string" || path.trim().length === 0) return;
|
|
445
|
-
const shouldIgnoreCase = ignoreCase === true;
|
|
446
|
-
const paths = getPaths(path, shouldIgnoreCase);
|
|
447
|
-
if (typeof paths === "string") return handleValue(data, paths, null, true, shouldIgnoreCase);
|
|
448
|
-
const { length } = paths;
|
|
449
|
-
let index = 0;
|
|
450
|
-
let value = data;
|
|
451
|
-
while (index < length && value != null) value = handleValue(value, paths[index++], null, true, shouldIgnoreCase);
|
|
452
|
-
return value;
|
|
453
|
-
}
|
|
454
|
-
function getTemplateOptions(input) {
|
|
455
|
-
const options = isPlainObject(input) ? input : {};
|
|
456
|
-
return {
|
|
457
|
-
ignoreCase: options.ignoreCase === true,
|
|
458
|
-
pattern: options.pattern instanceof RegExp ? options.pattern : EXPRESSION_VARIABLE
|
|
459
|
-
};
|
|
460
|
-
}
|
|
461
|
-
function handleTemplate(value, pattern, ignoreCase, variables) {
|
|
462
|
-
if (typeof value !== "string") return "";
|
|
463
|
-
if (typeof variables !== "object" || variables === null) return value;
|
|
464
|
-
const values = {};
|
|
465
|
-
return value.replace(pattern, (_, key) => {
|
|
466
|
-
if (values[key] == null) {
|
|
467
|
-
const templateValue = getValue(variables, key, ignoreCase);
|
|
468
|
-
values[key] = templateValue == null ? "" : getString(templateValue);
|
|
469
|
-
}
|
|
470
|
-
return values[key];
|
|
471
|
-
});
|
|
472
|
-
}
|
|
473
|
-
var template = ((value, variables, options) => {
|
|
474
|
-
const { ignoreCase, pattern } = getTemplateOptions(options);
|
|
475
|
-
return handleTemplate(value, pattern, ignoreCase, variables);
|
|
476
|
-
});
|
|
477
|
-
template.initialize = (options) => {
|
|
478
|
-
const { ignoreCase, pattern } = getTemplateOptions(options);
|
|
479
|
-
return (value, variables) => {
|
|
480
|
-
return handleTemplate(value, pattern, ignoreCase, variables);
|
|
481
|
-
};
|
|
482
|
-
};
|
|
483
|
-
var EXPRESSION_VARIABLE = /{{([\s\S]+?)}}/g;
|
|
484
402
|
function getBoolean(value, defaultValue) {
|
|
485
403
|
return typeof value === "boolean" ? value : defaultValue ?? false;
|
|
486
404
|
}
|
|
@@ -999,18 +917,18 @@ function createHtml(value) {
|
|
|
999
917
|
return parsed.body.innerHTML;
|
|
1000
918
|
}
|
|
1001
919
|
function createTemplate(value, options) {
|
|
1002
|
-
const template
|
|
1003
|
-
template
|
|
1004
|
-
if (typeof value === "string" && options.cache) templates[value] = template
|
|
1005
|
-
return template
|
|
920
|
+
const template = document.createElement(TEMPLATE_TAG);
|
|
921
|
+
template.innerHTML = createHtml(value);
|
|
922
|
+
if (typeof value === "string" && options.cache) templates[value] = template;
|
|
923
|
+
return template;
|
|
1006
924
|
}
|
|
1007
925
|
function getHtml(value) {
|
|
1008
926
|
return `${TEMPORARY_ELEMENT}${typeof value === "string" ? value : value.innerHTML}${TEMPORARY_ELEMENT}`;
|
|
1009
927
|
}
|
|
1010
928
|
function getNodes(value, options) {
|
|
1011
929
|
if (typeof value !== "string" && !(value instanceof HTMLTemplateElement)) return [];
|
|
1012
|
-
const template
|
|
1013
|
-
return template
|
|
930
|
+
const template = getTemplate(value, options);
|
|
931
|
+
return template == null ? [] : [...template.content.cloneNode(true).childNodes];
|
|
1014
932
|
}
|
|
1015
933
|
function getOptions(input) {
|
|
1016
934
|
const options = isPlainObject(input) ? input : {};
|
|
@@ -1024,8 +942,8 @@ function getParser() {
|
|
|
1024
942
|
function getTemplate(value, options) {
|
|
1025
943
|
if (value instanceof HTMLTemplateElement) return createTemplate(value, options);
|
|
1026
944
|
if (value.trim().length === 0) return;
|
|
1027
|
-
let template
|
|
1028
|
-
if (template
|
|
945
|
+
let template = templates[value];
|
|
946
|
+
if (template != null) return template;
|
|
1029
947
|
const element = EXPRESSION_ID.test(value) ? document.querySelector(`#${value}`) : null;
|
|
1030
948
|
return createTemplate(element instanceof HTMLTemplateElement ? element : value, options);
|
|
1031
949
|
}
|
|
@@ -1035,14 +953,14 @@ const html = ((value, options) => {
|
|
|
1035
953
|
html.clear = () => {
|
|
1036
954
|
templates = {};
|
|
1037
955
|
};
|
|
1038
|
-
html.remove = (template
|
|
1039
|
-
if (typeof template
|
|
956
|
+
html.remove = (template) => {
|
|
957
|
+
if (typeof template !== "string" || templates[template] == null) return;
|
|
1040
958
|
const keys = Object.keys(templates);
|
|
1041
959
|
const { length } = keys;
|
|
1042
960
|
const updated = {};
|
|
1043
961
|
for (let index = 0; index < length; index += 1) {
|
|
1044
962
|
const key = keys[index];
|
|
1045
|
-
if (key !== template
|
|
963
|
+
if (key !== template) updated[key] = templates[key];
|
|
1046
964
|
}
|
|
1047
965
|
templates = updated;
|
|
1048
966
|
};
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"url": "https://oscarpalmer.se"
|
|
5
5
|
},
|
|
6
6
|
"dependencies": {
|
|
7
|
-
"@oscarpalmer/atoms": "^0.
|
|
7
|
+
"@oscarpalmer/atoms": "^0.124"
|
|
8
8
|
},
|
|
9
9
|
"description": "A collection of badass DOM utilities.",
|
|
10
10
|
"devDependencies": {
|
|
@@ -93,5 +93,5 @@
|
|
|
93
93
|
},
|
|
94
94
|
"type": "module",
|
|
95
95
|
"types": "types/index.d.ts",
|
|
96
|
-
"version": "0.
|
|
96
|
+
"version": "0.34.0"
|
|
97
97
|
}
|