configre 1.2.2 → 1.2.4
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/index.js +1 -1
- package/merge.js +81 -0
- package/package.json +3 -4
package/index.js
CHANGED
package/merge.js
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
function isPlainObject(value) {
|
|
2
|
+
if (value === null || typeof value !== "object") {
|
|
3
|
+
return false;
|
|
4
|
+
}
|
|
5
|
+
const proto = Object.getPrototypeOf(value);
|
|
6
|
+
return proto === Object.prototype || proto === null;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
function isUnsafeKey(key) {
|
|
10
|
+
return key === "__proto__" || key === "constructor" || key === "prototype";
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function mergeArray(target, source) {
|
|
14
|
+
const result = target.slice();
|
|
15
|
+
|
|
16
|
+
for (let index = 0; index < source.length; index += 1) {
|
|
17
|
+
const srcValue = source[index];
|
|
18
|
+
const objValue = result[index];
|
|
19
|
+
|
|
20
|
+
if (Array.isArray(srcValue)) {
|
|
21
|
+
result[index] = mergeArray(Array.isArray(objValue) ? objValue : [], srcValue);
|
|
22
|
+
continue;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
if (isPlainObject(srcValue)) {
|
|
26
|
+
result[index] = baseMerge(isPlainObject(objValue) ? objValue : {}, srcValue);
|
|
27
|
+
continue;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
if (srcValue !== undefined || result[index] === undefined) {
|
|
31
|
+
result[index] = srcValue;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return result;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function baseMerge(object, source) {
|
|
39
|
+
if (object === source || source === null || typeof source !== "object") {
|
|
40
|
+
return object;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
for (const key in source) {
|
|
44
|
+
if (isUnsafeKey(key)) {
|
|
45
|
+
continue;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const srcValue = source[key];
|
|
49
|
+
const objValue = object[key];
|
|
50
|
+
|
|
51
|
+
if (Array.isArray(srcValue)) {
|
|
52
|
+
object[key] = mergeArray(Array.isArray(objValue) ? objValue : [], srcValue);
|
|
53
|
+
continue;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
if (isPlainObject(srcValue)) {
|
|
57
|
+
object[key] = baseMerge(isPlainObject(objValue) ? objValue : {}, srcValue);
|
|
58
|
+
continue;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
if (srcValue !== undefined || object[key] === undefined) {
|
|
62
|
+
object[key] = srcValue;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return object;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function merge(object, ...sources) {
|
|
70
|
+
const output = (object !== null && typeof object === "object") ? object : {};
|
|
71
|
+
|
|
72
|
+
for (const source of sources) {
|
|
73
|
+
baseMerge(output, source);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
return output;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
module.exports = {
|
|
80
|
+
merge
|
|
81
|
+
};
|
package/package.json
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "configre",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.4",
|
|
4
4
|
"description": "🔧 Effortlessly Tailor Your Settings",
|
|
5
5
|
"dependencies": {
|
|
6
|
-
"lemonlog": "^1.
|
|
7
|
-
"lodash": "^4.17.21"
|
|
6
|
+
"lemonlog": "^1.2.2"
|
|
8
7
|
},
|
|
9
8
|
"main": "index.js",
|
|
10
9
|
"keywords": [
|
|
@@ -34,4 +33,4 @@
|
|
|
34
33
|
"url": "https://github.com/clasen/Configre/issues"
|
|
35
34
|
},
|
|
36
35
|
"homepage": "https://github.com/clasen/Configre#readme"
|
|
37
|
-
}
|
|
36
|
+
}
|