diff --git a/lazy.js b/lazy.js index 1c39d8f..f44b727 100644 --- a/lazy.js +++ b/lazy.js @@ -1559,8 +1559,8 @@ * * @examples * Lazy([1, 2, 2, 3, 3, 3]).uniq() // sequence: [1, 2, 3] - * Lazy([{ name: 'mike' }, - * { name: 'sarah' }, + * Lazy([{ name: 'mike' }, + * { name: 'sarah' }, * { name: 'mike' } * ]).uniq('name') * // sequence: [{ name: 'mike' }, { name: 'sarah' }] @@ -6104,15 +6104,32 @@ } /** - * "Clones" a regular expression (but makes it always global). + * "Clones" a regular expression, but ensures it is always global. + * Will return the passed RegExp if global is already set. * * @private * @param {RegExp|string} pattern * @returns {RegExp} */ function cloneRegex(pattern) { - return eval("" + pattern + (!pattern.global ? "g" : "")); - }; + var patternStr, lsi, flags, global; + if (pattern instanceof RegExp) { + // Just return the passed in RegExp + if (pattern.global) + return pattern; + patternStr = pattern.toString(); + } + else { + patternStr = pattern; + } + lsi = patternStr.lastIndexOf("/"); + // No widespread RegExp.prototype.flags, unfortuantely; + // We use the string approach for both argument types! + flags = patternStr.substring(lsi + 1); + global = flags.indexOf("g") >= 0 ? "" : "g"; + + return new RegExp(patternStr.substring(1, lsi), flags + global); +} /** * A collection of unique elements. diff --git a/lazy.node.js b/lazy.node.js index 2fb4a9e..1704312 100644 --- a/lazy.node.js +++ b/lazy.node.js @@ -138,7 +138,7 @@ if (typeof Stream.Readable !== "undefined") { this.sequence = sequence; this.started = false; - + // Find delimiter on a (parent) sequence object if set while (sequence) { if (sequence.delimiter) { diff --git a/package.json b/package.json index 9d6da76..a00203e 100644 --- a/package.json +++ b/package.json @@ -42,7 +42,7 @@ "underscore": "1.8.3" }, "scripts": { - "test": "npm run-script 'autodoc' && npm run-script 'jasmine' && npm run-script 'amd' && npm run-script 'promise'", + "test": "npm run-script autodoc && npm run-script jasmine && npm run-script amd && npm run-script promise", "autodoc": "autodoc -t --variable Lazy lazy.js", "jasmine": "jasmine-node spec/node_spec.js", "amd": "node spec/amd_spec.js",