@domql/utils 2.5.154 → 2.5.159
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/cjs/object.js +1 -1
- package/dist/esm/array.js +122 -0
- package/dist/esm/component.js +241 -0
- package/dist/esm/cookie.js +60 -0
- package/dist/esm/env.js +12 -0
- package/dist/esm/function.js +61 -0
- package/dist/esm/globals.js +10 -0
- package/dist/esm/index.js +13 -0
- package/dist/esm/key.js +13 -0
- package/dist/esm/log.js +15 -0
- package/dist/esm/node.js +15 -0
- package/dist/esm/object.js +687 -0
- package/dist/esm/string.js +124 -0
- package/dist/esm/tags.js +145 -0
- package/dist/esm/types.js +64 -0
- package/object.js +1 -1
- package/package.json +6 -6
package/dist/cjs/object.js
CHANGED
|
@@ -264,7 +264,7 @@ const objectToString = (obj = {}, indent = 0) => {
|
|
|
264
264
|
if ((0, import_types.isArray)(value)) {
|
|
265
265
|
str += "[\n";
|
|
266
266
|
for (const element of value) {
|
|
267
|
-
if ((0, import_types.
|
|
267
|
+
if ((0, import_types.isObjectLike)(element) && element !== null) {
|
|
268
268
|
str += `${spaces} ${objectToString(element, indent + 2)},
|
|
269
269
|
`;
|
|
270
270
|
} else if ((0, import_types.isString)(element)) {
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { deepCloneWithExtend, deepMerge } from "./object";
|
|
2
|
+
import { isArray, isNumber, isString } from "./types";
|
|
3
|
+
const arrayContainsOtherArray = (arr1, arr2) => {
|
|
4
|
+
return arr2.every((val) => arr1.includes(val));
|
|
5
|
+
};
|
|
6
|
+
const getFrequencyInArray = (arr, value) => {
|
|
7
|
+
return arr.reduce((count, currentValue) => {
|
|
8
|
+
return currentValue === value ? count + 1 : count;
|
|
9
|
+
}, 0);
|
|
10
|
+
};
|
|
11
|
+
const removeFromArray = (arr, index) => {
|
|
12
|
+
if (isString(index))
|
|
13
|
+
index = parseInt(index);
|
|
14
|
+
if (isNumber(index)) {
|
|
15
|
+
if (index < 0 || index >= arr.length || isNaN(index)) {
|
|
16
|
+
throw new Error("Invalid index");
|
|
17
|
+
}
|
|
18
|
+
arr.splice(index, 1);
|
|
19
|
+
} else if (isArray(index)) {
|
|
20
|
+
index.forEach((idx) => removeFromArray(arr, idx));
|
|
21
|
+
} else {
|
|
22
|
+
throw new Error("Invalid index");
|
|
23
|
+
}
|
|
24
|
+
return arr;
|
|
25
|
+
};
|
|
26
|
+
const swapItemsInArray = (arr, i, j) => {
|
|
27
|
+
[arr[i], arr[j]] = [arr[j], arr[i]];
|
|
28
|
+
};
|
|
29
|
+
const joinArrays = (...arrays) => {
|
|
30
|
+
return [].concat(...arrays);
|
|
31
|
+
};
|
|
32
|
+
const mergeArray = (arr, excludeFrom = []) => {
|
|
33
|
+
return arr.reduce((a, c) => deepMerge(a, deepCloneWithExtend(c, excludeFrom), excludeFrom), {});
|
|
34
|
+
};
|
|
35
|
+
const mergeAndCloneIfArray = (obj) => {
|
|
36
|
+
return isArray(obj) ? mergeArray(obj) : deepCloneWithExtend(obj);
|
|
37
|
+
};
|
|
38
|
+
const cutArrayBeforeValue = (arr, value) => {
|
|
39
|
+
const index = arr.indexOf(value);
|
|
40
|
+
if (index !== -1) {
|
|
41
|
+
return arr.slice(0, index);
|
|
42
|
+
}
|
|
43
|
+
return arr;
|
|
44
|
+
};
|
|
45
|
+
const cutArrayAfterValue = (arr, value) => {
|
|
46
|
+
if (!isArray(arr))
|
|
47
|
+
return;
|
|
48
|
+
const index = arr.indexOf(value);
|
|
49
|
+
if (index !== -1) {
|
|
50
|
+
return arr.slice(index + 1);
|
|
51
|
+
}
|
|
52
|
+
return arr;
|
|
53
|
+
};
|
|
54
|
+
const removeValueFromArray = (arr, value) => {
|
|
55
|
+
const index = arr.indexOf(value);
|
|
56
|
+
if (index > -1) {
|
|
57
|
+
const newArray = [...arr];
|
|
58
|
+
newArray.splice(index, 1);
|
|
59
|
+
return newArray;
|
|
60
|
+
}
|
|
61
|
+
return arr;
|
|
62
|
+
};
|
|
63
|
+
const removeValueFromArrayAll = (arr, value) => {
|
|
64
|
+
return arr.filter((item) => item !== value);
|
|
65
|
+
};
|
|
66
|
+
const addItemAfterEveryElement = (array, item) => {
|
|
67
|
+
const result = [];
|
|
68
|
+
for (let i = 0; i < array.length; i++) {
|
|
69
|
+
result.push(array[i]);
|
|
70
|
+
if (i < array.length - 1) {
|
|
71
|
+
result.push(item);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
return result;
|
|
75
|
+
};
|
|
76
|
+
const reorderArrayByValues = (array, valueToMove, insertBeforeValue) => {
|
|
77
|
+
const newArray = [...array];
|
|
78
|
+
const indexToMove = newArray.indexOf(valueToMove);
|
|
79
|
+
const indexToInsertBefore = newArray.indexOf(insertBeforeValue);
|
|
80
|
+
if (indexToMove !== -1 && indexToInsertBefore !== -1) {
|
|
81
|
+
const removedItem = newArray.splice(indexToMove, 1)[0];
|
|
82
|
+
const insertIndex = indexToInsertBefore < indexToMove ? indexToInsertBefore : indexToInsertBefore + 1;
|
|
83
|
+
newArray.splice(insertIndex, 0, removedItem);
|
|
84
|
+
}
|
|
85
|
+
return newArray;
|
|
86
|
+
};
|
|
87
|
+
const arraysEqual = (arr1, arr2) => {
|
|
88
|
+
if (arr1.length !== arr2.length) {
|
|
89
|
+
return false;
|
|
90
|
+
}
|
|
91
|
+
for (let i = 0; i < arr1.length; i++) {
|
|
92
|
+
if (arr1[i] !== arr2[i]) {
|
|
93
|
+
return false;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
return true;
|
|
97
|
+
};
|
|
98
|
+
const filterArrays = (sourceArr, excludeArr) => {
|
|
99
|
+
return sourceArr.filter((item) => !excludeArr.includes(item));
|
|
100
|
+
};
|
|
101
|
+
const filterArraysFast = (sourceArr, excludeArr) => {
|
|
102
|
+
const excludeSet = new Set(excludeArr);
|
|
103
|
+
return sourceArr.filter((item) => !excludeSet.has(item));
|
|
104
|
+
};
|
|
105
|
+
export {
|
|
106
|
+
addItemAfterEveryElement,
|
|
107
|
+
arrayContainsOtherArray,
|
|
108
|
+
arraysEqual,
|
|
109
|
+
cutArrayAfterValue,
|
|
110
|
+
cutArrayBeforeValue,
|
|
111
|
+
filterArrays,
|
|
112
|
+
filterArraysFast,
|
|
113
|
+
getFrequencyInArray,
|
|
114
|
+
joinArrays,
|
|
115
|
+
mergeAndCloneIfArray,
|
|
116
|
+
mergeArray,
|
|
117
|
+
removeFromArray,
|
|
118
|
+
removeValueFromArray,
|
|
119
|
+
removeValueFromArrayAll,
|
|
120
|
+
reorderArrayByValues,
|
|
121
|
+
swapItemsInArray
|
|
122
|
+
};
|
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defProps = Object.defineProperties;
|
|
3
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
+
var __spreadValues = (a, b) => {
|
|
9
|
+
for (var prop in b || (b = {}))
|
|
10
|
+
if (__hasOwnProp.call(b, prop))
|
|
11
|
+
__defNormalProp(a, prop, b[prop]);
|
|
12
|
+
if (__getOwnPropSymbols)
|
|
13
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
14
|
+
if (__propIsEnum.call(b, prop))
|
|
15
|
+
__defNormalProp(a, prop, b[prop]);
|
|
16
|
+
}
|
|
17
|
+
return a;
|
|
18
|
+
};
|
|
19
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
|
+
import {
|
|
21
|
+
deepCloneWithExtend,
|
|
22
|
+
exec,
|
|
23
|
+
isArray,
|
|
24
|
+
isFunction,
|
|
25
|
+
isObject,
|
|
26
|
+
isString,
|
|
27
|
+
joinArrays
|
|
28
|
+
} from ".";
|
|
29
|
+
const ENV = "development";
|
|
30
|
+
const checkIfKeyIsComponent = (key) => {
|
|
31
|
+
const isFirstKeyString = isString(key);
|
|
32
|
+
if (!isFirstKeyString)
|
|
33
|
+
return;
|
|
34
|
+
const firstCharKey = key.slice(0, 1);
|
|
35
|
+
return /^[A-Z]*$/.test(firstCharKey);
|
|
36
|
+
};
|
|
37
|
+
const checkIfKeyIsProperty = (key) => {
|
|
38
|
+
const isFirstKeyString = isString(key);
|
|
39
|
+
if (!isFirstKeyString)
|
|
40
|
+
return;
|
|
41
|
+
const firstCharKey = key.slice(0, 1);
|
|
42
|
+
return /^[a-z]*$/.test(firstCharKey);
|
|
43
|
+
};
|
|
44
|
+
const addAdditionalExtend = (newExtend, element) => {
|
|
45
|
+
if (!newExtend)
|
|
46
|
+
return element;
|
|
47
|
+
const { extend: elementExtend } = element;
|
|
48
|
+
const originalArray = isArray(elementExtend) ? elementExtend : [elementExtend];
|
|
49
|
+
const receivedArray = isArray(newExtend) ? newExtend : [newExtend];
|
|
50
|
+
const extend = joinArrays(receivedArray, originalArray);
|
|
51
|
+
return __spreadProps(__spreadValues({}, element), { extend });
|
|
52
|
+
};
|
|
53
|
+
const checkIfSugar = (element, parent, key) => {
|
|
54
|
+
var _a;
|
|
55
|
+
const {
|
|
56
|
+
extend,
|
|
57
|
+
props,
|
|
58
|
+
childExtend,
|
|
59
|
+
extends: extendProps,
|
|
60
|
+
childExtends,
|
|
61
|
+
childProps,
|
|
62
|
+
children,
|
|
63
|
+
on,
|
|
64
|
+
$collection,
|
|
65
|
+
$stateCollection,
|
|
66
|
+
$propsCollection
|
|
67
|
+
} = element;
|
|
68
|
+
const hasComponentAttrs = extend || childExtend || props || on || $collection || $stateCollection || $propsCollection;
|
|
69
|
+
if (hasComponentAttrs && (childProps || extendProps || children || childExtends)) {
|
|
70
|
+
const logErr = (_a = parent || element) == null ? void 0 : _a.error;
|
|
71
|
+
if (logErr)
|
|
72
|
+
logErr.call(element, "Sugar component includes params for builtin components", { verbose: true });
|
|
73
|
+
}
|
|
74
|
+
return !hasComponentAttrs || childProps || extendProps || children || childExtends;
|
|
75
|
+
};
|
|
76
|
+
const extendizeByKey = (element, parent, key) => {
|
|
77
|
+
const { context } = parent;
|
|
78
|
+
const { tag, extend, childExtends } = element;
|
|
79
|
+
const isSugar = checkIfSugar(element, parent, key);
|
|
80
|
+
const extendFromKey = key.includes("+") ? key.split("+") : key.includes("_") ? [key.split("_")[0]] : key.includes(".") && !checkIfKeyIsComponent(key.split(".")[1]) ? [key.split(".")[0]] : [key];
|
|
81
|
+
const isExtendKeyComponent = context && context.components[extendFromKey];
|
|
82
|
+
if (element === isExtendKeyComponent)
|
|
83
|
+
return element;
|
|
84
|
+
else if (isSugar) {
|
|
85
|
+
const newElem = addAdditionalExtend(element.extends, {
|
|
86
|
+
extend: extendFromKey,
|
|
87
|
+
tag,
|
|
88
|
+
props: __spreadValues({}, element)
|
|
89
|
+
});
|
|
90
|
+
if (childExtends)
|
|
91
|
+
newElem.childExtend = childExtends;
|
|
92
|
+
return newElem;
|
|
93
|
+
} else if (!extend || extend === true) {
|
|
94
|
+
return __spreadProps(__spreadValues({}, element), {
|
|
95
|
+
tag,
|
|
96
|
+
extend: extendFromKey
|
|
97
|
+
});
|
|
98
|
+
} else if (extend) {
|
|
99
|
+
return addAdditionalExtend(extendFromKey, element);
|
|
100
|
+
} else if (isFunction(element)) {
|
|
101
|
+
return {
|
|
102
|
+
extend: extendFromKey,
|
|
103
|
+
tag,
|
|
104
|
+
props: __spreadValues({}, exec(element, parent))
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
function getCapitalCaseKeys(obj) {
|
|
109
|
+
return Object.keys(obj).filter((key) => /^[A-Z]/.test(key));
|
|
110
|
+
}
|
|
111
|
+
const addChildrenIfNotInOriginal = (element, parent, key) => {
|
|
112
|
+
const childElems = getCapitalCaseKeys(element.props);
|
|
113
|
+
if (!childElems.length)
|
|
114
|
+
return element;
|
|
115
|
+
for (const i in childElems) {
|
|
116
|
+
const childKey = childElems[i];
|
|
117
|
+
const childElem = element[childKey];
|
|
118
|
+
const newChild = element.props[childKey];
|
|
119
|
+
const assignChild = (val) => {
|
|
120
|
+
element[childKey] = val;
|
|
121
|
+
delete element.props[childKey];
|
|
122
|
+
};
|
|
123
|
+
if (newChild == null ? void 0 : newChild.ignoreExtend)
|
|
124
|
+
continue;
|
|
125
|
+
if (newChild === null)
|
|
126
|
+
assignChild(null);
|
|
127
|
+
else if (!childElem)
|
|
128
|
+
assignChild(deepCloneWithExtend(newChild));
|
|
129
|
+
else {
|
|
130
|
+
const isSugarChildElem = checkIfSugar(childElem, parent, key);
|
|
131
|
+
if (isSugarChildElem)
|
|
132
|
+
continue;
|
|
133
|
+
assignChild({
|
|
134
|
+
extend: element[childKey],
|
|
135
|
+
props: newChild
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
};
|
|
140
|
+
const applyKeyComponentAsExtend = (element, parent, key) => {
|
|
141
|
+
return extendizeByKey(element, parent, key) || element;
|
|
142
|
+
};
|
|
143
|
+
const applyComponentFromContext = (element, parent, options) => {
|
|
144
|
+
const { context } = element;
|
|
145
|
+
if (!context || !context.components)
|
|
146
|
+
return;
|
|
147
|
+
const { components } = context;
|
|
148
|
+
const { extend } = element;
|
|
149
|
+
const execExtend = exec(extend, element);
|
|
150
|
+
if (isString(execExtend)) {
|
|
151
|
+
const componentExists = components[execExtend] || components["smbls." + execExtend];
|
|
152
|
+
if (componentExists)
|
|
153
|
+
element.extend = componentExists;
|
|
154
|
+
else {
|
|
155
|
+
if ((ENV === "test" || ENV === "development") && options.verbose) {
|
|
156
|
+
console.warn(execExtend, "is not in library", components, element);
|
|
157
|
+
console.warn("replacing with ", {});
|
|
158
|
+
}
|
|
159
|
+
element.extend = {};
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
};
|
|
163
|
+
const isVariant = (param) => {
|
|
164
|
+
if (!isString(param))
|
|
165
|
+
return;
|
|
166
|
+
const firstCharKey = param.slice(0, 1);
|
|
167
|
+
return firstCharKey === ".";
|
|
168
|
+
};
|
|
169
|
+
const hasVariantProp = (element) => {
|
|
170
|
+
const { props } = element;
|
|
171
|
+
if (isObject(props) && isString(props.variant))
|
|
172
|
+
return true;
|
|
173
|
+
};
|
|
174
|
+
const getChildrenComponentsByKey = (key, el) => {
|
|
175
|
+
if (key === el.key || el.__ref.__componentKey === key) {
|
|
176
|
+
return el;
|
|
177
|
+
}
|
|
178
|
+
if (el.extend) {
|
|
179
|
+
const foundString = isString(el.extend) && el.extend === key;
|
|
180
|
+
const foundInArray = isArray(el.extend) && el.extend.filter((v) => v === key).length;
|
|
181
|
+
if (foundString || foundInArray)
|
|
182
|
+
return el;
|
|
183
|
+
}
|
|
184
|
+
if (el.parent && el.parent.childExtend) {
|
|
185
|
+
const foundString = isString(el.parent.childExtend) && el.parent.childExtend === key;
|
|
186
|
+
const foundInArray = isArray(el.parent.childExtend) && el.parent.childExtend.filter((v) => v === key).length;
|
|
187
|
+
if (foundString || foundInArray)
|
|
188
|
+
return el;
|
|
189
|
+
}
|
|
190
|
+
};
|
|
191
|
+
const getExtendsInElement = (obj) => {
|
|
192
|
+
let result = [];
|
|
193
|
+
function traverse(o) {
|
|
194
|
+
for (const key in o) {
|
|
195
|
+
if (Object.hasOwnProperty.call(o, key)) {
|
|
196
|
+
if (checkIfKeyIsComponent(key)) {
|
|
197
|
+
result.push(key);
|
|
198
|
+
}
|
|
199
|
+
if (key === "extend") {
|
|
200
|
+
if (typeof o[key] === "string") {
|
|
201
|
+
result.push(o[key]);
|
|
202
|
+
} else if (Array.isArray(o[key])) {
|
|
203
|
+
result = result.concat(o[key]);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
if (typeof o[key] === "object" && o[key] !== null) {
|
|
207
|
+
traverse(o[key]);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
traverse(obj);
|
|
213
|
+
return result;
|
|
214
|
+
};
|
|
215
|
+
const setContentKey = (el, opts = {}) => {
|
|
216
|
+
const { __ref: ref } = el;
|
|
217
|
+
const contentElementKey = opts.contentElementKey;
|
|
218
|
+
if (contentElementKey !== "content" && contentElementKey !== ref.contentElementKey || !ref.contentElementKey) {
|
|
219
|
+
ref.contentElementKey = contentElementKey || "content";
|
|
220
|
+
} else
|
|
221
|
+
ref.contentElementKey = "content";
|
|
222
|
+
if (contentElementKey !== "content")
|
|
223
|
+
opts.contentElementKey = "content";
|
|
224
|
+
return ref.contentElementKey;
|
|
225
|
+
};
|
|
226
|
+
export {
|
|
227
|
+
addAdditionalExtend,
|
|
228
|
+
addChildrenIfNotInOriginal,
|
|
229
|
+
applyComponentFromContext,
|
|
230
|
+
applyKeyComponentAsExtend,
|
|
231
|
+
checkIfKeyIsComponent,
|
|
232
|
+
checkIfKeyIsProperty,
|
|
233
|
+
checkIfSugar,
|
|
234
|
+
extendizeByKey,
|
|
235
|
+
getCapitalCaseKeys,
|
|
236
|
+
getChildrenComponentsByKey,
|
|
237
|
+
getExtendsInElement,
|
|
238
|
+
hasVariantProp,
|
|
239
|
+
isVariant,
|
|
240
|
+
setContentKey
|
|
241
|
+
};
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { isUndefined } from "./types";
|
|
2
|
+
import { document } from "@domql/utils";
|
|
3
|
+
const isMobile = (() => typeof navigator === "undefined" ? false : /Mobi/.test(navigator.userAgent))();
|
|
4
|
+
const setCookie = (cname, cvalue, exdays = 365) => {
|
|
5
|
+
if (isUndefined(document) || isUndefined(document.cookie))
|
|
6
|
+
return;
|
|
7
|
+
const d = /* @__PURE__ */ new Date();
|
|
8
|
+
d.setTime(d.getTime() + exdays * 24 * 60 * 60 * 1e3);
|
|
9
|
+
const expires = `expires=${d.toUTCString()}`;
|
|
10
|
+
document.cookie = `${cname}=${cvalue};${expires};path=/`;
|
|
11
|
+
};
|
|
12
|
+
const getCookie = (cname) => {
|
|
13
|
+
if (isUndefined(document) || isUndefined(document.cookie))
|
|
14
|
+
return;
|
|
15
|
+
const name = `${cname}=`;
|
|
16
|
+
const decodedCookie = decodeURIComponent(document.cookie);
|
|
17
|
+
const ca = decodedCookie.split(";");
|
|
18
|
+
for (let i = 0; i < ca.length; i++) {
|
|
19
|
+
let c = ca[i];
|
|
20
|
+
while (c.charAt(0) === " ")
|
|
21
|
+
c = c.substring(1);
|
|
22
|
+
if (c.indexOf(name) === 0)
|
|
23
|
+
return c.substring(name.length, c.length);
|
|
24
|
+
}
|
|
25
|
+
return "";
|
|
26
|
+
};
|
|
27
|
+
const removeCookie = (cname) => {
|
|
28
|
+
if (isUndefined(document) || isUndefined(document.cookie))
|
|
29
|
+
return;
|
|
30
|
+
document.cookie = cname + "=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;";
|
|
31
|
+
};
|
|
32
|
+
function getLocalStorage(key) {
|
|
33
|
+
let savedJSON;
|
|
34
|
+
if (window.localStorage) {
|
|
35
|
+
try {
|
|
36
|
+
savedJSON = JSON.parse(window.localStorage.getItem(key));
|
|
37
|
+
} catch (e) {
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
if (typeof savedJSON !== "undefined") {
|
|
41
|
+
return savedJSON;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
function setLocalStorage(key, data) {
|
|
45
|
+
if (data && window.localStorage) {
|
|
46
|
+
if (typeof data === "object") {
|
|
47
|
+
window.localStorage.setItem(key, JSON.stringify(data));
|
|
48
|
+
} else {
|
|
49
|
+
window.localStorage.setItem(key, data);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
export {
|
|
54
|
+
getCookie,
|
|
55
|
+
getLocalStorage,
|
|
56
|
+
isMobile,
|
|
57
|
+
removeCookie,
|
|
58
|
+
setCookie,
|
|
59
|
+
setLocalStorage
|
|
60
|
+
};
|
package/dist/esm/env.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
const NODE_ENV = "development";
|
|
2
|
+
const isProduction = (env = NODE_ENV) => env === "production" || env === "prod" || env !== "development" && env !== "dev" && env !== "test";
|
|
3
|
+
const isTest = (env = NODE_ENV) => env === "test";
|
|
4
|
+
const isDevelopment = (env = NODE_ENV) => env === "development" || env === "dev";
|
|
5
|
+
const getNev = (key, env = NODE_ENV) => env[key];
|
|
6
|
+
export {
|
|
7
|
+
NODE_ENV,
|
|
8
|
+
getNev,
|
|
9
|
+
isDevelopment,
|
|
10
|
+
isProduction,
|
|
11
|
+
isTest
|
|
12
|
+
};
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
function debounce(func, wait, immediate) {
|
|
2
|
+
let timeout;
|
|
3
|
+
return function() {
|
|
4
|
+
const context = this;
|
|
5
|
+
const args = arguments;
|
|
6
|
+
const later = function() {
|
|
7
|
+
timeout = null;
|
|
8
|
+
if (!immediate)
|
|
9
|
+
func.apply(context, args);
|
|
10
|
+
};
|
|
11
|
+
const callNow = immediate && !timeout;
|
|
12
|
+
clearTimeout(timeout);
|
|
13
|
+
timeout = setTimeout(later, wait);
|
|
14
|
+
if (callNow)
|
|
15
|
+
func.apply(context, args);
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
const debounceOnContext = (element, func, timeout = 300) => {
|
|
19
|
+
let timer;
|
|
20
|
+
return (...args) => {
|
|
21
|
+
clearTimeout(timer);
|
|
22
|
+
timer = setTimeout(() => {
|
|
23
|
+
func.apply(element, args);
|
|
24
|
+
}, timeout);
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
const memoize = (fn) => {
|
|
28
|
+
const cache = {};
|
|
29
|
+
return (...args) => {
|
|
30
|
+
const n = args[0];
|
|
31
|
+
if (n in cache) {
|
|
32
|
+
return cache[n];
|
|
33
|
+
} else {
|
|
34
|
+
const result = fn(n);
|
|
35
|
+
cache[n] = result;
|
|
36
|
+
return result;
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
const isStringFunction = (inputString) => {
|
|
41
|
+
const functionRegex = /^((function\s*\([^)]*\)\s*\{[^}]*\})|(\([^)]*\)\s*=>))/;
|
|
42
|
+
return functionRegex.test(inputString);
|
|
43
|
+
};
|
|
44
|
+
function cloneFunction(fn, win = window) {
|
|
45
|
+
const temp = function() {
|
|
46
|
+
return fn.apply(win, arguments);
|
|
47
|
+
};
|
|
48
|
+
for (const key in fn) {
|
|
49
|
+
if (Object.hasOwnProperty.call(fn, key)) {
|
|
50
|
+
temp[key] = fn[key];
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return temp;
|
|
54
|
+
}
|
|
55
|
+
export {
|
|
56
|
+
cloneFunction,
|
|
57
|
+
debounce,
|
|
58
|
+
debounceOnContext,
|
|
59
|
+
isStringFunction,
|
|
60
|
+
memoize
|
|
61
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export * from "./key.js";
|
|
2
|
+
export * from "./env.js";
|
|
3
|
+
export * from "./types.js";
|
|
4
|
+
export * from "./object.js";
|
|
5
|
+
export * from "./function.js";
|
|
6
|
+
export * from "./array.js";
|
|
7
|
+
export * from "./node.js";
|
|
8
|
+
export * from "./log.js";
|
|
9
|
+
export * from "./string.js";
|
|
10
|
+
export * from "./globals.js";
|
|
11
|
+
export * from "./cookie.js";
|
|
12
|
+
export * from "./tags.js";
|
|
13
|
+
export * from "./component.js";
|
package/dist/esm/key.js
ADDED
package/dist/esm/log.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
const logIf = (bool, ...arg) => {
|
|
2
|
+
if (bool)
|
|
3
|
+
arg.map((v) => console.log(v));
|
|
4
|
+
};
|
|
5
|
+
const logGroupIf = (bool, key, ...arg) => {
|
|
6
|
+
if (bool) {
|
|
7
|
+
console.group(key);
|
|
8
|
+
arg.map((v) => console.log(v));
|
|
9
|
+
console.groupEnd(key);
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
export {
|
|
13
|
+
logGroupIf,
|
|
14
|
+
logIf
|
|
15
|
+
};
|
package/dist/esm/node.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { window } from "./globals";
|
|
2
|
+
const isNode = (obj) => {
|
|
3
|
+
return (typeof Node === "object" ? obj instanceof window.Node : obj && typeof obj === "object" && typeof obj.nodeType === "number" && typeof obj.nodeName === "string") || false;
|
|
4
|
+
};
|
|
5
|
+
const isHtmlElement = (obj) => {
|
|
6
|
+
return (typeof HTMLElement === "object" ? obj instanceof window.HTMLElement : obj && typeof obj === "object" && obj !== null && obj.nodeType === 1 && typeof obj.nodeName === "string") || false;
|
|
7
|
+
};
|
|
8
|
+
const isDOMNode = (obj) => {
|
|
9
|
+
return typeof window !== "undefined" && (obj instanceof window.Node || obj instanceof window.Window || obj === window || obj === document);
|
|
10
|
+
};
|
|
11
|
+
export {
|
|
12
|
+
isDOMNode,
|
|
13
|
+
isHtmlElement,
|
|
14
|
+
isNode
|
|
15
|
+
};
|