@oscarpalmer/toretto 0.34.0 → 0.35.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 +77 -12
- package/package.json +5 -5
package/dist/toretto.full.js
CHANGED
|
@@ -53,12 +53,16 @@ function getString(value) {
|
|
|
53
53
|
const asString = String(value.valueOf?.() ?? value);
|
|
54
54
|
return asString.startsWith("[object ") ? JSON.stringify(value) : asString;
|
|
55
55
|
}
|
|
56
|
+
function ignoreKey(key) {
|
|
57
|
+
return EXPRESSION_IGNORED.test(key);
|
|
58
|
+
}
|
|
56
59
|
function join(value, delimiter) {
|
|
57
60
|
return compact(value).map(getString).join(typeof delimiter === "string" ? delimiter : "");
|
|
58
61
|
}
|
|
59
62
|
function words(value) {
|
|
60
63
|
return typeof value === "string" ? value.match(EXPRESSION_WORDS) ?? [] : [];
|
|
61
64
|
}
|
|
65
|
+
var EXPRESSION_IGNORED = /(^|\.)(__proto__|constructor|prototype)(\.|$)/i;
|
|
62
66
|
var EXPRESSION_WORDS = /[^\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\x7f]+/g;
|
|
63
67
|
function isNullableOrWhitespace(value) {
|
|
64
68
|
return value == null || EXPRESSION_WHITESPACE$1.test(getString(value));
|
|
@@ -237,7 +241,7 @@ function calculate() {
|
|
|
237
241
|
var TOTAL = 10;
|
|
238
242
|
var TRIM_PART = 2;
|
|
239
243
|
var TRIM_TOTAL = 4;
|
|
240
|
-
|
|
244
|
+
calculate().then((value) => {});
|
|
241
245
|
function clamp(value, minimum, maximum, loop) {
|
|
242
246
|
if (![
|
|
243
247
|
value,
|
|
@@ -399,6 +403,67 @@ function parse(value, reviver) {
|
|
|
399
403
|
return;
|
|
400
404
|
}
|
|
401
405
|
}
|
|
406
|
+
function findKey(needle, haystack) {
|
|
407
|
+
const keys = Object.keys(haystack);
|
|
408
|
+
const index = keys.map((key) => key.toLowerCase()).indexOf(needle.toLowerCase());
|
|
409
|
+
return index > -1 ? keys[index] : needle;
|
|
410
|
+
}
|
|
411
|
+
function getPaths(path, lowercase) {
|
|
412
|
+
const normalized = lowercase ? path.toLowerCase() : path;
|
|
413
|
+
if (!EXPRESSION_NESTED.test(normalized)) return normalized;
|
|
414
|
+
return normalized.replace(EXPRESSION_BRACKET, ".$1").replace(EXPRESSION_DOTS, "").split(".");
|
|
415
|
+
}
|
|
416
|
+
function handleValue(data, path, value, get, ignoreCase) {
|
|
417
|
+
if (typeof data === "object" && data !== null && !ignoreKey(path)) {
|
|
418
|
+
const key = ignoreCase ? findKey(path, data) : path;
|
|
419
|
+
if (get) return data[key];
|
|
420
|
+
data[key] = value;
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
var EXPRESSION_BRACKET = /\[(\w+)\]/g;
|
|
424
|
+
var EXPRESSION_DOTS = /^\.|\.$/g;
|
|
425
|
+
var EXPRESSION_NESTED = /\.|\[\w+\]/;
|
|
426
|
+
function getValue(data, path, ignoreCase) {
|
|
427
|
+
if (typeof data !== "object" || data === null || typeof path !== "string" || path.trim().length === 0) return;
|
|
428
|
+
const shouldIgnoreCase = ignoreCase === true;
|
|
429
|
+
const paths = getPaths(path, shouldIgnoreCase);
|
|
430
|
+
if (typeof paths === "string") return handleValue(data, paths, null, true, shouldIgnoreCase);
|
|
431
|
+
const { length } = paths;
|
|
432
|
+
let index = 0;
|
|
433
|
+
let value = data;
|
|
434
|
+
while (index < length && value != null) value = handleValue(value, paths[index++], null, true, shouldIgnoreCase);
|
|
435
|
+
return value;
|
|
436
|
+
}
|
|
437
|
+
function getTemplateOptions(input) {
|
|
438
|
+
const options = isPlainObject(input) ? input : {};
|
|
439
|
+
return {
|
|
440
|
+
ignoreCase: options.ignoreCase === true,
|
|
441
|
+
pattern: options.pattern instanceof RegExp ? options.pattern : EXPRESSION_VARIABLE
|
|
442
|
+
};
|
|
443
|
+
}
|
|
444
|
+
function handleTemplate(value, pattern, ignoreCase, variables) {
|
|
445
|
+
if (typeof value !== "string") return "";
|
|
446
|
+
if (typeof variables !== "object" || variables === null) return value;
|
|
447
|
+
const values = {};
|
|
448
|
+
return value.replace(pattern, (_, key) => {
|
|
449
|
+
if (values[key] == null) {
|
|
450
|
+
const templateValue = getValue(variables, key, ignoreCase);
|
|
451
|
+
values[key] = templateValue == null ? "" : getString(templateValue);
|
|
452
|
+
}
|
|
453
|
+
return values[key];
|
|
454
|
+
});
|
|
455
|
+
}
|
|
456
|
+
function template(value, variables, options) {
|
|
457
|
+
const { ignoreCase, pattern } = getTemplateOptions(options);
|
|
458
|
+
return handleTemplate(value, pattern, ignoreCase, variables);
|
|
459
|
+
}
|
|
460
|
+
template.initialize = function(options) {
|
|
461
|
+
const { ignoreCase, pattern } = getTemplateOptions(options);
|
|
462
|
+
return (value, variables) => {
|
|
463
|
+
return handleTemplate(value, pattern, ignoreCase, variables);
|
|
464
|
+
};
|
|
465
|
+
};
|
|
466
|
+
var EXPRESSION_VARIABLE = /{{([\s\S]+?)}}/g;
|
|
402
467
|
function getBoolean(value, defaultValue) {
|
|
403
468
|
return typeof value === "boolean" ? value : defaultValue ?? false;
|
|
404
469
|
}
|
|
@@ -917,18 +982,18 @@ function createHtml(value) {
|
|
|
917
982
|
return parsed.body.innerHTML;
|
|
918
983
|
}
|
|
919
984
|
function createTemplate(value, options) {
|
|
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;
|
|
985
|
+
const template$1 = document.createElement(TEMPLATE_TAG);
|
|
986
|
+
template$1.innerHTML = createHtml(value);
|
|
987
|
+
if (typeof value === "string" && options.cache) templates[value] = template$1;
|
|
988
|
+
return template$1;
|
|
924
989
|
}
|
|
925
990
|
function getHtml(value) {
|
|
926
991
|
return `${TEMPORARY_ELEMENT}${typeof value === "string" ? value : value.innerHTML}${TEMPORARY_ELEMENT}`;
|
|
927
992
|
}
|
|
928
993
|
function getNodes(value, options) {
|
|
929
994
|
if (typeof value !== "string" && !(value instanceof HTMLTemplateElement)) return [];
|
|
930
|
-
const template = getTemplate(value, options);
|
|
931
|
-
return template == null ? [] : [...template.content.cloneNode(true).childNodes];
|
|
995
|
+
const template$1 = getTemplate(value, options);
|
|
996
|
+
return template$1 == null ? [] : [...template$1.content.cloneNode(true).childNodes];
|
|
932
997
|
}
|
|
933
998
|
function getOptions(input) {
|
|
934
999
|
const options = isPlainObject(input) ? input : {};
|
|
@@ -942,8 +1007,8 @@ function getParser() {
|
|
|
942
1007
|
function getTemplate(value, options) {
|
|
943
1008
|
if (value instanceof HTMLTemplateElement) return createTemplate(value, options);
|
|
944
1009
|
if (value.trim().length === 0) return;
|
|
945
|
-
let template = templates[value];
|
|
946
|
-
if (template != null) return template;
|
|
1010
|
+
let template$1 = templates[value];
|
|
1011
|
+
if (template$1 != null) return template$1;
|
|
947
1012
|
const element = EXPRESSION_ID.test(value) ? document.querySelector(`#${value}`) : null;
|
|
948
1013
|
return createTemplate(element instanceof HTMLTemplateElement ? element : value, options);
|
|
949
1014
|
}
|
|
@@ -953,14 +1018,14 @@ const html = ((value, options) => {
|
|
|
953
1018
|
html.clear = () => {
|
|
954
1019
|
templates = {};
|
|
955
1020
|
};
|
|
956
|
-
html.remove = (template) => {
|
|
957
|
-
if (typeof template !== "string" || templates[template] == null) return;
|
|
1021
|
+
html.remove = (template$1) => {
|
|
1022
|
+
if (typeof template$1 !== "string" || templates[template$1] == null) return;
|
|
958
1023
|
const keys = Object.keys(templates);
|
|
959
1024
|
const { length } = keys;
|
|
960
1025
|
const updated = {};
|
|
961
1026
|
for (let index = 0; index < length; index += 1) {
|
|
962
1027
|
const key = keys[index];
|
|
963
|
-
if (key !== template) updated[key] = templates[key];
|
|
1028
|
+
if (key !== template$1) updated[key] = templates[key];
|
|
964
1029
|
}
|
|
965
1030
|
templates = updated;
|
|
966
1031
|
};
|
package/package.json
CHANGED
|
@@ -4,16 +4,16 @@
|
|
|
4
4
|
"url": "https://oscarpalmer.se"
|
|
5
5
|
},
|
|
6
6
|
"dependencies": {
|
|
7
|
-
"@oscarpalmer/atoms": "^0.
|
|
7
|
+
"@oscarpalmer/atoms": "^0.127"
|
|
8
8
|
},
|
|
9
9
|
"description": "A collection of badass DOM utilities.",
|
|
10
10
|
"devDependencies": {
|
|
11
11
|
"@types/node": "^25",
|
|
12
12
|
"@vitest/coverage-istanbul": "^4",
|
|
13
13
|
"jsdom": "^27.4",
|
|
14
|
-
"oxfmt": "^0.
|
|
15
|
-
"oxlint": "^1.
|
|
16
|
-
"rolldown": "1.0.0-beta.
|
|
14
|
+
"oxfmt": "^0.22",
|
|
15
|
+
"oxlint": "^1.38",
|
|
16
|
+
"rolldown": "1.0.0-beta.58",
|
|
17
17
|
"tslib": "^2.8",
|
|
18
18
|
"typescript": "^5.9",
|
|
19
19
|
"vite": "8.0.0-beta.5",
|
|
@@ -93,5 +93,5 @@
|
|
|
93
93
|
},
|
|
94
94
|
"type": "module",
|
|
95
95
|
"types": "types/index.d.ts",
|
|
96
|
-
"version": "0.
|
|
96
|
+
"version": "0.35.0"
|
|
97
97
|
}
|