New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

cyclonejs

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cyclonejs - npm Package Compare versions

Comparing version 1.0.1 to 1.1.0

.jshintrc

2

component.json

@@ -5,5 +5,5 @@ {

"description": "A pure-javascript adaptation of the W3C's structured cloning algorithm, designed to provide an easy interface for deep copying of complex objects",
"version": "0.0.2",
"version": "1.1.0",
"scripts": ["cyclone.js"],
"main": "cyclone.js"
}

@@ -54,2 +54,4 @@ /**

// in the map, so it's better to keep the implementation consistent.
// We can ignore coverage of the following ternary statement.
/* istanbul ignore next */
var Map = _isFunc(root.Map) ? root.Map : function Map() {

@@ -71,2 +73,5 @@ Object.defineProperties(this, {

// Ignoring this and the subsequent if statement since we don't need to cover
// shim conditionals.
/* istanbul ignore next */
if (!_isFunc(Map.prototype.set)) {

@@ -76,13 +81,12 @@ // Map a given `input` object to a given `output` object. Relatively

Map.prototype.set = function(input, output) {
var inputIdx = this.inputs.indexOf(input);
if (inputIdx === -1) {
this.inputs.push(input);
this.outputs.push(output);
} else {
// Associate this input with the new output.
this.outputs[inputIdx] = output;
}
// Note that here for our purposes we *never* have to assert that
// we're re-assigning since clones will always map 1:1 and never be
// overridden by another clone in one go. Therefore that conditional logic
// is omitted.
this.inputs.push(input);
this.outputs.push(output);
};
}
/* istanbul ignore next */
if (!_isFunc(Map.prototype.get)) {

@@ -200,3 +204,3 @@ // Retrieve the object that's mapped to `input`, or null if input is not

throw new TypeError(
"Don't know how to clone object of type " + obType
'Don\'t know how to clone object of type ' + obType
);

@@ -245,9 +249,19 @@ }

var desc = Object.getOwnPropertyDescriptor(input, prop);
// We only clone if the property is a non-accessor. We can't really clone
// getters and setters, we can only pass them through.
if (desc.value !== undefined) {
desc.value = _iSClone(desc.value, mMap, options);
var isNonAccessor = _hasOwn(desc, 'value');
var inputVal = isNonAccessor ? desc.value : desc.get();
var outputVal = _iSClone(inputVal, mMap, options);
// If `options.preserveDescriptors` is true, only then do we preserve
// descriptors. Otherwise we simply assign the property. This is in an
// effort to adhere to the spec, since this behaviour errs more towards
// what developers expect.
if (options.preserveDescriptors === true) {
// We only clone if the property is a non-accessor. We can't really
// clone getters and setters, we can only pass them through.
if (desc.value !== undefined) {
desc.value = outputVal;
}
Object.defineProperty(output, prop, desc);
} else {
output[prop] = outputVal;
}
Object.defineProperty(output, prop, desc);
});

@@ -324,8 +338,8 @@ }

// Finally we take care of exporting business.
// Finally we take care of exporting business. We can ignore coverage of this.
/* istanbul ignore next */
if (typeof module === 'object' && typeof module.exports === 'object') {
// Node
module.exports = CY;
} else if (typeof define === "function" && define.amd) {
} else if (typeof define === 'function' && define.amd) {
// AMD/RequireJS

@@ -332,0 +346,0 @@ define([], function() { return CY; });

{
"name": "cyclonejs",
"version": "1.0.1",
"version": "1.1.0",
"description": "A pure-javascript adaptation of the W3C's structured cloning algorithm, designed to provide an easy interface for deep copying of complex objects",

@@ -8,3 +8,4 @@ "main": "cyclone.js",

"pretest": "./node_modules/.bin/jshint *.js test/*.js",
"test": "./node_modules/.bin/mocha --reporter spec test/*.mspec.js"
"test": "./node_modules/.bin/istanbul cover ./node_modules/.bin/_mocha --format html -- --require test/init --reporter spec test/*.mspec.js",
"posttest": "./node_modules/.bin/istanbul check-coverage --statements 100 --branches 100 --functions 100 --lines 100"
},

@@ -27,4 +28,5 @@ "repository": {

"expect.js": "~0.2.0",
"jshint": "~2.1.4",
"docco": "~0.6.2"
"jshint": "~2.5.0",
"docco": "~0.6.2",
"istanbul": "~0.2.7"
},

@@ -31,0 +33,0 @@ "testling": {

@@ -35,3 +35,4 @@ [![Build Status](https://travis-ci.org/traviskaufman/cycloneJS.png)](https://travis-ci.org/traviskaufman/cycloneJS)

* Non-enumerable properties, or properties with custom descriptors
* Accessor properties
(disabled by default: see options)
* Accessor properties (disabled by default: see options)

@@ -93,2 +94,20 @@ ## Usage

* `preserveDescriptors`: (default: `false`) In order to be more predictable out-of-the-box with how the Structured Cloning Algorithm
normally behaves, this module by default does *not* preserve property descriptors/accessor methods when cloning. However, this functionality
can be useful when one is concerned with preserving every single aspect of the original object. If this is the case, set this property to
`true` and CY.clone() will copy the property to the new object with the descriptors intact. _NOTE_: Accessor methods will be simply passed through, *not* truly
copied, so mutating a property on the copied object will cause the same side effects as performing the same operation on the original. If you're concerned about
high-integrity code, this option is for you.
```javascript
var APlus = CY.clone(Array.prototype, {
preserveDescriptors: true,
allowFunctions: true
});
var enum = Object.create(APlus);
enum.push(1, 2, 3, 4, 5);
console.log(Object.keys(enum)); // ['0', '1', '2', '3', '4']
```
### Extending `CY.clone()`'s functionality with `defineCloneProcedure`

@@ -140,12 +159,23 @@

## Contributing/Testing
First install the module
```sh
$ 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.
## MIT License
The MIT License (MIT)
Issues and Pull Requests are widely encouraged!!
Copyright (c) 2014 Travis Kaufman
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

@@ -0,1 +1,3 @@

'use strict';
/**

@@ -5,6 +7,6 @@ * CycloneJS Unit Tests.

var CY = require('../cyclone.js');
var expect = require('expect.js');
var expect = global.expect;
describe('cycloneJS', function() {
var original;
var original, val, clone;

@@ -30,3 +32,3 @@ // http://stackoverflow.com/questions/10776600/

beforeEach(function() {
var val = 0;
val = 0;
/*jshint -W053 */

@@ -41,3 +43,4 @@ original = {

stringObj: new String('hey'),
regex: /^someRE$/g,
regex: /^someRE$/gim,
regexNoFlags: /lookMaNoFlags/,
array: [1, 2, {buckleMy: 'shoe'}],

@@ -69,3 +72,2 @@ object: {

describe('basic cloning functionality', function() {
var clone;
beforeEach(function() {

@@ -109,2 +111,9 @@ clone = CY.clone(original);

it('clones regex objects with no flags', function() {
expect(original.regexNoFlags).not.to.be(clone.regexNoFlags);
expect(
_isRegexEqual(original.regexNoFlags, clone.regexNoFlags)
).to.be(true);
});
it('clones boolean objects', function() {

@@ -156,3 +165,3 @@ expect(_isClonedWrapper(original.boolObj, clone.boolObj)).to.be(true);

it("throws an error if it doesn't know how to clone an object",
it('throws an error if it doesn\'t know how to clone an object',
function() {

@@ -190,6 +199,7 @@ original.f = function() {};

it('preserves descriptor values on copied properties', function() {
it('does *not* preserve descriptor values on copied properties ' +
'(GH#11)', function() {
expect(
Object.getOwnPropertyDescriptor(clone, 'nonEnumerable').enumerable
).to.be(false);
).to.be(true);
});

@@ -200,2 +210,8 @@

});
it('only assigns the value returned from the accessor by default ' +
'(GH#11)', function() {
clone.accessor = 10;
expect(val).to.be(0);
});
});

@@ -262,3 +278,3 @@

detect: function(obj) { return obj === true; },
copy: function(obj) { return 'true'; }
copy: function() { return 'true'; }
})).to.be(true);

@@ -271,6 +287,16 @@ });

it("will fail if an object isn't passed in", function() {
it('will fail if an object isn\'t passed in', function() {
expect(CY.defineCloneProcedure('herp')).to.be(false);
});
it('will only copy the procedure if detect() returns true', function() {
var copy;
CY.defineCloneProcedure({
detect: function(obj) { return obj === true; },
copy: function() { return 'not this'; }
});
copy = CY.clone({ foo: true });
expect(copy.foo).to.be(true);
});
it('will fail if the object lacks a `detect` function', function() {

@@ -308,2 +334,18 @@ expect(CY.defineCloneProcedure({

describe('options for CY.clone', function() {
it ('has a `preserveDescriptors` option that will copy property ' +
'descriptors when set to true', function() {
clone = CY.clone(original, { preserveDescriptors: true });
expect(
Object.getOwnPropertyDescriptor(clone, 'nonEnumerable').enumerable
).to.be(false);
});
it ('passes get/set accessor methods through when `preserveDescriptors` ' +
'is set to true', function() {
clone = CY.clone(original, { preserveDescriptors: true });
clone.accessor = 10;
expect(val).to.be(10);
});
it('has an `allowFunctions` option that will pass functions ' +

@@ -329,3 +371,4 @@ 'through', function() {

it('returns null if `suppressErrors` is true and an error is thrown', function() {
it('returns null if `suppressErrors` is true and an error ' +
'is thrown', function() {
original.f = function() {};

@@ -332,0 +375,0 @@ expect(CY.clone(original, {suppressErrors: true})).to.be(null);

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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