Gathering detailed insights and metrics for klona
Gathering detailed insights and metrics for klona
Gathering detailed insights and metrics for klona
Gathering detailed insights and metrics for klona
A tiny (240B to 501B) and fast utility to "deep clone" Objects, Arrays, Dates, RegExps, and more!
npm install klona
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
1,622 Stars
99 Commits
43 Forks
13 Watching
2 Branches
8 Contributors
Updated on 28 Nov 2024
JavaScript (100%)
Cumulative downloads
Total Downloads
Last day
-5.6%
1,955,521
Compared to previous day
Last week
1.1%
10,837,370
Compared to previous week
Last month
2.8%
46,460,152
Compared to previous month
Last year
-8.5%
568,785,126
Compared to previous year
Unlike a "shallow copy" (eg, Object.assign
), a "deep clone" recursively traverses a source input and copies its values — instead of references to its values — into a new instance of that input. The result is a structurally equivalent clone that operates independently of the original source and controls its own values.
Why "klona"? It's "clone" in Swedish.
What's with the sheep? Dolly.
$ npm install --save klona
There are multiple "versions" of klona
available, which allows you to bring only the functionality you need!
klona/json
Size (gzip): 240 bytes
Availability: CommonJS, ES Module, UMD
Ability: JSON data types
1import { klona } from 'klona/json';
klona/lite
Size (gzip): 354 bytes
Availability: CommonJS, ES Module, UMD
Ability: extendsklona/json
with support for custom class, Date, and RegExp
1import { klona } from 'klona/lite';
klona
Size (gzip): 451 bytes
Availability: CommonJS, ES Module, UMD
Ability: extendsklona/lite
with support for Map, Set, DataView, ArrayBuffer, TypedArray
1import { klona } from 'klona';
klona/full
Size (gzip): 501 bytes
Availability: CommonJS, ES Module, UMD
Ability: extendsklona
with support for Symbol properties and non-enumerable properties
1import { klona } from 'klona/full';
1import { klona } from 'klona'; 2 3const input = { 4 foo: 1, 5 bar: { 6 baz: 2, 7 bat: { 8 hello: 'world' 9 } 10 } 11}; 12 13const output = klona(input); 14 15// exact copy of original 16assert.deepStrictEqual(input, output); 17 18// applying deep updates... 19output.bar.bat.hola = 'mundo'; 20output.bar.baz = 99; 21 22// ...doesn't affect source! 23console.log( 24 JSON.stringify(input, null, 2) 25); 26// { 27// "foo": 1, 28// "bar": { 29// "baz": 2, 30// "bat": { 31// "hello": "world" 32// } 33// } 34// }
Returns: typeof input
Returns a deep copy/clone of the input.
Running Node v12.18.3
The benchmarks can be found in the /bench
directory. They are separated into multiple categories:
JSON
– compares an array of objects comprised of JSON data types (String
, Number
, null
, Array
, Object
)LITE
– like JSON
, but adds RegExp
, Date
and undefined
valuesDEFAULT
– object with RegExp
, Date
, Array
, Map
, Set
, custom class, Int8Array
, DataView
, Buffer
valuesFULL
– like DEFAULT
, but adds Symbol
and non-enumerable propertiesImportant: Only candidates that pass validation step(s) are listed.
However,lodash
andclone
are kept to highlight important differences.
Note: The
clone/include
candidate refers to itsincludeNonEnumerable
option enabled.
Load times:
lodash/clonedeep 29.257ms
rfdc 0.511ms
clone 0.576ms
clone-deep 2.494ms
deep-copy 0.451ms
klona/full 0.408ms
klona 0.265ms
klona/lite 0.308ms
klona/json 0.263ms
Benchmark :: JSON
JSON.stringify x 53,899 ops/sec ±0.76% (92 runs sampled)
lodash x 46,800 ops/sec ±0.86% (90 runs sampled)
rfdc x 221,456 ops/sec ±0.88% (92 runs sampled)
clone x 39,537 ops/sec ±0.68% (92 runs sampled)
clone/include x 25,488 ops/sec ±1.06% (88 runs sampled)
clone-deep x 99,998 ops/sec ±0.91% (93 runs sampled)
deep-copy x 141,270 ops/sec ±0.95% (92 runs sampled)
klona/full x 55,016 ops/sec ±0.68% (94 runs sampled)
klona x 281,215 ops/sec ±0.77% (93 runs sampled)
klona/lite x 318,481 ops/sec ±0.72% (91 runs sampled)
klona/json x 334,932 ops/sec ±0.66% (93 runs sampled)
Benchmark :: LITE
lodash x 36,992 ops/sec ±0.65% (91 runs sampled)
clone x 35,974 ops/sec ±1.13% (88 runs sampled)
clone/include x 22,609 ops/sec ±1.02% (91 runs sampled)
clone-deep x 92,846 ops/sec ±0.66% (93 runs sampled)
klona/full x 47,873 ops/sec ±0.83% (88 runs sampled)
klona x 226,638 ops/sec ±1.16% (93 runs sampled)
klona/lite x 257,900 ops/sec ±0.82% (93 runs sampled)
Benchmark :: DEFAULT
lodash x 55,914 ops/sec ±0.75% (93 runs sampled)
✘ Buffer
✘ Map keys
clone x 92,127 ops/sec ±0.83% (94 runs sampled)
✘ DataView
clone/include x 62,052 ops/sec ±0.88% (93 runs sampled)
✘ DataView
klona/full x 90,308 ops/sec ±0.68% (89 runs sampled)
klona x 230,257 ops/sec ±0.71% (91 runs sampled)
Benchmark :: FULL
lodash x 60,361 ops/sec ±0.65% (91 runs sampled)
✘ Buffer
✘ Map keys
✘ Missing non-enumerable Properties
clone/include x 47,263 ops/sec ±0.85% (93 runs sampled)
✘ DataView
✘ Incorrect non-enumerable Properties
klona/full x 82,346 ops/sec ±0.62% (93 runs sampled)
MIT © Luke Edwards
The latest stable version of the package.
Stable Version
2
9.8/10
Summary
Improper Input Validation in klona
Affected Versions
<= 1.1.0
Patched Versions
1.1.1
0/10
Summary
Prototype Pollution in klona
Affected Versions
< 1.1.1
Patched Versions
1.1.1
Reason
no binaries found in the repo
Reason
no dangerous workflow patterns detected
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
Reason
Found 4/24 approved changesets -- score normalized to 1
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
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2024-11-18
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