Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

copy-anything

Package Overview
Dependencies
Maintainers
1
Versions
30
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

copy-anything - npm Package Compare versions

Comparing version 3.0.5 to 4.0.0

6

dist/index.d.ts

@@ -1,2 +0,2 @@

type Options = {
export type Options = {
props?: (string | symbol)[];

@@ -12,4 +12,2 @@ nonenumerable?: boolean;

*/
declare function copy<T>(target: T, options?: Options): T;
export { Options, copy };
export declare function copy<T>(target: T, options?: Options): T;
import { isArray, isPlainObject } from 'is-what';
function assignProp(carry, key, newVal, originalObject, includeNonenumerable) {
const propType = {}.propertyIsEnumerable.call(originalObject, key) ? "enumerable" : "nonenumerable";
if (propType === "enumerable")
carry[key] = newVal;
if (includeNonenumerable && propType === "nonenumerable") {
Object.defineProperty(carry, key, {
value: newVal,
enumerable: false,
writable: true,
configurable: true
});
}
const propType = {}.propertyIsEnumerable.call(originalObject, key)
? 'enumerable'
: 'nonenumerable';
if (propType === 'enumerable')
carry[key] = newVal;
if (includeNonenumerable && propType === 'nonenumerable') {
Object.defineProperty(carry, key, {
value: newVal,
enumerable: false,
writable: true,
configurable: true,
});
}
}
function copy(target, options = {}) {
if (isArray(target)) {
return target.map((item) => copy(item, options));
}
if (!isPlainObject(target)) {
return target;
}
const props = Object.getOwnPropertyNames(target);
const symbols = Object.getOwnPropertySymbols(target);
return [...props, ...symbols].reduce((carry, key) => {
if (isArray(options.props) && !options.props.includes(key)) {
return carry;
/**
* Copy (clone) an object and all its props recursively to get rid of any prop referenced of the original object. Arrays are also cloned, however objects inside arrays are still linked.
*
* @param target Target can be anything
* @param [options = {}] Options can be `props` or `nonenumerable`
* @returns the target with replaced values
*/
export function copy(target, options = {}) {
if (isArray(target)) {
return target.map((item) => copy(item, options));
}
const val = target[key];
const newVal = copy(val, options);
assignProp(carry, key, newVal, target, options.nonenumerable);
return carry;
}, {});
if (!isPlainObject(target)) {
return target;
}
const props = Object.getOwnPropertyNames(target);
const symbols = Object.getOwnPropertySymbols(target);
return [...props, ...symbols].reduce((carry, key) => {
if (isArray(options.props) && !options.props.includes(key)) {
return carry;
}
const val = target[key];
const newVal = copy(val, options);
assignProp(carry, key, newVal, target, options.nonenumerable);
return carry;
}, {});
}
export { copy };
{
"name": "copy-anything",
"version": "3.0.5",
"version": "4.0.0",
"description": "An optimised way to copy'ing an object. A small and simple integration",
"type": "module",
"sideEffects": false,
"types": "./dist/index.d.ts",
"module": "./dist/index.js",
"main": "./dist/index.js",
"exports": {

@@ -22,13 +19,10 @@ ".": {

},
"files": [
"dist"
],
"engines": {
"node": ">=12.13"
"node": ">=18"
},
"scripts": {
"test": "vitest run",
"lint": "tsc --noEmit && eslint ./src --ext .ts",
"build": "rollup -c ./rollup.config.js",
"release": "npm run lint && del dist && npm run build && np"
"lint": "tsc --noEmit && eslint ./src",
"build": "del-cli dist && tsc",
"release": "npm run lint && npm run build && np"
},

@@ -39,16 +33,11 @@ "dependencies": {

"devDependencies": {
"@typescript-eslint/eslint-plugin": "^5.59.2",
"@typescript-eslint/parser": "^5.59.2",
"del-cli": "^5.0.0",
"eslint": "^8.40.0",
"eslint-config-prettier": "^8.8.0",
"eslint-plugin-tree-shaking": "^1.10.0",
"np": "^7.7.0",
"prettier": "^2.8.8",
"rollup": "^3.23.0",
"rollup-plugin-dts": "^5.3.0",
"rollup-plugin-esbuild": "^5.0.0",
"typescript": "^4.9.5",
"vitest": "^0.31.0"
"del-cli": "^5.1.0",
"np": "^10.0.5",
"vitest": "^1.6.0",
"@cycraft/eslint": "^0.3.0",
"@cycraft/tsconfig": "^0.1.2"
},
"files": [
"dist"
],
"keywords": [

@@ -68,44 +57,11 @@ "copy",

],
"author": "Luca Ban - Mesqueeb",
"author": "Luca Ban - Mesqueeb (https://cycraft.co)",
"funding": "https://github.com/sponsors/mesqueeb",
"license": "MIT",
"bugs": {
"url": "https://github.com/mesqueeb/copy-anything/issues"
},
"homepage": "https://github.com/mesqueeb/copy-anything#readme",
"repository": {
"type": "git",
"url": "git+https://github.com/mesqueeb/copy-anything.git"
"url": "https://github.com/mesqueeb/copy-anything.git"
},
"np": {
"yarn": false,
"branch": "production"
},
"eslintConfig": {
"ignorePatterns": [
"node_modules",
"dist",
"scripts",
"test"
],
"root": true,
"parser": "@typescript-eslint/parser",
"plugins": [
"@typescript-eslint",
"tree-shaking"
],
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended",
"prettier"
],
"rules": {
"@typescript-eslint/no-empty-function": "off",
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/ban-ts-ignore": "off",
"tree-shaking/no-side-effects-in-initialization": "error",
"@typescript-eslint/ban-ts-comment": "off"
}
}
"homepage": "https://github.com/mesqueeb/copy-anything#readme",
"bugs": "https://github.com/mesqueeb/copy-anything/issues"
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc