@twobirds/microcomponents 0.0.80 → 0.0.82
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/MC.js +379 -0
- package/dist/McEvent.js +71 -0
- package/dist/elements.js +48 -0
- package/dist/formValues.js +162 -0
- package/dist/helpers.js +113 -0
- package/dist/microcomponents.js +8 -1115
- package/dist/observables.js +249 -0
- package/dist/selectors.js +971 -0
- package/package.json +2 -2
- package/public/typedoc/classes/MC.DC.html +2 -2
- package/public/typedoc/classes/MC.MC.html +2 -2
- package/public/typedoc/classes/MC.McBase.html +2 -2
- package/public/typedoc/classes/MC.McEvent.html +2 -2
- package/public/typedoc/functions/MC.addListener.html +1 -1
- package/public/typedoc/functions/MC.autoload.html +1 -1
- package/public/typedoc/functions/MC.removeListener.html +1 -1
- package/public/typedoc/functions/elements.defineCE.html +1 -1
- package/public/typedoc/functions/elements.getCE.html +1 -1
- package/public/typedoc/functions/formValues.formValues.html +1 -1
- package/public/typedoc/functions/observables.observe.html +1 -1
- package/public/typedoc/interfaces/MC.HTMLMcElement.html +2 -2
- package/public/typedoc/modules/MC.html +1 -1
- package/public/typedoc/modules/elements.html +1 -1
- package/public/typedoc/modules/formValues.html +1 -1
- package/public/typedoc/modules/observables.html +1 -1
- package/public/typedoc/types/observables.Observable.html +1 -1
- package/webpack.config.js +0 -38
package/dist/helpers.js
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
export function isNativeObject(value) {
|
|
3
|
+
return value && value['constructor'] && value.constructor === Object;
|
|
4
|
+
}
|
|
5
|
+
export function sortObject(o) {
|
|
6
|
+
let result = {}, keys = [...Object.keys(o)].sort();
|
|
7
|
+
keys.forEach((key) => {
|
|
8
|
+
if (isNativeObject(o[key])) {
|
|
9
|
+
result[key] = sortObject(o[key]);
|
|
10
|
+
}
|
|
11
|
+
else {
|
|
12
|
+
result[key] = o[key];
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
return result;
|
|
16
|
+
}
|
|
17
|
+
export function flattenObject(o, doSort = true) {
|
|
18
|
+
let result = {};
|
|
19
|
+
[...Object.getOwnPropertyNames(o)].forEach((propName) => {
|
|
20
|
+
if (o[propName] &&
|
|
21
|
+
o[propName]['constructor'] &&
|
|
22
|
+
o[propName].constructor === Object) {
|
|
23
|
+
const temp = flattenObject(o[propName], false);
|
|
24
|
+
for (const j in temp) {
|
|
25
|
+
result[propName + '.' + j] = temp[j];
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
result[propName] = o[propName];
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
return doSort ? sortObject(result) : result;
|
|
33
|
+
}
|
|
34
|
+
export function deepEqual(o1, o2) {
|
|
35
|
+
return (JSON.stringify(flattenObject(o1)) === JSON.stringify(flattenObject(o2)));
|
|
36
|
+
}
|
|
37
|
+
export function nameSpace(ns, obj = {}) {
|
|
38
|
+
let nsa = ns.constructor === String ? ns.split('.') : ns;
|
|
39
|
+
if (!obj || !nsa[0] || !obj[nsa[0]]) {
|
|
40
|
+
console.warn('ns', nsa[0], 'not in', obj);
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
if (obj[nsa[0]].constructor === Object && nsa.length > 1) {
|
|
44
|
+
return nameSpace(nsa.splice(1), obj[nsa[0]]);
|
|
45
|
+
}
|
|
46
|
+
return obj[nsa[0]];
|
|
47
|
+
}
|
|
48
|
+
export function parse(what, parseThis) {
|
|
49
|
+
var args = Array.from(arguments);
|
|
50
|
+
if (args.length > 2) {
|
|
51
|
+
while (args.length > 1) {
|
|
52
|
+
args[0] = parse(args[0], args[1]);
|
|
53
|
+
args.splice(1, 1);
|
|
54
|
+
}
|
|
55
|
+
return args[0];
|
|
56
|
+
}
|
|
57
|
+
if (typeof what === 'string') {
|
|
58
|
+
what.match(/\{[^\{\}]*\}/g)?.forEach(function (pPropname) {
|
|
59
|
+
var propname = pPropname.substring(1, pPropname.length - 1), value = nameSpace(propname, parseThis);
|
|
60
|
+
if (typeof value !== 'undefined') {
|
|
61
|
+
what = what.replace(pPropname, value);
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
else if (isNativeObject(what)) {
|
|
66
|
+
switch (what.constructor) {
|
|
67
|
+
case Object:
|
|
68
|
+
Object.keys(what).forEach(function (pKey) {
|
|
69
|
+
if (what.hasOwnProperty(pKey)) {
|
|
70
|
+
what[pKey] = parse(what[pKey], parseThis);
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
break;
|
|
74
|
+
case Array:
|
|
75
|
+
what.forEach(function (pValue, pKey, original) {
|
|
76
|
+
original[pKey] = parse(what[pKey], parseThis);
|
|
77
|
+
});
|
|
78
|
+
break;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
return what;
|
|
82
|
+
}
|
|
83
|
+
export function kebabToPascal(str) {
|
|
84
|
+
return str
|
|
85
|
+
.split('-')
|
|
86
|
+
.map((word) => word.charAt(0).toUpperCase() + word.slice(1))
|
|
87
|
+
.join('');
|
|
88
|
+
}
|
|
89
|
+
export function debounce(func, milliseconds) {
|
|
90
|
+
let timeout;
|
|
91
|
+
return () => {
|
|
92
|
+
clearTimeout(timeout);
|
|
93
|
+
timeout = setTimeout(function () {
|
|
94
|
+
func(...arguments);
|
|
95
|
+
}, milliseconds);
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
export function htmlToElements(html) {
|
|
99
|
+
let template = document.createElement('template');
|
|
100
|
+
html = html.replace(/<([A-Za-z0-9\-]*)([^>\/]*)(\/>)/gi, '<$1$2></$1>');
|
|
101
|
+
template.innerHTML = html;
|
|
102
|
+
template.content.normalize();
|
|
103
|
+
return Array.from(template.content.childNodes);
|
|
104
|
+
}
|
|
105
|
+
export function copyGettersSetters(source, target) {
|
|
106
|
+
const descriptors = Object.getOwnPropertyDescriptors(source);
|
|
107
|
+
for (const [key, descriptor] of Object.entries(descriptors)) {
|
|
108
|
+
if ('get' in descriptor || 'set' in descriptor) {
|
|
109
|
+
Object.defineProperty(target, key, descriptor);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
//# sourceMappingURL=helpers.js.map
|