@alwatr/deep-clone 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/CHANGELOG.md ADDED
@@ -0,0 +1,10 @@
1
+ # Change Log
2
+
3
+ All notable changes to this project will be documented in this file.
4
+ See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
+
6
+ # 1.0.0 (2023-12-22)
7
+
8
+ ### Features
9
+
10
+ * **deep-clone:** new package for deep clone obj/array ([9ac5379](https://github.com/Alwatr/nanolib/commit/9ac5379bd579b85d165a79b75bb782654167430d)) by @AliMD
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2022 S. Ali Mihandoost
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,28 @@
1
+ # Deep Clone
2
+
3
+ Clone deeply nested objects and arrays in JavaScript.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ yarn add @alwatr/deep-clone
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```typescript
14
+ import {deepClone} from '@alwatr/deep-clone';
15
+
16
+ const obj1 = {
17
+ a: 1,
18
+ b: {
19
+ c: 2,
20
+ d: [3, 4, 5],
21
+ },
22
+ };
23
+
24
+ const obj2 = deepClone(obj1);
25
+
26
+ obj2.b.c = 6;
27
+ console.log(obj1.b.c); // 2
28
+ ```
package/demo/bench.mjs ADDED
@@ -0,0 +1,16 @@
1
+ import {deepClone} from '@alwatr/deep-clone';
2
+
3
+ const obj1 = {};
4
+ for (let i = 0; i < 100; i++) {
5
+ obj1[i] = { a: 1, b: { c: 2 } };
6
+ }
7
+
8
+ console.log('start');
9
+
10
+ const startTime = performance.now();
11
+
12
+ for (let i = 1; i <= 100_000; i++) {
13
+ const obj2 = deepClone(obj1);
14
+ }
15
+
16
+ console.log(`Execution time: ${Math.round(performance.now() - startTime)}ms`);
package/dist/main.cjs ADDED
@@ -0,0 +1,3 @@
1
+ /* @alwatr/deep-clone v1.0.0 */
2
+ "use strict";var o=Object.defineProperty;var t=Object.getOwnPropertyDescriptor;var T=Object.getOwnPropertyNames;var i=Object.prototype.hasOwnProperty;var d=(n,e)=>{for(var u in e)o(n,u,{get:e[u],enumerable:!0})},f=(n,e,u,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let l of T(e))!i.call(n,l)&&l!==u&&o(n,l,{get:()=>e[l],enumerable:!(r=t(e,l))||r.enumerable});return n};var p=n=>f(o({},"__esModule",{value:!0}),n);var x={};d(x,{deepClone:()=>c});module.exports=p(x);function c(n){return n==null?null:JSON.parse(JSON.stringify(n))}0&&(module.exports={deepClone});
3
+ //# sourceMappingURL=main.cjs.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/main.ts"],
4
+ "sourcesContent": ["/**\n * Clone deeply nested objects and arrays.\n *\n * @param obj The object to clone.\n * @returns A clone of the object.\n * @example\n * ```typescript\n * const obj2 = deepClone(obj1);\n * ```\n */\nexport function deepClone<T>(obj: T): T;\n\n/**\n * Clone deeply nested objects and arrays.\n *\n * if the object is null or undefined, it returns null.\n *\n * @param obj The object to clone.\n * @returns A clone of the object.\n * @example\n * ```typescript\n * const obj2 = deepClone(obj1);\n * ```\n */\nexport function deepClone<T>(obj: T | null | undefined): T | null;\n\nexport function deepClone<T>(obj: T | null | undefined): T | null {\n if (obj == null) return null;\n return JSON.parse(JSON.stringify(obj));\n}\n"],
5
+ "mappings": ";yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,eAAAE,IAAA,eAAAC,EAAAH,GA0BO,SAASE,EAAaE,EAAqC,CAChE,OAAIA,GAAO,KAAa,KACjB,KAAK,MAAM,KAAK,UAAUA,CAAG,CAAC,CACvC",
6
+ "names": ["main_exports", "__export", "deepClone", "__toCommonJS", "obj"]
7
+ }
package/dist/main.d.ts ADDED
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Clone deeply nested objects and arrays.
3
+ *
4
+ * @param obj The object to clone.
5
+ * @returns A clone of the object.
6
+ * @example
7
+ * ```typescript
8
+ * const obj2 = deepClone(obj1);
9
+ * ```
10
+ */
11
+ export declare function deepClone<T>(obj: T): T;
12
+ /**
13
+ * Clone deeply nested objects and arrays.
14
+ *
15
+ * if the object is null or undefined, it returns null.
16
+ *
17
+ * @param obj The object to clone.
18
+ * @returns A clone of the object.
19
+ * @example
20
+ * ```typescript
21
+ * const obj2 = deepClone(obj1);
22
+ * ```
23
+ */
24
+ export declare function deepClone<T>(obj: T | null | undefined): T | null;
25
+ //# sourceMappingURL=main.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"main.d.ts","sourceRoot":"","sources":["../src/main.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,wBAAgB,SAAS,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,GAAG,CAAC,CAAC;AAExC;;;;;;;;;;;GAWG;AACH,wBAAgB,SAAS,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,GAAG,IAAI,GAAG,SAAS,GAAG,CAAC,GAAG,IAAI,CAAC"}
package/dist/main.mjs ADDED
@@ -0,0 +1,3 @@
1
+ /* @alwatr/deep-clone v1.0.0 */
2
+ function e(n){return n==null?null:JSON.parse(JSON.stringify(n))}export{e as deepClone};
3
+ //# sourceMappingURL=main.mjs.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/main.ts"],
4
+ "sourcesContent": ["/**\n * Clone deeply nested objects and arrays.\n *\n * @param obj The object to clone.\n * @returns A clone of the object.\n * @example\n * ```typescript\n * const obj2 = deepClone(obj1);\n * ```\n */\nexport function deepClone<T>(obj: T): T;\n\n/**\n * Clone deeply nested objects and arrays.\n *\n * if the object is null or undefined, it returns null.\n *\n * @param obj The object to clone.\n * @returns A clone of the object.\n * @example\n * ```typescript\n * const obj2 = deepClone(obj1);\n * ```\n */\nexport function deepClone<T>(obj: T | null | undefined): T | null;\n\nexport function deepClone<T>(obj: T | null | undefined): T | null {\n if (obj == null) return null;\n return JSON.parse(JSON.stringify(obj));\n}\n"],
5
+ "mappings": ";AA0BO,SAASA,EAAaC,EAAqC,CAChE,OAAIA,GAAO,KAAa,KACjB,KAAK,MAAM,KAAK,UAAUA,CAAG,CAAC,CACvC",
6
+ "names": ["deepClone", "obj"]
7
+ }
package/package.json ADDED
@@ -0,0 +1,64 @@
1
+ {
2
+ "name": "@alwatr/deep-clone",
3
+ "version": "1.0.0",
4
+ "description": "Clone deeply nested objects and arrays in JavaScript.",
5
+ "author": "S. Ali Mihandoost <ali.mihandoost@gmail.com>",
6
+ "keywords": [
7
+ "deep-clone",
8
+ "clone",
9
+ "object",
10
+ "copy",
11
+ "typescript",
12
+ "esm",
13
+ "alwatr"
14
+ ],
15
+ "type": "module",
16
+ "main": "./dist/main.cjs",
17
+ "module": "./dist/main.mjs",
18
+ "types": "./dist/main.d.ts",
19
+ "exports": {
20
+ ".": {
21
+ "import": "./dist/main.mjs",
22
+ "require": "./dist/main.cjs",
23
+ "types": "./dist/main.d.ts"
24
+ }
25
+ },
26
+ "license": "MIT",
27
+ "files": [
28
+ "**/*.{d.ts.map,d.ts,js.map,js,html,md,cjs,mjs,cjs.map,mjs.map}"
29
+ ],
30
+ "publishConfig": {
31
+ "access": "public"
32
+ },
33
+ "repository": {
34
+ "type": "git",
35
+ "url": "https://github.com/Alwatr/nanolib",
36
+ "directory": "packages/deep-clone"
37
+ },
38
+ "homepage": "https://github.com/Alwatr/nanolib/tree/next/packages/deep-clone#readme",
39
+ "bugs": {
40
+ "url": "https://github.com/Alwatr/nanolib/issues"
41
+ },
42
+ "prettier": "@alwatr/prettier-config",
43
+ "scripts": {
44
+ "b": "yarn run build",
45
+ "w": "yarn run watch",
46
+ "c": "yarn run clean",
47
+ "cb": "yarn run clean && yarn run build",
48
+ "d": "yarn run build:es && ALWATR_DEBUG=1 yarn node",
49
+ "build": "yarn run build:ts & yarn run build:es",
50
+ "build:es": "nano-build",
51
+ "build:ts": "tsc --build",
52
+ "watch": "yarn run watch:ts & yarn run watch:es",
53
+ "watch:es": "yarn run build:es --watch",
54
+ "watch:ts": "yarn run build:ts --watch --preserveWatchOutput",
55
+ "clean": "rm -rfv dist .tsbuildinfo"
56
+ },
57
+ "devDependencies": {
58
+ "@alwatr/nano-build": "^1.0.1",
59
+ "@alwatr/prettier-config": "^1.0.1",
60
+ "@alwatr/tsconfig-base": "^1.0.1",
61
+ "typescript": "^5.3.3"
62
+ },
63
+ "gitHead": "6c30d421d36a77375653b67ec1f46b5c1020094e"
64
+ }