@shrkcrft/core 0.1.0-alpha.16 → 0.1.0-alpha.17
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.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"object-utils.d.ts","sourceRoot":"","sources":["../../src/object/object-utils.ts"],"names":[],"mappings":"AAAA,wBAAgB,UAAU,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,QAAQ,CAAC,CAAC,CAAC,CASnD;AAED,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAI9E;
|
|
1
|
+
{"version":3,"file":"object-utils.d.ts","sourceRoot":"","sources":["../../src/object/object-utils.ts"],"names":[],"mappings":"AAAA,wBAAgB,UAAU,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,QAAQ,CAAC,CAAC,CAAC,CASnD;AAED,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAI9E;AAiBD,wBAAgB,KAAK,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACxF,CAAC,EAAE,CAAC,EACJ,CAAC,EAAE,CAAC,GACH,CAAC,GAAG,CAAC,CAYP;AAED,wBAAgB,IAAI,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC,SAAS,MAAM,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,IAAI,EAAE,SAAS,CAAC,EAAE,GAAG,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,CAUhG;AAED,wBAAgB,IAAI,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC,SAAS,MAAM,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,IAAI,EAAE,SAAS,CAAC,EAAE,GAAG,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,CAShG;AAED,wBAAgB,QAAQ,CAAC,CAAC,EAAE,CAAC,EAAE,KAAK,EAAE,SAAS,CAAC,EAAE,EAAE,KAAK,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE,CAW9E;AAED,wBAAgB,OAAO,CAAC,CAAC,EAAE,CAAC,SAAS,MAAM,GAAG,MAAM,EAClD,KAAK,EAAE,SAAS,CAAC,EAAE,EACnB,KAAK,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,GACpB,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAOhB"}
|
|
@@ -15,16 +15,29 @@ export function isPlainObject(value) {
|
|
|
15
15
|
const proto = Object.getPrototypeOf(value);
|
|
16
16
|
return proto === null || proto === Object.prototype;
|
|
17
17
|
}
|
|
18
|
+
/**
|
|
19
|
+
* Assign an own enumerable data property. Plain `target[key] = value` invokes
|
|
20
|
+
* the `Object.prototype.__proto__` setter for a key literally equal to
|
|
21
|
+
* `"__proto__"` (a real own key after `JSON.parse`), which silently drops the
|
|
22
|
+
* value (or pollutes the prototype) — so build these objects via defineProperty.
|
|
23
|
+
*/
|
|
24
|
+
function setOwn(target, key, value) {
|
|
25
|
+
Object.defineProperty(target, key, { value, writable: true, enumerable: true, configurable: true });
|
|
26
|
+
}
|
|
27
|
+
/** Read an OWN property value (returns undefined when the key isn't an own prop). */
|
|
28
|
+
function getOwn(obj, key) {
|
|
29
|
+
return Object.prototype.hasOwnProperty.call(obj, key) ? obj[key] : undefined;
|
|
30
|
+
}
|
|
18
31
|
export function merge(a, b) {
|
|
19
32
|
const result = { ...a };
|
|
20
33
|
for (const key of Object.keys(b)) {
|
|
21
|
-
const av = result
|
|
34
|
+
const av = getOwn(result, key);
|
|
22
35
|
const bv = b[key];
|
|
23
36
|
if (isPlainObject(av) && isPlainObject(bv)) {
|
|
24
|
-
result
|
|
37
|
+
setOwn(result, key, merge(av, bv));
|
|
25
38
|
}
|
|
26
39
|
else if (bv !== undefined) {
|
|
27
|
-
result
|
|
40
|
+
setOwn(result, key, bv);
|
|
28
41
|
}
|
|
29
42
|
}
|
|
30
43
|
return result;
|
|
@@ -32,8 +45,11 @@ export function merge(a, b) {
|
|
|
32
45
|
export function pick(obj, keys) {
|
|
33
46
|
const result = {};
|
|
34
47
|
for (const key of keys) {
|
|
35
|
-
|
|
36
|
-
|
|
48
|
+
// Own-property check (not `key in obj`, which walks the prototype chain, so
|
|
49
|
+
// pick(obj, ['toString']) would otherwise copy the inherited function).
|
|
50
|
+
if (Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
51
|
+
setOwn(result, key, obj[key]);
|
|
52
|
+
}
|
|
37
53
|
}
|
|
38
54
|
return result;
|
|
39
55
|
}
|
|
@@ -42,7 +58,7 @@ export function omit(obj, keys) {
|
|
|
42
58
|
const result = {};
|
|
43
59
|
for (const key of Object.keys(obj)) {
|
|
44
60
|
if (!keySet.has(key)) {
|
|
45
|
-
result
|
|
61
|
+
setOwn(result, key, obj[key]);
|
|
46
62
|
}
|
|
47
63
|
}
|
|
48
64
|
return result;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shrkcrft/core",
|
|
3
|
-
"version": "0.1.0-alpha.
|
|
3
|
+
"version": "0.1.0-alpha.17",
|
|
4
4
|
"description": "SharkCraft core primitives: Result, AppError, logger, file-system abstraction, path/string/object utils, IDs.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "SharkCraft contributors",
|