clone
Advanced tools
Comparing version 0.1.9 to 0.1.10
21
clone.js
@@ -15,2 +15,9 @@ "use strict"; | ||
return typeof re === 'object' && objectToString(re) === '[object RegExp]'; | ||
}, | ||
getRegExpFlags: function (re) { | ||
var flags = ''; | ||
re.global && (flags += 'g'); | ||
re.ignoreCase && (flags += 'i'); | ||
re.multiline && (flags += 'm'); | ||
return flags; | ||
} | ||
@@ -70,5 +77,6 @@ }; | ||
child = new Date(parent.getTime()); | ||
else if (util.isRegExp(parent)) | ||
child = new RegExp(parent.source); | ||
else if (useBuffer && Buffer.isBuffer(parent)) | ||
else if (util.isRegExp(parent)) { | ||
child = new RegExp(parent.source, util.getRegExpFlags(parent)); | ||
if (parent.lastIndex) child.lastIndex = parent.lastIndex; | ||
} else if (useBuffer && Buffer.isBuffer(parent)) | ||
{ | ||
@@ -121,5 +129,6 @@ child = new Buffer(parent.length); | ||
child = new Date(parent.getTime() ); | ||
else if (util.isRegExp(parent)) | ||
child = new RegExp(parent.source); | ||
else { | ||
else if (util.isRegExp(parent)) { | ||
child = new RegExp(parent.source, util.getRegExpFlags(parent)); | ||
if (parent.lastIndex) child.lastIndex = parent.lastIndex; | ||
} else { | ||
child = {}; | ||
@@ -126,0 +135,0 @@ child.__proto__ = parent.__proto__; |
@@ -11,3 +11,3 @@ { | ||
], | ||
"version": "0.1.9", | ||
"version": "0.1.10", | ||
"repository": { | ||
@@ -31,3 +31,4 @@ "type": "git", | ||
"Hugh Kennedy (http://twitter.com/hughskennedy)", | ||
"Dustin Diaz (http://dustindiaz.com)" | ||
"Dustin Diaz (http://dustindiaz.com)", | ||
"Ilya Shaisultanov (https://github.com/diversario)" | ||
], | ||
@@ -34,0 +35,0 @@ "engines": { |
24
test.js
@@ -99,2 +99,26 @@ if(module.parent === null) { | ||
exports["clone regexp"] = function(test) { | ||
test.expect(5); | ||
var a = /abc123/gi; | ||
var b = clone(a); | ||
test.deepEqual(b, a); | ||
var c = /a/g; | ||
test.ok(c.lastIndex === 0); | ||
c.exec('123a456a'); | ||
test.ok(c.lastIndex === 4); | ||
var d = clone(c); | ||
test.ok(d.global); | ||
test.ok(d.lastIndex === 4); | ||
test.done(); | ||
}; | ||
exports["clone object containing array"] = function(test) { | ||
@@ -101,0 +125,0 @@ test.expect(2); // how many tests? |
14613
300