merge-deeper-object 0.1.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.md +21 -0
- package/README.md +32 -0
- package/lib/cjs/index.js +18 -0
- package/lib/cjs/types/index.d.ts +3 -0
- package/lib/cjs/types/index.d.ts.map +1 -0
- package/lib/esm/index.mjs +17 -0
- package/lib/esm/types/index.d.ts +3 -0
- package/lib/esm/types/index.d.ts.map +1 -0
- package/package.json +84 -0
package/LICENSE.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 Ilyass Mabrouk
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
## merge-deeper-object
|
|
2
|
+
Combine the attributes of objects deeply. Compatible with both CommonJS (CJS) and ECMAScript Module (ESM) formats.
|
|
3
|
+
|
|
4
|
+
## Install
|
|
5
|
+
```
|
|
6
|
+
npm install --save @work-state/merge-deeper-object
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
## Running tests
|
|
10
|
+
```
|
|
11
|
+
npm install
|
|
12
|
+
npm run test
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Usage
|
|
16
|
+
```javascript
|
|
17
|
+
var mergeDeeper = require('@work-state/merge-deeper-object')
|
|
18
|
+
|
|
19
|
+
var obj1 = { a: { b: { c: 1 } }, d: "d", e: { f: true } }
|
|
20
|
+
var obj2 = { a: { g: "g" }, d: "dd", e: { f: false } }
|
|
21
|
+
|
|
22
|
+
mergeDeeper(obj1, obj2)
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
> { a: { b: { c: 1 }, g: "g" }, d: "dd", e: { f: false } }
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## Author
|
|
29
|
+
[Ilyass Mabrouk](https://github.com/work-state)
|
|
30
|
+
|
|
31
|
+
## License
|
|
32
|
+
[MIT](https://github.com/work-state/merge-deeper-object/blob/master/LICENSE.md)
|
package/lib/cjs/index.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const mergeDeeper = (object, merge) => {
|
|
4
|
+
if (!merge || typeof merge === "string")
|
|
5
|
+
merge = {};
|
|
6
|
+
[...Object.keys(merge), ...Object.getOwnPropertySymbols(merge)].map((el) => {
|
|
7
|
+
if (typeof merge[el] !== typeof object[el] ||
|
|
8
|
+
(typeof merge[el] && typeof object[el]) !== "object")
|
|
9
|
+
object[el] = merge[el];
|
|
10
|
+
if (!(el in object))
|
|
11
|
+
object[el] =
|
|
12
|
+
typeof merge[el] === "object" && !Array.isArray(merge[el])
|
|
13
|
+
? Object.assign({}, merge[el]) : merge[el];
|
|
14
|
+
mergeDeeper(object[el], merge[el]);
|
|
15
|
+
});
|
|
16
|
+
return object;
|
|
17
|
+
};
|
|
18
|
+
exports.default = mergeDeeper;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAAA,QAAA,MAAM,WAAW,WAAY,OAAO,GAAG,EAAE,GAAG,CAAC,SAAS,OAAO,GAAG,EAAE,GAAG,CAAC,qBAoBrE,CAAC;AAEF,eAAe,WAAW,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
const mergeDeeper = (object, merge) => {
|
|
2
|
+
if (!merge || typeof merge === "string")
|
|
3
|
+
merge = {};
|
|
4
|
+
[...Object.keys(merge), ...Object.getOwnPropertySymbols(merge)].map((el) => {
|
|
5
|
+
if (typeof merge[el] !== typeof object[el] ||
|
|
6
|
+
(typeof merge[el] && typeof object[el]) !== "object")
|
|
7
|
+
object[el] = merge[el];
|
|
8
|
+
if (!(el in object))
|
|
9
|
+
object[el] =
|
|
10
|
+
typeof merge[el] === "object" && !Array.isArray(merge[el])
|
|
11
|
+
? { ...merge[el] }
|
|
12
|
+
: merge[el];
|
|
13
|
+
mergeDeeper(object[el], merge[el]);
|
|
14
|
+
});
|
|
15
|
+
return object;
|
|
16
|
+
};
|
|
17
|
+
export default mergeDeeper;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAAA,QAAA,MAAM,WAAW,WAAY,OAAO,GAAG,EAAE,GAAG,CAAC,SAAS,OAAO,GAAG,EAAE,GAAG,CAAC,qBAoBrE,CAAC;AAEF,eAAe,WAAW,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": "0.1.0",
|
|
3
|
+
"author": "Ilyass Mabrouk",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"name": "merge-deeper-object",
|
|
6
|
+
"description": "Deep merge properties of objects. Support both CJS and ESM.",
|
|
7
|
+
"homepage": "https://github.com/work-state/merge-deeper-object",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/work-state/merge-deeper-object.git"
|
|
11
|
+
},
|
|
12
|
+
"bugs": {
|
|
13
|
+
"url": "https://github.com/work-state/merge-deeper-object/issues"
|
|
14
|
+
},
|
|
15
|
+
"types": "./lib/cjs/types/index.d.ts",
|
|
16
|
+
"main": "./lib/cjs/index.js",
|
|
17
|
+
"module": "./lib/esm/index.msj",
|
|
18
|
+
"files": [
|
|
19
|
+
"lib/**/*"
|
|
20
|
+
],
|
|
21
|
+
"scripts": {
|
|
22
|
+
"clean": "rm -rf ./lib",
|
|
23
|
+
"build": "npm run clean && npm run build:esm && npm run build:cjs",
|
|
24
|
+
"build:esm": "tsc -p ./config/tsconfig.esm.json && mv lib/esm/index.js lib/esm/index.mjs",
|
|
25
|
+
"build:cjs": "tsc -p ./config/tsconfig.cjs.json",
|
|
26
|
+
"prepack": "npm run build",
|
|
27
|
+
"test": "mocha"
|
|
28
|
+
},
|
|
29
|
+
"keywords": [
|
|
30
|
+
"object",
|
|
31
|
+
"objects",
|
|
32
|
+
"nested",
|
|
33
|
+
"deep",
|
|
34
|
+
"deeper",
|
|
35
|
+
"merge",
|
|
36
|
+
"combine",
|
|
37
|
+
"clone deep",
|
|
38
|
+
"keys",
|
|
39
|
+
"key",
|
|
40
|
+
"values",
|
|
41
|
+
"value",
|
|
42
|
+
"properties",
|
|
43
|
+
"property",
|
|
44
|
+
"entries",
|
|
45
|
+
"entry"
|
|
46
|
+
],
|
|
47
|
+
"verb": {
|
|
48
|
+
"tasks": [
|
|
49
|
+
"readme"
|
|
50
|
+
],
|
|
51
|
+
"reflinks": [
|
|
52
|
+
"verb"
|
|
53
|
+
],
|
|
54
|
+
"lint": {
|
|
55
|
+
"reflinks": true
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
"exports": {
|
|
59
|
+
".": {
|
|
60
|
+
"import": {
|
|
61
|
+
"types": "./lib/esm/types/index.d.ts",
|
|
62
|
+
"default": "./lib/esm/index.mjs"
|
|
63
|
+
},
|
|
64
|
+
"require": {
|
|
65
|
+
"types": "./lib/cjs/types/index.d.ts",
|
|
66
|
+
"default": "./lib/cjs/index.js"
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
},
|
|
70
|
+
"dependencies": {
|
|
71
|
+
"typescript": "^4.9.5"
|
|
72
|
+
},
|
|
73
|
+
"devDependencies": {
|
|
74
|
+
"@types/chai": "^4.3.4",
|
|
75
|
+
"@types/mocha": "^10.0.1",
|
|
76
|
+
"chai": "^4.3.7",
|
|
77
|
+
"mocha": "^10.2.0",
|
|
78
|
+
"ts-node": "^10.9.1"
|
|
79
|
+
},
|
|
80
|
+
"directories": {
|
|
81
|
+
"lib": "lib",
|
|
82
|
+
"test": "test"
|
|
83
|
+
}
|
|
84
|
+
}
|