@aeriajs/common 0.0.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/LICENSE +19 -0
- package/README.md +13 -0
- package/dist/arraysIntersects.d.ts +1 -0
- package/dist/arraysIntersects.js +12 -0
- package/dist/arraysIntersects.mjs +8 -0
- package/dist/checkForUndefined.d.ts +2 -0
- package/dist/checkForUndefined.js +12 -0
- package/dist/checkForUndefined.mjs +6 -0
- package/dist/convertConditionToQuery.d.ts +2 -0
- package/dist/convertConditionToQuery.js +60 -0
- package/dist/convertConditionToQuery.mjs +72 -0
- package/dist/date.d.ts +7 -0
- package/dist/date.js +42 -0
- package/dist/date.mjs +101 -0
- package/dist/deepClone.d.ts +1 -0
- package/dist/deepClone.js +9 -0
- package/dist/deepClone.mjs +3 -0
- package/dist/deepMerge.d.ts +5 -0
- package/dist/deepMerge.js +39 -0
- package/dist/deepMerge.mjs +66 -0
- package/dist/dynamicImport.d.ts +1 -0
- package/dist/dynamicImport.js +16 -0
- package/dist/dynamicImport.mjs +145 -0
- package/dist/either.d.ts +9 -0
- package/dist/either.js +37 -0
- package/dist/either.mjs +32 -0
- package/dist/evaluateCondition.d.ts +5 -0
- package/dist/evaluateCondition.js +57 -0
- package/dist/evaluateCondition.mjs +63 -0
- package/dist/formatValue.d.ts +2 -0
- package/dist/formatValue.js +55 -0
- package/dist/formatValue.mjs +59 -0
- package/dist/freshItem.d.ts +2 -0
- package/dist/freshItem.js +36 -0
- package/dist/freshItem.mjs +133 -0
- package/dist/getMissingProperties.d.ts +2 -0
- package/dist/getMissingProperties.js +38 -0
- package/dist/getMissingProperties.mjs +50 -0
- package/dist/getReferenceProperty.d.ts +2 -0
- package/dist/getReferenceProperty.js +19 -0
- package/dist/getReferenceProperty.mjs +11 -0
- package/dist/getValueFromPath.d.ts +1 -0
- package/dist/getValueFromPath.js +10 -0
- package/dist/getValueFromPath.mjs +6 -0
- package/dist/http.d.ts +20 -0
- package/dist/http.js +51 -0
- package/dist/http.mjs +224 -0
- package/dist/index.d.ts +20 -0
- package/dist/index.js +36 -0
- package/dist/index.mjs +20 -0
- package/dist/isReference.d.ts +2 -0
- package/dist/isReference.js +9 -0
- package/dist/isReference.mjs +3 -0
- package/dist/isRequired.d.ts +2 -0
- package/dist/isRequired.js +18 -0
- package/dist/isRequired.mjs +14 -0
- package/dist/pipe.d.ts +4 -0
- package/dist/pipe.js +28 -0
- package/dist/pipe.mjs +259 -0
- package/dist/schema.d.ts +20 -0
- package/dist/schema.js +74 -0
- package/dist/schema.mjs +72 -0
- package/dist/serialize.d.ts +3 -0
- package/dist/serialize.js +33 -0
- package/dist/serialize.mjs +38 -0
- package/package.json +37 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
Copyright 2023 João Santos (joaosan177@gmail.com)
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
4
|
+
this software and associated documentation files (the “Software”), to deal in
|
|
5
|
+
the Software without restriction, including without limitation the rights to
|
|
6
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
|
7
|
+
of the Software, and to permit persons to whom the Software is furnished to do
|
|
8
|
+
so, subject to the following conditions:
|
|
9
|
+
|
|
10
|
+
The above copyright notice and this permission notice shall be included in all
|
|
11
|
+
copies or substantial portions of the Software.
|
|
12
|
+
|
|
13
|
+
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
19
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const arraysIntersects: <T extends string[]>(subject: string | T, arr: T | undefined) => boolean;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.arraysIntersects = void 0;
|
|
4
|
+
const arraysIntersects = (subject, arr) => {
|
|
5
|
+
if (!arr) {
|
|
6
|
+
return false;
|
|
7
|
+
}
|
|
8
|
+
return Array.isArray(subject)
|
|
9
|
+
? subject.some((e) => arr.includes(e))
|
|
10
|
+
: arr.includes(subject);
|
|
11
|
+
};
|
|
12
|
+
exports.arraysIntersects = arraysIntersects;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.checkForUndefined = void 0;
|
|
4
|
+
const checkForUndefined = (property, propertyName, what) => {
|
|
5
|
+
if (property.readOnly || property.isTimestamp) {
|
|
6
|
+
return false;
|
|
7
|
+
}
|
|
8
|
+
return what[propertyName] === null
|
|
9
|
+
|| what[propertyName] === undefined
|
|
10
|
+
|| what[propertyName] === '';
|
|
11
|
+
};
|
|
12
|
+
exports.checkForUndefined = checkForUndefined;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.convertConditionToQuery = void 0;
|
|
4
|
+
const getValueFromPath_js_1 = require("./getValueFromPath.js");
|
|
5
|
+
const convertExpression = (condition, subject) => {
|
|
6
|
+
const term2 = 'term2' in condition
|
|
7
|
+
? typeof condition.term2 === 'string' && condition.term2.startsWith('$.')
|
|
8
|
+
? (0, getValueFromPath_js_1.getValueFromPath)(subject, condition.term2.split('$.')[1])
|
|
9
|
+
: condition.term2
|
|
10
|
+
: null;
|
|
11
|
+
switch (condition.operator) {
|
|
12
|
+
case 'truthy': return {
|
|
13
|
+
$ne: [
|
|
14
|
+
null,
|
|
15
|
+
undefined,
|
|
16
|
+
],
|
|
17
|
+
};
|
|
18
|
+
case 'equal': return term2;
|
|
19
|
+
case 'gt': return {
|
|
20
|
+
$gt: term2,
|
|
21
|
+
};
|
|
22
|
+
case 'lt': return {
|
|
23
|
+
$lt: term2,
|
|
24
|
+
};
|
|
25
|
+
case 'gte': return {
|
|
26
|
+
$gte: term2,
|
|
27
|
+
};
|
|
28
|
+
case 'lte': return {
|
|
29
|
+
$lte: term2,
|
|
30
|
+
};
|
|
31
|
+
case 'in': {
|
|
32
|
+
return Array.isArray(term2)
|
|
33
|
+
? {
|
|
34
|
+
$in: term2,
|
|
35
|
+
}
|
|
36
|
+
: term2;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
const convertConditionToQuery = (condition, subject) => {
|
|
41
|
+
if ('or' in condition) {
|
|
42
|
+
return {
|
|
43
|
+
$or: condition.or.map((sub) => (0, exports.convertConditionToQuery)(sub, subject)),
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
if ('and' in condition) {
|
|
47
|
+
return {
|
|
48
|
+
$and: condition.and.map((sub) => (0, exports.convertConditionToQuery)(sub, subject)),
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
if ('not' in condition) {
|
|
52
|
+
return {
|
|
53
|
+
$not: (0, exports.convertConditionToQuery)(condition.not, subject),
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
return {
|
|
57
|
+
[condition.term1]: convertExpression(condition, subject),
|
|
58
|
+
};
|
|
59
|
+
};
|
|
60
|
+
exports.convertConditionToQuery = convertConditionToQuery;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
function _define_property(obj, key, value) {
|
|
2
|
+
if (key in obj) {
|
|
3
|
+
Object.defineProperty(obj, key, {
|
|
4
|
+
value: value,
|
|
5
|
+
enumerable: true,
|
|
6
|
+
configurable: true,
|
|
7
|
+
writable: true
|
|
8
|
+
});
|
|
9
|
+
} else {
|
|
10
|
+
obj[key] = value;
|
|
11
|
+
}
|
|
12
|
+
return obj;
|
|
13
|
+
}
|
|
14
|
+
import { getValueFromPath } from "./getValueFromPath.mjs";
|
|
15
|
+
var convertExpression = function(condition, subject) {
|
|
16
|
+
var term2 = "term2" in condition ? typeof condition.term2 === "string" && condition.term2.startsWith("$.") ? getValueFromPath(subject, condition.term2.split("$.")[1]) : condition.term2 : null;
|
|
17
|
+
switch(condition.operator){
|
|
18
|
+
case "truthy":
|
|
19
|
+
return {
|
|
20
|
+
$ne: [
|
|
21
|
+
null,
|
|
22
|
+
undefined
|
|
23
|
+
]
|
|
24
|
+
};
|
|
25
|
+
case "equal":
|
|
26
|
+
return term2;
|
|
27
|
+
case "gt":
|
|
28
|
+
return {
|
|
29
|
+
$gt: term2
|
|
30
|
+
};
|
|
31
|
+
case "lt":
|
|
32
|
+
return {
|
|
33
|
+
$lt: term2
|
|
34
|
+
};
|
|
35
|
+
case "gte":
|
|
36
|
+
return {
|
|
37
|
+
$gte: term2
|
|
38
|
+
};
|
|
39
|
+
case "lte":
|
|
40
|
+
return {
|
|
41
|
+
$lte: term2
|
|
42
|
+
};
|
|
43
|
+
case "in":
|
|
44
|
+
{
|
|
45
|
+
return Array.isArray(term2) ? {
|
|
46
|
+
$in: term2
|
|
47
|
+
} : term2;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
export var convertConditionToQuery = function(condition, subject) {
|
|
52
|
+
if ("or" in condition) {
|
|
53
|
+
return {
|
|
54
|
+
$or: condition.or.map(function(sub) {
|
|
55
|
+
return convertConditionToQuery(sub, subject);
|
|
56
|
+
})
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
if ("and" in condition) {
|
|
60
|
+
return {
|
|
61
|
+
$and: condition.and.map(function(sub) {
|
|
62
|
+
return convertConditionToQuery(sub, subject);
|
|
63
|
+
})
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
if ("not" in condition) {
|
|
67
|
+
return {
|
|
68
|
+
$not: convertConditionToQuery(condition.not, subject)
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
return _define_property({}, condition.term1, convertExpression(condition, subject));
|
|
72
|
+
};
|
package/dist/date.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export type DateFormatOptions = {
|
|
2
|
+
hours?: boolean;
|
|
3
|
+
hoursOnly?: boolean;
|
|
4
|
+
locale?: string;
|
|
5
|
+
};
|
|
6
|
+
export declare const formatDateTime: (date: Date | string, options?: DateFormatOptions) => string;
|
|
7
|
+
export declare const getRelativeTimeFromNow: (target: any) => string | undefined;
|
package/dist/date.js
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getRelativeTimeFromNow = exports.formatDateTime = void 0;
|
|
4
|
+
const rtf = new Intl.RelativeTimeFormat(undefined, {
|
|
5
|
+
numeric: 'auto',
|
|
6
|
+
});
|
|
7
|
+
const units = {
|
|
8
|
+
year: 31536000000,
|
|
9
|
+
month: 2628000000,
|
|
10
|
+
day: 86400000,
|
|
11
|
+
hour: 3600000,
|
|
12
|
+
minute: 6000,
|
|
13
|
+
second: 1000,
|
|
14
|
+
};
|
|
15
|
+
const formatDateTime = function (date, options) {
|
|
16
|
+
const target = date instanceof Date
|
|
17
|
+
? date
|
|
18
|
+
: new Date(date);
|
|
19
|
+
if (isNaN(target.getDate())) {
|
|
20
|
+
return '-';
|
|
21
|
+
}
|
|
22
|
+
const { hours, hoursOnly, locale = 'navigator' in globalThis
|
|
23
|
+
? navigator.language
|
|
24
|
+
: 'en-US', } = options || {};
|
|
25
|
+
if (hoursOnly) {
|
|
26
|
+
return target.toLocaleTimeString();
|
|
27
|
+
}
|
|
28
|
+
return hours
|
|
29
|
+
? target.toLocaleString(locale)
|
|
30
|
+
: target.toLocaleDateString(locale);
|
|
31
|
+
};
|
|
32
|
+
exports.formatDateTime = formatDateTime;
|
|
33
|
+
const getRelativeTimeFromNow = function (target) {
|
|
34
|
+
const now = new Date();
|
|
35
|
+
const elapsed = now - target;
|
|
36
|
+
for (const [u, value] of Object.entries(units)) {
|
|
37
|
+
if (Math.abs(elapsed) > value || u === 'second') {
|
|
38
|
+
return rtf.format(-1 * Math.round(elapsed / value), u);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
exports.getRelativeTimeFromNow = getRelativeTimeFromNow;
|
package/dist/date.mjs
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
function _array_like_to_array(arr, len) {
|
|
2
|
+
if (len == null || len > arr.length) len = arr.length;
|
|
3
|
+
for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
|
|
4
|
+
return arr2;
|
|
5
|
+
}
|
|
6
|
+
function _array_with_holes(arr) {
|
|
7
|
+
if (Array.isArray(arr)) return arr;
|
|
8
|
+
}
|
|
9
|
+
function _instanceof(left, right) {
|
|
10
|
+
if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
|
|
11
|
+
return !!right[Symbol.hasInstance](left);
|
|
12
|
+
} else {
|
|
13
|
+
return left instanceof right;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
function _iterable_to_array_limit(arr, i) {
|
|
17
|
+
var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
|
|
18
|
+
if (_i == null) return;
|
|
19
|
+
var _arr = [];
|
|
20
|
+
var _n = true;
|
|
21
|
+
var _d = false;
|
|
22
|
+
var _s, _e;
|
|
23
|
+
try {
|
|
24
|
+
for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
|
|
25
|
+
_arr.push(_s.value);
|
|
26
|
+
if (i && _arr.length === i) break;
|
|
27
|
+
}
|
|
28
|
+
} catch (err) {
|
|
29
|
+
_d = true;
|
|
30
|
+
_e = err;
|
|
31
|
+
} finally{
|
|
32
|
+
try {
|
|
33
|
+
if (!_n && _i["return"] != null) _i["return"]();
|
|
34
|
+
} finally{
|
|
35
|
+
if (_d) throw _e;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return _arr;
|
|
39
|
+
}
|
|
40
|
+
function _non_iterable_rest() {
|
|
41
|
+
throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
42
|
+
}
|
|
43
|
+
function _sliced_to_array(arr, i) {
|
|
44
|
+
return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
|
|
45
|
+
}
|
|
46
|
+
function _unsupported_iterable_to_array(o, minLen) {
|
|
47
|
+
if (!o) return;
|
|
48
|
+
if (typeof o === "string") return _array_like_to_array(o, minLen);
|
|
49
|
+
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
50
|
+
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
51
|
+
if (n === "Map" || n === "Set") return Array.from(n);
|
|
52
|
+
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
|
|
53
|
+
}
|
|
54
|
+
var rtf = new Intl.RelativeTimeFormat(undefined, {
|
|
55
|
+
numeric: "auto"
|
|
56
|
+
});
|
|
57
|
+
var units = {
|
|
58
|
+
year: 31536000000,
|
|
59
|
+
month: 2628000000,
|
|
60
|
+
day: 86400000,
|
|
61
|
+
hour: 3600000,
|
|
62
|
+
minute: 6000,
|
|
63
|
+
second: 1000
|
|
64
|
+
};
|
|
65
|
+
export var formatDateTime = function formatDateTime(date, options) {
|
|
66
|
+
var target = _instanceof(date, Date) ? date : new Date(date);
|
|
67
|
+
if (isNaN(target.getDate())) {
|
|
68
|
+
return "-";
|
|
69
|
+
}
|
|
70
|
+
var _ref = options || {}, hours = _ref.hours, hoursOnly = _ref.hoursOnly, _ref_locale = _ref.locale, locale = _ref_locale === void 0 ? "navigator" in globalThis ? navigator.language : "en-US" : _ref_locale;
|
|
71
|
+
if (hoursOnly) {
|
|
72
|
+
return target.toLocaleTimeString();
|
|
73
|
+
}
|
|
74
|
+
return hours ? target.toLocaleString(locale) : target.toLocaleDateString(locale);
|
|
75
|
+
};
|
|
76
|
+
export var getRelativeTimeFromNow = function getRelativeTimeFromNow(target) {
|
|
77
|
+
var now = new Date();
|
|
78
|
+
var elapsed = now - target;
|
|
79
|
+
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
80
|
+
try {
|
|
81
|
+
for(var _iterator = Object.entries(units)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
|
|
82
|
+
var _step_value = _sliced_to_array(_step.value, 2), u = _step_value[0], value = _step_value[1];
|
|
83
|
+
if (Math.abs(elapsed) > value || u === "second") {
|
|
84
|
+
return rtf.format(-1 * Math.round(elapsed / value), u);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
} catch (err) {
|
|
88
|
+
_didIteratorError = true;
|
|
89
|
+
_iteratorError = err;
|
|
90
|
+
} finally{
|
|
91
|
+
try {
|
|
92
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
93
|
+
_iterator.return();
|
|
94
|
+
}
|
|
95
|
+
} finally{
|
|
96
|
+
if (_didIteratorError) {
|
|
97
|
+
throw _iteratorError;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const deepClone: <const TObject>(obj: TObject) => TObject;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.deepClone = void 0;
|
|
4
|
+
const deepClone = (obj) => {
|
|
5
|
+
return typeof 'structuredClone' === 'function'
|
|
6
|
+
? structuredClone(obj)
|
|
7
|
+
: JSON.parse(JSON.stringify(obj));
|
|
8
|
+
};
|
|
9
|
+
exports.deepClone = deepClone;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export type MergeOptions = {
|
|
2
|
+
arrays?: false;
|
|
3
|
+
callback?: (key: string, leftVal: any, rightVal: any) => any;
|
|
4
|
+
};
|
|
5
|
+
export declare const deepMerge: <const TLeft extends Record<string, any>, const TRight extends Record<string, any>>(left: TLeft, right: TRight, options?: MergeOptions) => TLeft & TRight;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.deepMerge = void 0;
|
|
4
|
+
const deepMerge = (left, right, options) => {
|
|
5
|
+
const result = Object.assign({}, left);
|
|
6
|
+
const { arrays = true } = options || {};
|
|
7
|
+
for (const key in right) {
|
|
8
|
+
const leftVal = result[key];
|
|
9
|
+
const rightVal = right[key];
|
|
10
|
+
if (options?.callback) {
|
|
11
|
+
const res = options.callback(key, leftVal, rightVal);
|
|
12
|
+
if (res !== undefined) {
|
|
13
|
+
result[key] = res;
|
|
14
|
+
continue;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
if (Array.isArray(leftVal) && Array.isArray(rightVal)) {
|
|
18
|
+
result[key] = arrays
|
|
19
|
+
? result[key].concat(...rightVal)
|
|
20
|
+
: rightVal;
|
|
21
|
+
continue;
|
|
22
|
+
}
|
|
23
|
+
if (rightVal instanceof Function) {
|
|
24
|
+
result[key] = rightVal;
|
|
25
|
+
continue;
|
|
26
|
+
}
|
|
27
|
+
if (leftVal instanceof Object && rightVal instanceof Object) {
|
|
28
|
+
if (rightVal.constructor !== Object) {
|
|
29
|
+
result[key] = rightVal;
|
|
30
|
+
continue;
|
|
31
|
+
}
|
|
32
|
+
result[key] = (0, exports.deepMerge)(leftVal, rightVal, options);
|
|
33
|
+
continue;
|
|
34
|
+
}
|
|
35
|
+
result[key] = rightVal;
|
|
36
|
+
}
|
|
37
|
+
return result;
|
|
38
|
+
};
|
|
39
|
+
exports.deepMerge = deepMerge;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
function _array_like_to_array(arr, len) {
|
|
2
|
+
if (len == null || len > arr.length) len = arr.length;
|
|
3
|
+
for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
|
|
4
|
+
return arr2;
|
|
5
|
+
}
|
|
6
|
+
function _array_without_holes(arr) {
|
|
7
|
+
if (Array.isArray(arr)) return _array_like_to_array(arr);
|
|
8
|
+
}
|
|
9
|
+
function _instanceof(left, right) {
|
|
10
|
+
if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
|
|
11
|
+
return !!right[Symbol.hasInstance](left);
|
|
12
|
+
} else {
|
|
13
|
+
return left instanceof right;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
function _iterable_to_array(iter) {
|
|
17
|
+
if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
|
|
18
|
+
}
|
|
19
|
+
function _non_iterable_spread() {
|
|
20
|
+
throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
21
|
+
}
|
|
22
|
+
function _to_consumable_array(arr) {
|
|
23
|
+
return _array_without_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array(arr) || _non_iterable_spread();
|
|
24
|
+
}
|
|
25
|
+
function _unsupported_iterable_to_array(o, minLen) {
|
|
26
|
+
if (!o) return;
|
|
27
|
+
if (typeof o === "string") return _array_like_to_array(o, minLen);
|
|
28
|
+
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
29
|
+
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
30
|
+
if (n === "Map" || n === "Set") return Array.from(n);
|
|
31
|
+
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
|
|
32
|
+
}
|
|
33
|
+
export var deepMerge = function(left, right, options) {
|
|
34
|
+
var result = Object.assign({}, left);
|
|
35
|
+
var _ref = options || {}, _ref_arrays = _ref.arrays, arrays = _ref_arrays === void 0 ? true : _ref_arrays;
|
|
36
|
+
for(var key in right){
|
|
37
|
+
var leftVal = result[key];
|
|
38
|
+
var rightVal = right[key];
|
|
39
|
+
if (options === null || options === void 0 ? void 0 : options.callback) {
|
|
40
|
+
var res = options.callback(key, leftVal, rightVal);
|
|
41
|
+
if (res !== undefined) {
|
|
42
|
+
result[key] = res;
|
|
43
|
+
continue;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
if (Array.isArray(leftVal) && Array.isArray(rightVal)) {
|
|
47
|
+
var _result_key;
|
|
48
|
+
result[key] = arrays ? (_result_key = result[key]).concat.apply(_result_key, _to_consumable_array(rightVal)) : rightVal;
|
|
49
|
+
continue;
|
|
50
|
+
}
|
|
51
|
+
if (_instanceof(rightVal, Function)) {
|
|
52
|
+
result[key] = rightVal;
|
|
53
|
+
continue;
|
|
54
|
+
}
|
|
55
|
+
if (_instanceof(leftVal, Object) && _instanceof(rightVal, Object)) {
|
|
56
|
+
if (rightVal.constructor !== Object) {
|
|
57
|
+
result[key] = rightVal;
|
|
58
|
+
continue;
|
|
59
|
+
}
|
|
60
|
+
result[key] = deepMerge(leftVal, rightVal, options);
|
|
61
|
+
continue;
|
|
62
|
+
}
|
|
63
|
+
result[key] = rightVal;
|
|
64
|
+
}
|
|
65
|
+
return result;
|
|
66
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const dynamicImport: (path: string) => Promise<any>;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.dynamicImport = void 0;
|
|
4
|
+
const dynamicImport = async (path) => {
|
|
5
|
+
try {
|
|
6
|
+
return require(path);
|
|
7
|
+
}
|
|
8
|
+
catch (err) {
|
|
9
|
+
}
|
|
10
|
+
const fn = new Function(`return (async () => {
|
|
11
|
+
const { pathToFileURL } = await import('url')
|
|
12
|
+
return import(pathToFileURL('${path.replace(/\\/g, '\\\\')}'))
|
|
13
|
+
})()`);
|
|
14
|
+
return fn();
|
|
15
|
+
};
|
|
16
|
+
exports.dynamicImport = dynamicImport;
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
2
|
+
try {
|
|
3
|
+
var info = gen[key](arg);
|
|
4
|
+
var value = info.value;
|
|
5
|
+
} catch (error) {
|
|
6
|
+
reject(error);
|
|
7
|
+
return;
|
|
8
|
+
}
|
|
9
|
+
if (info.done) {
|
|
10
|
+
resolve(value);
|
|
11
|
+
} else {
|
|
12
|
+
Promise.resolve(value).then(_next, _throw);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
function _async_to_generator(fn) {
|
|
16
|
+
return function() {
|
|
17
|
+
var self = this, args = arguments;
|
|
18
|
+
return new Promise(function(resolve, reject) {
|
|
19
|
+
var gen = fn.apply(self, args);
|
|
20
|
+
function _next(value) {
|
|
21
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
|
22
|
+
}
|
|
23
|
+
function _throw(err) {
|
|
24
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
|
25
|
+
}
|
|
26
|
+
_next(undefined);
|
|
27
|
+
});
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
function _ts_generator(thisArg, body) {
|
|
31
|
+
var f, y, t, g, _ = {
|
|
32
|
+
label: 0,
|
|
33
|
+
sent: function() {
|
|
34
|
+
if (t[0] & 1) throw t[1];
|
|
35
|
+
return t[1];
|
|
36
|
+
},
|
|
37
|
+
trys: [],
|
|
38
|
+
ops: []
|
|
39
|
+
};
|
|
40
|
+
return g = {
|
|
41
|
+
next: verb(0),
|
|
42
|
+
"throw": verb(1),
|
|
43
|
+
"return": verb(2)
|
|
44
|
+
}, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
|
|
45
|
+
return this;
|
|
46
|
+
}), g;
|
|
47
|
+
function verb(n) {
|
|
48
|
+
return function(v) {
|
|
49
|
+
return step([
|
|
50
|
+
n,
|
|
51
|
+
v
|
|
52
|
+
]);
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
function step(op) {
|
|
56
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
57
|
+
while(_)try {
|
|
58
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
59
|
+
if (y = 0, t) op = [
|
|
60
|
+
op[0] & 2,
|
|
61
|
+
t.value
|
|
62
|
+
];
|
|
63
|
+
switch(op[0]){
|
|
64
|
+
case 0:
|
|
65
|
+
case 1:
|
|
66
|
+
t = op;
|
|
67
|
+
break;
|
|
68
|
+
case 4:
|
|
69
|
+
_.label++;
|
|
70
|
+
return {
|
|
71
|
+
value: op[1],
|
|
72
|
+
done: false
|
|
73
|
+
};
|
|
74
|
+
case 5:
|
|
75
|
+
_.label++;
|
|
76
|
+
y = op[1];
|
|
77
|
+
op = [
|
|
78
|
+
0
|
|
79
|
+
];
|
|
80
|
+
continue;
|
|
81
|
+
case 7:
|
|
82
|
+
op = _.ops.pop();
|
|
83
|
+
_.trys.pop();
|
|
84
|
+
continue;
|
|
85
|
+
default:
|
|
86
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
87
|
+
_ = 0;
|
|
88
|
+
continue;
|
|
89
|
+
}
|
|
90
|
+
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
91
|
+
_.label = op[1];
|
|
92
|
+
break;
|
|
93
|
+
}
|
|
94
|
+
if (op[0] === 6 && _.label < t[1]) {
|
|
95
|
+
_.label = t[1];
|
|
96
|
+
t = op;
|
|
97
|
+
break;
|
|
98
|
+
}
|
|
99
|
+
if (t && _.label < t[2]) {
|
|
100
|
+
_.label = t[2];
|
|
101
|
+
_.ops.push(op);
|
|
102
|
+
break;
|
|
103
|
+
}
|
|
104
|
+
if (t[2]) _.ops.pop();
|
|
105
|
+
_.trys.pop();
|
|
106
|
+
continue;
|
|
107
|
+
}
|
|
108
|
+
op = body.call(thisArg, _);
|
|
109
|
+
} catch (e) {
|
|
110
|
+
op = [
|
|
111
|
+
6,
|
|
112
|
+
e
|
|
113
|
+
];
|
|
114
|
+
y = 0;
|
|
115
|
+
} finally{
|
|
116
|
+
f = t = 0;
|
|
117
|
+
}
|
|
118
|
+
if (op[0] & 5) throw op[1];
|
|
119
|
+
return {
|
|
120
|
+
value: op[0] ? op[1] : void 0,
|
|
121
|
+
done: true
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
export var dynamicImport = function() {
|
|
126
|
+
var _ref = _async_to_generator(function(path) {
|
|
127
|
+
var fn;
|
|
128
|
+
return _ts_generator(this, function(_state) {
|
|
129
|
+
try {
|
|
130
|
+
return [
|
|
131
|
+
2,
|
|
132
|
+
require(path)
|
|
133
|
+
];
|
|
134
|
+
} catch (err) {}
|
|
135
|
+
fn = new Function("return (async () => {\n const { pathToFileURL } = await import('url')\n return import(pathToFileURL('".concat(path.replace(/\\/g, "\\\\"), "'))\n })()"));
|
|
136
|
+
return [
|
|
137
|
+
2,
|
|
138
|
+
fn()
|
|
139
|
+
];
|
|
140
|
+
});
|
|
141
|
+
});
|
|
142
|
+
return function dynamicImport(path) {
|
|
143
|
+
return _ref.apply(this, arguments);
|
|
144
|
+
};
|
|
145
|
+
}();
|