Browse files

fix for regex detection on node 0.6

  • Loading branch information...
1 parent 04bb7f2 commit cd7c42121ccaf3749b6bbdb1766ccabdf4e21b79 @substack committed Feb 11, 2012
Showing with 11 additions and 3 deletions.
  1. +10 −2 index.js
  2. +1 −1 package.json
View
12 index.js
@@ -217,8 +217,7 @@ function difflet (opts, prev, next) {
if (typeof node === 'string') {
write('"' + node.toString().replace(/"/g, '\\"') + '"');
}
- else if (node instanceof RegExp
- || (typeof node === 'function' && node.name === undefined)) {
+ else if (isRegExp(node)) {
write(node.toString());
}
else if (typeof node === 'function') {
@@ -238,3 +237,12 @@ function difflet (opts, prev, next) {
return stream;
}
+
+function isRegExp (node) {
+ return node instanceof RegExp || (node
+ && typeof node.test === 'function'
+ && typeof node.exec === 'function'
+ && typeof node.compile === 'function'
+ && node.constructor && node.constructor.name === 'RegExp'
+ );
+}
View
2 package.json
@@ -1,7 +1,7 @@
{
"name" : "difflet",
"description" : "colorful diffs for javascript objects",
- "version" : "0.0.1",
+ "version" : "0.0.2",
"repository" : {
"type" : "git",
"url" : "git://github.com/substack/difflet.git"

0 comments on commit cd7c421

Please sign in to comment.