@eggjs/extend2 4.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 ADDED
@@ -0,0 +1,23 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017-present eggjs and other contributors.
4
+ Copyright (c) 2014 Stefan Thomas
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining
7
+ a copy of this software and associated documentation files (the
8
+ "Software"), to deal in the Software without restriction, including
9
+ without limitation the rights to use, copy, modify, merge, publish,
10
+ distribute, sublicense, and/or sell copies of the Software, and to
11
+ permit persons to whom the Software is furnished to do so, subject to
12
+ the following conditions:
13
+
14
+ The above copyright notice and this permission notice shall be
15
+ included in all copies or substantial portions of the Software.
16
+
17
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,51 @@
1
+ # @eggjs/extend2
2
+
3
+ Forked from [node-extend], the difference is overriding array as primitive when deep clone.
4
+
5
+ [![NPM version][npm-image]][npm-url]
6
+ [![Known Vulnerabilities][snyk-image]][snyk-url]
7
+ [![npm download][download-image]][download-url]
8
+
9
+ [npm-image]: https://img.shields.io/npm/v/@eggjs/extend2.svg?style=flat-square
10
+ [npm-url]: https://npmjs.org/package/@eggjs/extend2
11
+ [snyk-image]: https://snyk.io/test/npm/extend2/badge.svg?style=flat-square
12
+ [snyk-url]: https://snyk.io/test/npm/@eggjs/extend2
13
+ [download-image]: https://img.shields.io/npm/dm/@eggjs/extend2.svg?style=flat-square
14
+ [download-url]: https://npmjs.org/package/@eggjs/extend2
15
+
16
+ ## Usage
17
+
18
+ ```ts
19
+ import { extend } from '@eggjs/extend2';
20
+
21
+ // for deep clone
22
+ extend(true, {}, object1, objectN);
23
+ ```
24
+
25
+ ## License
26
+
27
+ `@eggjs/extend2` is licensed under the [MIT License](LICENSE).
28
+
29
+ ## Acknowledgements
30
+
31
+ All credit to the jQuery authors for perfecting this amazing utility.
32
+
33
+ Ported to Node.js by [Stefan Thomas][github-justmoon] with contributions by [Jonathan Buchanan][github-insin] and [Jordan Harband][github-ljharb].
34
+
35
+ <!-- GITCONTRIBUTOR_START -->
36
+
37
+ ## Contributors
38
+
39
+ | [<img src="https://avatars.githubusercontent.com/u/45469?v=4" width="100px;"/><br/><sub><b>ljharb</b></sub>](https://github.com/ljharb)<br/> | [<img src="https://avatars.githubusercontent.com/u/53233?v=4" width="100px;"/><br/><sub><b>justmoon</b></sub>](https://github.com/justmoon)<br/> | [<img src="https://avatars.githubusercontent.com/u/1557266?v=4" width="100px;"/><br/><sub><b>jonmorehouse</b></sub>](https://github.com/jonmorehouse)<br/> | [<img src="https://avatars.githubusercontent.com/u/360661?v=4" width="100px;"/><br/><sub><b>popomore</b></sub>](https://github.com/popomore)<br/> | [<img src="https://avatars.githubusercontent.com/u/2396468?v=4" width="100px;"/><br/><sub><b>greelgorke</b></sub>](https://github.com/greelgorke)<br/> | [<img src="https://avatars.githubusercontent.com/u/273857?v=4" width="100px;"/><br/><sub><b>andyburke</b></sub>](https://github.com/andyburke)<br/> |
40
+ | :-------------------------------------------------------------------------------------------------------------------------------------------------: | :----------------------------------------------------------------------------------------------------------------------------------------------: | :--------------------------------------------------------------------------------------------------------------------------------------------------------: | :-----------------------------------------------------------------------------------------------------------------------------------------------: | :----------------------------------------------------------------------------------------------------------------------------------------------------: | :-------------------------------------------------------------------------------------------------------------------------------------------------: |
41
+ | [<img src="https://avatars.githubusercontent.com/u/788368?v=4" width="100px;"/><br/><sub><b>blaise-io</b></sub>](https://github.com/blaise-io)<br/> | [<img src="https://avatars.githubusercontent.com/u/680696?v=4" width="100px;"/><br/><sub><b>danbell</b></sub>](https://github.com/danbell)<br/> | [<img src="https://avatars.githubusercontent.com/u/2598089?v=4" width="100px;"/><br/><sub><b>jamielinux</b></sub>](https://github.com/jamielinux)<br/> | [<img src="https://avatars.githubusercontent.com/u/226692?v=4" width="100px;"/><br/><sub><b>insin</b></sub>](https://github.com/insin)<br/> | [<img src="https://avatars.githubusercontent.com/u/152407?v=4" width="100px;"/><br/><sub><b>madarche</b></sub>](https://github.com/madarche)<br/> | [<img src="https://avatars.githubusercontent.com/u/1088720?v=4" width="100px;"/><br/><sub><b>Mithgol</b></sub>](https://github.com/Mithgol)<br/> |
42
+ | [<img src="https://avatars.githubusercontent.com/u/156269?v=4" width="100px;"/><br/><sub><b>fengmk2</b></sub>](https://github.com/fengmk2)<br/> | [<img src="https://avatars.githubusercontent.com/u/5362563?v=4" width="100px;"/><br/><sub><b>2hu12</b></sub>](https://github.com/2hu12)<br/> |
43
+
44
+ This project follows the git-contributor [spec](https://github.com/xudafeng/git-contributor), auto updated at `Sat Jun 15 2024 10:08:30 GMT+0800`.
45
+
46
+ <!-- GITCONTRIBUTOR_END -->
47
+
48
+ [github-justmoon]: https://github.com/justmoon
49
+ [github-insin]: https://github.com/insin
50
+ [github-ljharb]: https://github.com/ljharb
51
+ [node-extend]: https://github.com/justmoon/node-extend
@@ -0,0 +1,4 @@
1
+ //#region src/index.d.ts
2
+ declare function extend<T = Record<string, any>>(deepOrTarget?: unknown, ...objects: unknown[]): T;
3
+ //#endregion
4
+ export { extend as default, extend };
package/dist/index.js ADDED
@@ -0,0 +1,42 @@
1
+ //#region src/index.ts
2
+ const hasOwn = Object.prototype.hasOwnProperty;
3
+ const toStr = Object.prototype.toString;
4
+ function isPlainObject(obj) {
5
+ if (!obj || toStr.call(obj) !== "[object Object]") return false;
6
+ const hasOwnConstructor = hasOwn.call(obj, "constructor");
7
+ const hasIsPrototypeOf = obj.constructor && obj.constructor.prototype && hasOwn.call(obj.constructor.prototype, "isPrototypeOf");
8
+ if (obj.constructor && !hasOwnConstructor && !hasIsPrototypeOf) return false;
9
+ let key;
10
+ for (key in obj);
11
+ return typeof key === "undefined" || hasOwn.call(obj, key);
12
+ }
13
+ function extend(deepOrTarget, ...objects) {
14
+ let target = deepOrTarget;
15
+ let i = 0;
16
+ const length = objects.length;
17
+ let deep = false;
18
+ if (typeof target === "boolean") {
19
+ deep = target;
20
+ target = objects[0] || {};
21
+ i = 1;
22
+ } else if (typeof target !== "object" && typeof target !== "function" || target == null) target = {};
23
+ for (; i < length; ++i) {
24
+ const options = objects[i];
25
+ if (options === null || options === void 0) continue;
26
+ for (const name in options) {
27
+ if (name === "__proto__") continue;
28
+ const src = target[name];
29
+ const copy = options[name];
30
+ if (target === copy) continue;
31
+ if (deep && copy && isPlainObject(copy)) {
32
+ const clone = src && isPlainObject(src) ? src : {};
33
+ target[name] = extend(deep, clone, copy);
34
+ } else if (typeof copy !== "undefined") target[name] = copy;
35
+ }
36
+ }
37
+ return target;
38
+ }
39
+ var src_default = extend;
40
+
41
+ //#endregion
42
+ export { src_default as default, extend };
package/package.json ADDED
@@ -0,0 +1,53 @@
1
+ {
2
+ "name": "@eggjs/extend2",
3
+ "author": "popomore <sakura9515@gmail.com>",
4
+ "version": "4.0.0",
5
+ "engines": {
6
+ "node": ">=18.7.0"
7
+ },
8
+ "publishConfig": {
9
+ "access": "public",
10
+ "exports": {
11
+ ".": "./dist/index.js",
12
+ "./package.json": "./package.json"
13
+ }
14
+ },
15
+ "description": "Port of jQuery.extend for Node.js",
16
+ "scripts": {
17
+ "build": "tsdown",
18
+ "clean": "rimraf dist",
19
+ "lint": "oxlint",
20
+ "test": "vitest run",
21
+ "prepublishOnly": "pnpm run build"
22
+ },
23
+ "keywords": [
24
+ "extend",
25
+ "clone",
26
+ "merge"
27
+ ],
28
+ "repository": {
29
+ "type": "git",
30
+ "url": "git+https://github.com/eggjs/egg.git",
31
+ "directory": "packages/extend2"
32
+ },
33
+ "devDependencies": {
34
+ "@eggjs/tsconfig": "catalog:",
35
+ "@types/node": "catalog:",
36
+ "oxlint": "catalog:",
37
+ "tsdown": "catalog:",
38
+ "typescript": "catalog:",
39
+ "vitest": "catalog:"
40
+ },
41
+ "license": "MIT",
42
+ "files": [
43
+ "dist"
44
+ ],
45
+ "type": "module",
46
+ "exports": {
47
+ ".": "./src/index.ts",
48
+ "./package.json": "./package.json"
49
+ },
50
+ "main": "./dist/index.js",
51
+ "types": "./dist/index.d.ts",
52
+ "module": "./dist/index.js"
53
+ }