![Create React App Officially Deprecated Amid React 19 Compatibility Issues](https://cdn.sanity.io/images/cgdhsj6q/production/04fa08cf844d798abc0e1a6391c129363cc7e2ab-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Create React App Officially Deprecated Amid React 19 Compatibility Issues
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.
A pure-javascript adaptation of the W3C's structured cloning algorithm, designed to provide an easy interface for deep copying of complex objects
Cyclone is an attempt to implement an adaptation of the HTML5 Structured Cloning Algorithm.
It is meant to be:
postMessage()
,
replaceState()
, etc), and therefore agnostic to types such as File
,
Blob
, etc (which also allows it to be synchronous in the first place).It can handle objects containing:
null
undefined
function Foo() { this.bar = 'baz' }; var cloneable = new Foo();
)This module exposes a single object, CY
, into the global scope when used within browsers. A client can then use
this module's clone
method to perform clone operations.
var o = {
date: new Date(),
number: Math.random()
};
o.self = o;
o.tricky = { self: o };
var c = CY.clone(o);
c === o; // false
c.date === o.date; // false
+(c.date) === +(o.date); // true
c.number === o.number; // true
c.self === c; // true
c.tricky.self === c; // true
Note that cycloneJS also supports AMD loading as well as use within nodeJS/CJS environments, so with node you could do something like
var CY = require('cyclonejs');
// Do some CY.clone()-ing
CY.clone
takes an options hash as a second argument, which accepts the following parameters:
allowFunctions
: (default: false
) If set to true, CY.clone
will simply pass functions through to the copied object, instead of throwing an error saying it can't clone a function.var fnObject = {
f: function() {}
};
var copy = CY.clone(fnObject, {
allowFunctions: true
});
console.log(copy.f === fnObject.f) // true
suppressErrors
: (default: false
) If set to true, CY.clone
will return null
instead of throwing an Error if it comes across an object it doesn't know how to clone. If you need CY.clone
to be extremely forgiving, this is the option for you.var mixedBag = {
htmlElement: document.createElement('div'),
ctx: document.getElementsByTagName('canvas')[0].getContext('2d')
};
var result = CY.clone(mixedBag, {
suppressErrors: true
});
console.log(result); // null
CY.clone()
's functionality with defineCloneProcedure
Because cyclone is built to be environment-agnostic, it is incapable of handling certain cloneable host objects, such as DOM elements, out-of-the-box. However, that doesn't mean that these objects themselves aren't cloneable! For example, most DOM elements can be cloned using cloneNode()
. Cyclone comes with a method called defineCloneProcedure
that allows you to add in your own cloning methods for host objects, or other objects, that can't be handled in a standard way by CY.clone
. Here's how you can add support for cloning DOM nodes using CY.clone
:
var elementTagRE = /^HTML\w*Element$/;
CY.defineCloneProcedure({
detect: function(obj) {
var klass = Object.prototype.toString.call(obj).slice(8, -1);
return elementTagRE.test(klass) && typeof obj.cloneNode === 'function';
},
copy: function(el) {
return el.cloneNode()
}
});
var orig = document.createElement('div');
var clone = CY.clone(orig);
console.log(clone !== orig); // True
Here's another example of how to handle most jQuery objects:
CY.defineCloneProcedure({
detect: function(obj) {
return 'jquery' in obj;
},
copy: function($el) {
return $el.clone();
}
});
CY.clone($('#main')); // Returns a cloned jQuery object.
defineCloneProcedure
takes an object that must contain two properties detect
and copy
.
detect
should be a function that takes an object and returns true
if and only if obj
is of the type that you want to define your custom cloning procedure for. In the above example, detect
ensures that the [[Class]]
of obj
is specified as some kind of HTML Element, and that it has a function called cloneNode
.
copy
should be a function that takes an object and returns a copy of that object. You are responsible for providing the procedure used to copy the object. In the case of an HTML Element, we simply call its cloneNode
method.
defineCloneProcedure
will return true
if the cloning procedure is successfully defined, and false
otherwise. Note that defineCloneProcedure
gives priority to procedures that were defined most recently. That means if you define two cloning procedures whose detect
functions both return true for a given type of object, the latter's copy
function will be used.
You can erase all custom cloning procedures defined by calling CY.clearCustomCloneProcedures()
.
First install the module
$ git clone https://github.com/traviskaufman/cycloneJS.git
$ cd /path/to/cycloneJS
$ npm install .
Then just run npm test
within the module's directory whenever you want to test. This will run jshint on all javascript
files as well as run tests against cyclone.
Issues and Pull Requests are widely encouraged!!
FAQs
A pure-javascript adaptation of the W3C's structured cloning algorithm, designed to provide an easy interface for deep copying of complex objects
The npm package cyclonejs receives a total of 0 weekly downloads. As such, cyclonejs popularity was classified as not popular.
We found that cyclonejs demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.