@js-utils-kit/object 1.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 +21 -0
- package/dist/index.cjs +1 -0
- package/dist/index.d.cts +49 -0
- package/dist/index.d.mts +49 -0
- package/dist/index.mjs +1 -0
- package/package.json +42 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Sriman
|
|
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/dist/index.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
function e(t=!1,...n){let r=e=>typeof e==`object`&&!!e,i={};for(let a of n)if(r(a))for(let n of Object.keys(a)){let o=a[n],s=i[n];Array.isArray(o)?i[n]=t&&Array.isArray(s)?[...s,...o]:[...o]:r(o)&&!Array.isArray(o)?i[n]=r(s)&&!Array.isArray(s)?e(t,s,o):e(t,{},o):i[n]=o}return i}exports.mergeObj=e;
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
//#region src/mergeObj.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Deeply merges multiple source objects into one.
|
|
4
|
+
*
|
|
5
|
+
* - Object properties are merged recursively.
|
|
6
|
+
* - If a key exists in multiple objects:
|
|
7
|
+
* - If the value is a plain object, it is deeply merged.
|
|
8
|
+
* - If the value is an array:
|
|
9
|
+
* - If `appendArray` is `true`, arrays are concatenated.
|
|
10
|
+
* - If `appendArray` is `false` (default), later arrays replace earlier ones.
|
|
11
|
+
* - Primitive values (string, number, boolean, etc.) are overwritten by later sources.
|
|
12
|
+
*
|
|
13
|
+
* - Objects passed later in the list of sources have **higher priority**.
|
|
14
|
+
* For example, values in the last object will override previous ones.
|
|
15
|
+
* - If you want to give **priority to a specific object**, **pass it last**.
|
|
16
|
+
*
|
|
17
|
+
* @returns A new object containing deeply merged keys and values.
|
|
18
|
+
*
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```ts
|
|
22
|
+
* const defaultConfig = { env: "dev", features: ["a"], flags: { debug: true } };
|
|
23
|
+
* const userConfig = { env: "prod", features: ["b"], flags: { beta: true } };
|
|
24
|
+
*
|
|
25
|
+
* const result = mergeObj(defaultConfig, userConfig);
|
|
26
|
+
* // {
|
|
27
|
+
* // env: "prod",
|
|
28
|
+
* // features: ["b"], // replaced, not merged
|
|
29
|
+
* // flags: { debug: true, beta: true }
|
|
30
|
+
* // }
|
|
31
|
+
*
|
|
32
|
+
* const result2 = mergeObj(true, defaultConfig, userConfig);
|
|
33
|
+
* // {
|
|
34
|
+
* // env: "prod",
|
|
35
|
+
* // features: ["a", "b"], // arrays merged
|
|
36
|
+
* // flags: { debug: true, beta: true }
|
|
37
|
+
* // }
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
declare function mergeObj(
|
|
41
|
+
/**
|
|
42
|
+
* If `true`, arrays are concatenated. If `false` (default), arrays are replaced.
|
|
43
|
+
*
|
|
44
|
+
* @default false
|
|
45
|
+
*/
|
|
46
|
+
appendArray?: boolean, /** One or more objects to deeply merge */
|
|
47
|
+
...sources: object[]): object;
|
|
48
|
+
//#endregion
|
|
49
|
+
export { mergeObj };
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
//#region src/mergeObj.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Deeply merges multiple source objects into one.
|
|
4
|
+
*
|
|
5
|
+
* - Object properties are merged recursively.
|
|
6
|
+
* - If a key exists in multiple objects:
|
|
7
|
+
* - If the value is a plain object, it is deeply merged.
|
|
8
|
+
* - If the value is an array:
|
|
9
|
+
* - If `appendArray` is `true`, arrays are concatenated.
|
|
10
|
+
* - If `appendArray` is `false` (default), later arrays replace earlier ones.
|
|
11
|
+
* - Primitive values (string, number, boolean, etc.) are overwritten by later sources.
|
|
12
|
+
*
|
|
13
|
+
* - Objects passed later in the list of sources have **higher priority**.
|
|
14
|
+
* For example, values in the last object will override previous ones.
|
|
15
|
+
* - If you want to give **priority to a specific object**, **pass it last**.
|
|
16
|
+
*
|
|
17
|
+
* @returns A new object containing deeply merged keys and values.
|
|
18
|
+
*
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```ts
|
|
22
|
+
* const defaultConfig = { env: "dev", features: ["a"], flags: { debug: true } };
|
|
23
|
+
* const userConfig = { env: "prod", features: ["b"], flags: { beta: true } };
|
|
24
|
+
*
|
|
25
|
+
* const result = mergeObj(defaultConfig, userConfig);
|
|
26
|
+
* // {
|
|
27
|
+
* // env: "prod",
|
|
28
|
+
* // features: ["b"], // replaced, not merged
|
|
29
|
+
* // flags: { debug: true, beta: true }
|
|
30
|
+
* // }
|
|
31
|
+
*
|
|
32
|
+
* const result2 = mergeObj(true, defaultConfig, userConfig);
|
|
33
|
+
* // {
|
|
34
|
+
* // env: "prod",
|
|
35
|
+
* // features: ["a", "b"], // arrays merged
|
|
36
|
+
* // flags: { debug: true, beta: true }
|
|
37
|
+
* // }
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
declare function mergeObj(
|
|
41
|
+
/**
|
|
42
|
+
* If `true`, arrays are concatenated. If `false` (default), arrays are replaced.
|
|
43
|
+
*
|
|
44
|
+
* @default false
|
|
45
|
+
*/
|
|
46
|
+
appendArray?: boolean, /** One or more objects to deeply merge */
|
|
47
|
+
...sources: object[]): object;
|
|
48
|
+
//#endregion
|
|
49
|
+
export { mergeObj };
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
function e(t=!1,...n){let r=e=>typeof e==`object`&&!!e,i={};for(let a of n)if(r(a))for(let n of Object.keys(a)){let o=a[n],s=i[n];Array.isArray(o)?i[n]=t&&Array.isArray(s)?[...s,...o]:[...o]:r(o)&&!Array.isArray(o)?i[n]=r(s)&&!Array.isArray(s)?e(t,s,o):e(t,{},o):i[n]=o}return i}export{e as mergeObj};
|
package/package.json
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@js-utils-kit/object",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Object utilities",
|
|
5
|
+
"private": false,
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"author": {
|
|
8
|
+
"name": "Sriman",
|
|
9
|
+
"email": "136729116+TenEplaysOfficial@users.noreply.github.com",
|
|
10
|
+
"url": "https://tene.vercel.app"
|
|
11
|
+
},
|
|
12
|
+
"homepage": "https://js-utils.js.org",
|
|
13
|
+
"repository": {
|
|
14
|
+
"type": "git",
|
|
15
|
+
"url": "https://github.com/teneplaysofficial/js-utils-kit",
|
|
16
|
+
"directory": "packages/object"
|
|
17
|
+
},
|
|
18
|
+
"bugs": {
|
|
19
|
+
"url": "https://github.com/teneplaysofficial/js-utils-kit/issues"
|
|
20
|
+
},
|
|
21
|
+
"files": [
|
|
22
|
+
"dist"
|
|
23
|
+
],
|
|
24
|
+
"engines": {
|
|
25
|
+
"node": ">=22"
|
|
26
|
+
},
|
|
27
|
+
"type": "module",
|
|
28
|
+
"main": "./dist/index.cjs",
|
|
29
|
+
"module": "./dist/index.mjs",
|
|
30
|
+
"types": "./dist/index.d.cts",
|
|
31
|
+
"exports": {
|
|
32
|
+
".": {
|
|
33
|
+
"import": "./dist/index.mjs",
|
|
34
|
+
"require": "./dist/index.cjs"
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
"dependencies": {},
|
|
38
|
+
"scripts": {
|
|
39
|
+
"build": "tsdown",
|
|
40
|
+
"test": "vitest run"
|
|
41
|
+
}
|
|
42
|
+
}
|