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 1.6.0 to 2.0.0

4

dist/index.cjs.js
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
var isWhat = require('is-what');

@@ -72,2 +74,2 @@

module.exports = copy;
exports.copy = copy;

@@ -70,2 +70,2 @@ import { isArray, isPlainObject } from 'is-what';

export default copy;
export { copy };
{
"name": "copy-anything",
"sideEffects": false,
"version": "1.6.0",
"version": "2.0.0",
"description": "An optimised way to copy'ing an object. A small and simple integration",

@@ -29,3 +29,5 @@ "main": "dist/index.cjs.js",

"deep-clone",
"deep-copy"
"deep-copy",
"typescript",
"ts"
],

@@ -54,9 +56,5 @@ "author": "Luca Ban - Mesqueeb",

"ava": {
"extensions": [
"ts"
],
"require": [
"ts-node/register"
]
"extensions": ["ts"],
"require": ["ts-node/register"]
}
}

@@ -11,3 +11,3 @@ # Copy anything 🎭

I created this package because I tried a lot of similar packages that do copy'ing/cloning. But all had its quirks, and *all of them break things they are not supposed to break*... 😞
I created this package because I tried a lot of similar packages that do copy'ing/cloning. But all had its quirks, and _all of them break things they are not supposed to break_... 😞

@@ -41,5 +41,5 @@ I was looking for:

```js
import copy from 'copy-anything'
import { copy } from 'copy-anything'
const original = {name: 'Ditto', type: {water: true}}
const original = { name: 'Ditto', type: { water: true } }
const copy = copy(original)

@@ -49,7 +49,8 @@

copy.type.water = false
copy.type.fire = true // new prop
copy.type.fire = true(
// new prop
// then the original object will still be the same:
(original.type.water === true)
(original.type.fire === undefined)
// then the original object will still be the same:
original.type.water === true
)(original.type.fire === undefined)
```

@@ -64,3 +65,3 @@

```js
const original = [{name: 'Squirtle'}]
const original = [{ name: 'Squirtle' }]
const copy = copy(original)

@@ -70,7 +71,8 @@

copy[0].name = 'Wartortle'
copy.push({name: 'Charmander'}) // new item
copy.push({ name: 'Charmander' })(
// new item
// then the original array will still be the same:
(original[0].name === 'Squirtle')
(original[1] === undefined)
// then the original array will still be the same:
original[0].name === 'Squirtle'
)(original[1] === undefined)
```

@@ -83,3 +85,3 @@

```js
const original = {name: 'Bulbasaur'}
const original = { name: 'Bulbasaur' }
// bulbasaur's ID is non-enumerable

@@ -90,9 +92,6 @@ Object.defineProperty(original, 'id', {

enumerable: false,
configurable: true
configurable: true,
})
const copy1 = copy(original)
const copy2 = copy(original, {nonenumerable: true})
(copy1.id === undefined)
(copy2.id === '001')
const copy2 = copy(original, { nonenumerable: true })(copy1.id === undefined)(copy2.id === '001')
```

@@ -105,6 +104,4 @@

```js
const original = {name: 'Flareon', type: ['fire'], id: '136'}
const copy = copy(original, {props: ['name']})
(copy === {name: 'Flareon'})
const original = { name: 'Flareon', type: ['fire'], id: '136' }
const copy = copy(original, { props: ['name'] })(copy === { name: 'Flareon' })
```

@@ -121,3 +118,3 @@

export default function copy (target) {
export function copy (target) {
if (isArray(target)) return target.map(i => copy(i))

@@ -124,0 +121,0 @@ if (!isPlainObject(target)) return target

@@ -39,3 +39,3 @@ import { isPlainObject, isArray } from 'is-what'

*/
export default function copy<T extends any> (target: T, options: Options = {}): T {
export function copy<T extends any> (target: T, options: Options = {}): T {
if (isArray(target)) return target.map((i: any) => copy(i, options))

@@ -42,0 +42,0 @@ if (!isPlainObject(target)) return target

import test from 'ava'
import copy from '../src/index'
import { copy } from '../src/index'

@@ -4,0 +4,0 @@ test('copy - change original', t => {

@@ -15,2 +15,2 @@ export declare type Options = {

*/
export default function copy<T extends any>(target: T, options?: Options): T;
export declare function copy<T extends any>(target: T, options?: Options): T;
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