@faasjs/deep_merge 0.0.2-beta.54 → 0.0.3-beta.2

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/README.md CHANGED
@@ -1,7 +1,45 @@
1
1
  # @faasjs/deep_merge
2
2
 
3
- 合并对象
4
-
5
- [![License: MIT](https://img.shields.io/npm/l/@faasjs/deep_merge.svg)](https://github.com/faasjs/faasjs/blob/master/packages/faasjs/deep_merge/LICENSE)
3
+ [![License: MIT](https://img.shields.io/npm/l/@faasjs/deep_merge.svg)](https://github.com/faasjs/faasjs/blob/main/packages/faasjs/deep_merge/LICENSE)
6
4
  [![NPM Stable Version](https://img.shields.io/npm/v/@faasjs/deep_merge/stable.svg)](https://www.npmjs.com/package/@faasjs/deep_merge)
7
5
  [![NPM Beta Version](https://img.shields.io/npm/v/@faasjs/deep_merge/beta.svg)](https://www.npmjs.com/package/@faasjs/deep_merge)
6
+
7
+ A helper function to deep merge objects and array.
8
+
9
+ ## Install
10
+
11
+ npm install @faasjs/deep_merge
12
+
13
+ ## Modules
14
+
15
+ ### Functions
16
+
17
+ - [deepMerge](#deepmerge)
18
+
19
+ ## Functions
20
+
21
+ ### deepMerge
22
+
23
+ ▸ **deepMerge**(...`sources`): `any`
24
+
25
+ Deep merge two objects or arrays.
26
+
27
+ Features:
28
+ * All objects will be cloned before merging.
29
+ * Merging order is from right to left.
30
+ * If an array include same objects, it will be unique to one.
31
+
32
+ ```ts
33
+ deepMerge({ a: 1 }, { a: 2 }) // { a: 2 }
34
+ deepMerge([1, 2], [2, 3]) // [1, 2, 3]
35
+ ```
36
+
37
+ #### Parameters
38
+
39
+ | Name | Type |
40
+ | :------ | :------ |
41
+ | `...sources` | `any`[] |
42
+
43
+ #### Returns
44
+
45
+ `any`
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Deep merge two objects or arrays.
3
+ *
4
+ * Features:
5
+ * * All objects will be cloned before merging.
6
+ * * Merging order is from right to left.
7
+ * * If an array include same objects, it will be unique to one.
8
+ *
9
+ * ```ts
10
+ * deepMerge({ a: 1 }, { a: 2 }) // { a: 2 }
11
+ * deepMerge([1, 2], [2, 3]) // [1, 2, 3]
12
+ * ```
13
+ */
14
+ declare function deepMerge(...sources: any[]): any;
15
+
16
+ export { deepMerge };
package/dist/index.js ADDED
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var src_exports = {};
22
+ __export(src_exports, {
23
+ deepMerge: () => deepMerge
24
+ });
25
+ module.exports = __toCommonJS(src_exports);
26
+ var shouldMerge = function(item) {
27
+ const type = Object.prototype.toString.call(item);
28
+ return type === "[object Object]" || type === "[object Array]";
29
+ };
30
+ function deepMerge(...sources) {
31
+ let acc = /* @__PURE__ */ Object.create(null);
32
+ for (const source of sources)
33
+ if (source instanceof Array) {
34
+ if (!(acc instanceof Array))
35
+ acc = [];
36
+ acc = [...new Set(source.concat(...acc))];
37
+ } else if (shouldMerge(source))
38
+ for (const [key, value] of Object.entries(source)) {
39
+ let val;
40
+ if (shouldMerge(value))
41
+ val = deepMerge(acc[key], value);
42
+ else
43
+ val = value;
44
+ acc = {
45
+ ...acc,
46
+ [key]: val
47
+ };
48
+ }
49
+ return acc;
50
+ }
51
+ // Annotate the CommonJS export names for ESM import in node:
52
+ 0 && (module.exports = {
53
+ deepMerge
54
+ });
package/dist/index.mjs ADDED
@@ -0,0 +1,29 @@
1
+ // src/index.ts
2
+ var shouldMerge = function(item) {
3
+ const type = Object.prototype.toString.call(item);
4
+ return type === "[object Object]" || type === "[object Array]";
5
+ };
6
+ function deepMerge(...sources) {
7
+ let acc = /* @__PURE__ */ Object.create(null);
8
+ for (const source of sources)
9
+ if (source instanceof Array) {
10
+ if (!(acc instanceof Array))
11
+ acc = [];
12
+ acc = [...new Set(source.concat(...acc))];
13
+ } else if (shouldMerge(source))
14
+ for (const [key, value] of Object.entries(source)) {
15
+ let val;
16
+ if (shouldMerge(value))
17
+ val = deepMerge(acc[key], value);
18
+ else
19
+ val = value;
20
+ acc = {
21
+ ...acc,
22
+ [key]: val
23
+ };
24
+ }
25
+ return acc;
26
+ }
27
+ export {
28
+ deepMerge
29
+ };
package/package.json CHANGED
@@ -1,25 +1,28 @@
1
1
  {
2
2
  "name": "@faasjs/deep_merge",
3
- "version": "0.0.2-beta.54",
3
+ "version": "0.0.3-beta.2",
4
4
  "license": "MIT",
5
- "main": "lib/index.js",
6
- "types": "lib/index.d.ts",
7
- "module": "lib/index.es.js",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "homepage": "https://faasjs.com/doc/deep_merge.html",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git+https://github.com/faasjs/faasjs.git",
11
+ "directory": "packages/deep_merge"
12
+ },
13
+ "bugs": {
14
+ "url": "https://github.com/faasjs/faasjs/issues"
15
+ },
16
+ "funding": "https://github.com/sponsors/faasjs",
8
17
  "scripts": {
9
- "lint": "eslint --ext .ts src",
10
- "prepack": "rm -rf ./lib && rollup -c",
11
- "ci": "yarn lint && jest --silent"
18
+ "build": "tsup-node src/index.ts --format esm,cjs",
19
+ "build:types": "tsup-node src/index.ts --dts-only"
12
20
  },
13
21
  "files": [
14
- "lib"
22
+ "dist"
15
23
  ],
16
- "devDependencies": {
17
- "@types/debug": "*",
18
- "@types/jest": "*",
19
- "@types/node": "*",
20
- "rollup": "*",
21
- "rollup-plugin-typescript2": "*",
22
- "typescript": "*"
23
- },
24
- "gitHead": "ef598f53e0d1a357ced00d98df09818309dd207f"
24
+ "engines": {
25
+ "npm": ">=8.0.0",
26
+ "node": ">=16.0.0"
27
+ }
25
28
  }
package/lib/index.d.ts DELETED
@@ -1,10 +0,0 @@
1
- /**
2
- * 合并对象
3
- * @description
4
- * 注意事项:
5
- * * 合并时会复制对象,不会修改原对象
6
- * * 合并顺序是后面的覆盖前面的
7
- * * 若有数组形式的属性,数组里的内容将被去重合并
8
- * @param sources [...any] 合并对象
9
- */
10
- export default function deepMerge(...sources: any[]): any;
package/lib/index.es.js DELETED
@@ -1,37 +0,0 @@
1
- const shouldMerge = function (item) {
2
- const type = Object.prototype.toString.call(item);
3
- return type === '[object Object]' || type === '[object Array]';
4
- };
5
- /**
6
- * 合并对象
7
- * @description
8
- * 注意事项:
9
- * * 合并时会复制对象,不会修改原对象
10
- * * 合并顺序是后面的覆盖前面的
11
- * * 若有数组形式的属性,数组里的内容将被去重合并
12
- * @param sources [...any] 合并对象
13
- */
14
- function deepMerge(...sources) {
15
- let acc = Object.create(null);
16
- for (const source of sources)
17
- if (source instanceof Array) {
18
- if (!(acc instanceof Array))
19
- acc = [];
20
- acc = [...new Set((source).concat(...acc))];
21
- }
22
- else if (shouldMerge(source))
23
- for (const [key, value] of Object.entries(source)) {
24
- let val;
25
- if (shouldMerge(value))
26
- val = deepMerge(acc[key], value);
27
- else
28
- val = value;
29
- acc = {
30
- ...acc,
31
- [key]: val,
32
- };
33
- }
34
- return acc;
35
- }
36
-
37
- export default deepMerge;
package/lib/index.js DELETED
@@ -1,39 +0,0 @@
1
- 'use strict';
2
-
3
- const shouldMerge = function (item) {
4
- const type = Object.prototype.toString.call(item);
5
- return type === '[object Object]' || type === '[object Array]';
6
- };
7
- /**
8
- * 合并对象
9
- * @description
10
- * 注意事项:
11
- * * 合并时会复制对象,不会修改原对象
12
- * * 合并顺序是后面的覆盖前面的
13
- * * 若有数组形式的属性,数组里的内容将被去重合并
14
- * @param sources [...any] 合并对象
15
- */
16
- function deepMerge(...sources) {
17
- let acc = Object.create(null);
18
- for (const source of sources)
19
- if (source instanceof Array) {
20
- if (!(acc instanceof Array))
21
- acc = [];
22
- acc = [...new Set((source).concat(...acc))];
23
- }
24
- else if (shouldMerge(source))
25
- for (const [key, value] of Object.entries(source)) {
26
- let val;
27
- if (shouldMerge(value))
28
- val = deepMerge(acc[key], value);
29
- else
30
- val = value;
31
- acc = {
32
- ...acc,
33
- [key]: val,
34
- };
35
- }
36
- return acc;
37
- }
38
-
39
- module.exports = deepMerge;