Gathering detailed insights and metrics for copy-anything
Gathering detailed insights and metrics for copy-anything
Gathering detailed insights and metrics for copy-anything
Gathering detailed insights and metrics for copy-anything
An optimised way to copy'ing (cloning) an Object or Array. A small and simple integration
npm install copy-anything
Typescript
Module System
Min. Node Version
Node Version
NPM Version
99.7
Supply Chain
100
Quality
78.5
Maintenance
100
Vulnerability
100
License
TypeScript (97.79%)
JavaScript (2.21%)
Total Downloads
877,422,623
Last Day
335,539
Last Week
8,183,640
Last Month
35,017,269
Last Year
342,744,480
MIT License
48 Stars
82 Commits
9 Forks
2 Watchers
8 Branches
2 Contributors
Updated on May 09, 2025
Latest Version
4.0.5
Package Id
copy-anything@4.0.5
Unpacked Size
9.76 kB
Size
3.88 kB
File Count
5
NPM Version
10.9.2
Node Version
22.14.0
Published on
Mar 24, 2025
Cumulative downloads
Total Downloads
Last Day
-3.3%
335,539
Compared to previous day
Last Week
-7.8%
8,183,640
Compared to previous week
Last Month
4.8%
35,017,269
Compared to previous month
Last Year
38%
342,744,480
Compared to previous year
1
5
npm i copy-anything
An optimised way to copy'ing (cloning) an object or array. A small and simple integration.
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 was looking for:
This last one is crucial! So many libraries use custom classes that create objects with special prototypes, and such objects all break when trying to copy them improperly. So we gotta be careful!
copy-anything will copy objects and nested properties, but only as long as they're "plain objects". As soon as a sub-prop is not a "plain object" and has a special prototype, it will copy that instance over "as is". ♻️
1import { copy } from 'copy-anything' 2 3const original = { name: 'Ditto', type: { water: true } } 4const copy = copy(original) 5 6// now if we change a nested prop like the type 7copy.type.water = false 8// or add a new nested prop 9copy.type.fire = true 10 11// then the original object will still be the same: 12(original.type.water === true) // true 13(original.type.fire === undefined) // true
Please note, by default copy-anything does not copy non-enumerable props. If you need to copy those, see the instructions further down below.
It will also clone arrays, as well as objects inside arrays! 😉
1const original = [{ name: 'Squirtle' }] 2const copy = copy(original) 3 4// now if we change a prop in the array 5copy[0].name = 'Wartortle' 6// or add a new item to the array 7copy.push({ name: 'Charmander' }) 8 9// then the original array will still be the same: 10(original[0].name === 'Squirtle') // true 11(original[1] === undefined) // true
By default, copy-anything only copies enumerable properties. If you also want to copy non-enumerable properties you can do so by passing that as an option.
1const original = { name: 'Bulbasaur' } 2// bulbasaur's ID is non-enumerable 3Object.defineProperty(original, 'id', { 4 value: '001', 5 writable: true, 6 enumerable: false, 7 configurable: true, 8}) 9const copy1 = copy(original) 10(copy1.id === undefined) // true 11 12const copy2 = copy(original, { nonenumerable: true }) 13(copy2.id === '001') // true
You can limit to specific props.
1const original = { name: 'Flareon', type: ['fire'], id: '136' } 2const copy = copy(original, { props: ['name'] }) 3 4(copy) // will look like: `{ name: 'Flareon' }`
Please note, if the props you have specified are non-enumerable, you will also need to pass
{nonenumerable: true}
.
The source code is literally just these lines. Most of the magic comes from the isPlainObject function from the is-what library.
1import { isPlainObject } from 'is-what' 2 3export function copy (target) { 4 if (isArray(target)) return target.map(i => copy(i)) 5 if (!isPlainObject(target)) return target 6 return Object.keys(target) 7 .reduce((carry, key) => { 8 const val = target[key] 9 carry[key] = copy(val) 10 return carry 11 }, {}) 12}
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
no dangerous workflow patterns detected
Reason
license file detected
Details
Reason
5 existing vulnerabilities detected
Details
Reason
dependency not pinned by hash detected -- score normalized to 3
Details
Reason
Found 1/30 approved changesets -- score normalized to 0
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
Reason
security policy file not detected
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
branch protection not enabled on development/release branches
Details
Score
Last Scanned on 2025-06-23
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More