Gathering detailed insights and metrics for realistic-structured-clone
Gathering detailed insights and metrics for realistic-structured-clone
Gathering detailed insights and metrics for realistic-structured-clone
Gathering detailed insights and metrics for realistic-structured-clone
A pure JS implementation of the structured clone algorithm (or at least something pretty close to that).
npm install realistic-structured-clone
Typescript
Module System
Node Version
NPM Version
JavaScript (100%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
25 Stars
58 Commits
8 Forks
5 Watchers
3 Branches
4 Contributors
Updated on Apr 29, 2022
Latest Version
3.0.0
Package Id
realistic-structured-clone@3.0.0
Unpacked Size
92.13 kB
Size
21.92 kB
File Count
3
NPM Version
8.5.2
Node Version
17.7.1
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
3
6
You might not need this anymore! A native structuredClone
function is available in many recent environments, such as Node v17 and Firefox v94. Check if your target environment has structuredClone
built in. If it does, use that.
This is a pure JS implementation of the structured clone algorithm (or at least something pretty close to that).
Why do you want this? Well, you probably don't. If your goal is to just clone a JS object, you're better off with lodash's _.cloneDeep or the popular clone
module on npm.
Let's try again... why do you want this? If you are making an implementation of an API that explicitly uses the structured clone algorithm (such as IndexedDB), then you want something that handles quirks and edge cases exactly like the structured clone algorithm. That's what realistic-structured-clone
is for. It's not totally there (see below) but it's a decent start.
$ npm install realistic-structured-clone
Then use it:
// First load the module
// (Use Browserify or something if you're targeting the web)
var structuredClone = require('realistic-structured-clone');
// Clone a variable (will throw a DataCloneError for invalid input)
var clonedX = structuredClone(x);
If you look around, you'll notice various modules calling themselves implementations of the structured clone algorithm, such as the structured-clone
package on npm. But that package, like all the others I've seen, doesn't actually seem to be an attempt at implementing the structured clone algorithm. It's just some arbitrary type of clone. As I wrote above, this distinction only matters if you really care about the nuances of the structured clone algorithm, which you probably don't.
If you're working in the browser, you can do something like this to do a real structured clone:
function clone(x) {
return new Promise(function (resolve, reject) {
window.addEventListener('message', function(e) {
resolve(e.data);
});
window.postMessage(x, "*");
});
}
var x = {a:[1,2,3], b:{c:1}};
clone(x).then(function(cloned) {
console.log("x: %s", JSON.stringify(x));
console.log("cloned: %s", JSON.stringify(cloned));
console.log("x == cloned %s", x == cloned);
console.log("x === cloned %s", x === cloned);
});
However, that won't help you in Node.js. It's also asynchronous, which could be a problem. realistic-structured-clone
is synchronous and works everywhere.
As of version 2.0, it should be pretty damn close to the spec! However it is now just a light wrapper around the Typeson structured-cloning-throwing preset.
Apache 2.0
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
no dangerous workflow patterns detected
Reason
Found 4/26 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
license 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
Reason
17 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-07-07
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