Comparing version 1.1.1 to 1.1.2
{ | ||
"name": "cyclonejs", | ||
"version": "1.1.1", | ||
"version": "1.1.2", | ||
"description": "A pure-js adaptation of the W3C structured cloning algorithm, designed to provide an easy interface for deep copying of complex objects", | ||
@@ -5,0 +5,0 @@ "main": "cyclone.js", |
@@ -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": "1.1.1", | ||
"version": "1.1.2", | ||
"scripts": ["cyclone.js"], | ||
"main": "cyclone.js" | ||
} |
@@ -183,2 +183,6 @@ /** | ||
case '[object ArrayBuffer]': | ||
output = _handleArrayBufferClone(input); | ||
break; | ||
case '[object Array]': | ||
@@ -203,2 +207,5 @@ output = new Array(input.length); | ||
output = input; | ||
} else if (_isTypedArray(input)) { | ||
// If it is a typed array, clone it according to the W3C spec | ||
output = _handleTypedArrayClone(input); | ||
} else { | ||
@@ -270,2 +277,28 @@ throw new TypeError( | ||
// Handles the cloning of ArrayBuffer objects, as specified in the W3C | ||
// spec. | ||
function _handleArrayBufferClone(buf) { | ||
var dst = new ArrayBuffer(buf.byteLength); | ||
for (var i = 0, l = buf.byteLength; i < l; i++) { | ||
dst[i] = buf[i]; | ||
} | ||
return dst; | ||
} | ||
function _isTypedArray(obj) { | ||
var Ctor = Object.getPrototypeOf(obj).constructor; | ||
return /^(?:.+)Array$/.test(Ctor.name); | ||
} | ||
// Handles the cloning of TypedArray objects, as specified in the W3C | ||
// spec. | ||
function _handleTypedArrayClone(typedArray) { | ||
var TypedArray = Object.getPrototypeOf(typedArray).constructor; | ||
return new TypedArray( | ||
_handleArrayBufferClone(typedArray.buffer), | ||
typedArray.byteOffset, | ||
typedArray.length | ||
); | ||
} | ||
function _attemptCustomClone(obj) { | ||
@@ -272,0 +305,0 @@ var proc; |
{ | ||
"name": "cyclonejs", | ||
"version": "1.1.1", | ||
"version": "1.1.2", | ||
"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,3 @@ "main": "cyclone.js", | ||
"pretest": "./node_modules/.bin/jshint *.js test/*.js", | ||
"test": "./node_modules/.bin/istanbul cover ./node_modules/.bin/_mocha --format html -- --require test/init --reporter spec test/*.mspec.js", | ||
"test": "./node_modules/.bin/istanbul cover ./node_modules/.bin/_mocha --format html -- --require test/init --reporter spec test/*.js", | ||
"posttest": "./node_modules/.bin/istanbul check-coverage --statements 100 --branches 100 --functions 100 --lines 100" | ||
@@ -34,3 +34,3 @@ }, | ||
"harness": "mocha", | ||
"files": "test/cyclone.mspec.js", | ||
"files": "test/cyclone.spec.js", | ||
"browsers": { | ||
@@ -37,0 +37,0 @@ "ie": [ |
@@ -14,3 +14,3 @@ [![Build Status](https://travis-ci.org/traviskaufman/cycloneJS.png)](https://travis-ci.org/traviskaufman/cycloneJS) | ||
* Serve the <strong>majority of use cases out of the box</strong>, but also | ||
provide a mechanism to be extensible (coming soon). | ||
provide a mechanism to be extensible. | ||
* Able to copy functions (including function objects) by reference. | ||
@@ -31,2 +31,3 @@ <strong>This is the only property that's copied by reference.</strong> | ||
* Array objects | ||
* TypedArray and ArrayBuffer object | ||
* Object (or "plain") objects | ||
@@ -33,0 +34,0 @@ * In most cases, Objects instantiated with the use of a custom constructor (e.g. `function Foo() { this.bar = 'baz' }; var cloneable = new Foo();`) |
436650
25
1466
180