{"action":"created","comment":{"url":"https://api.github.com/repos/yeoman/stringify-object/pulls/comments/35891177","id":35891177,"diff_hunk":"@@ -2,74 +2,97 @@\n var isRegexp = require('is-regexp');\n var isPlainObj = require('is-plain-obj');\n \n-module.exports = function (val, opts, pad) {\n-\tvar seen = [];\n-\n-\treturn (function stringify(val, opts, pad) {\n-\t\topts = opts || {};\n-\t\topts.indent = opts.indent || '\\t';\n-\t\tpad = pad || '';\n-\n-\t\tif (val === null ||\n-\t\t\tval === undefined ||\n-\t\t\ttypeof val === 'number' ||\n-\t\t\ttypeof val === 'boolean' ||\n-\t\t\ttypeof val === 'function' ||\n-\t\t\tisRegexp(val)) {\n-\t\t\treturn String(val);\n-\t\t}\n-\n-\t\tif (val instanceof Date) {\n-\t\t\treturn 'new Date(\\'' + val.toISOString() + '\\')';\n-\t\t}\n-\n-\t\tif (Array.isArray(val)) {\n-\t\t\tif (val.length === 0) {\n-\t\t\t\treturn '[]';\n-\t\t\t}\n-\n-\t\t\treturn '[\\n' + val.map(function (el, i) {\n-\t\t\t\tvar eol = val.length - 1 === i ? '\\n' : ',\\n';\n-\t\t\t\treturn pad + opts.indent + stringify(el, opts, pad + opts.indent) + eol;\n-\t\t\t}).join('') + pad + ']';\n-\t\t}\n-\n-\t\tif (isPlainObj(val)) {\n-\t\t\tif (seen.indexOf(val) !== -1) {\n-\t\t\t\treturn '\"[Circular]\"';\n-\t\t\t}\n-\n-\t\t\tvar objKeys = Object.keys(val);\n-\n-\t\t\tif (objKeys.length === 0) {\n-\t\t\t\treturn '{}';\n-\t\t\t}\n-\n-\t\t\tseen.push(val);\n-\n-\t\t\tvar ret = '{\\n' + objKeys.map(function (el, i) {\n-\t\t\t\tif (opts.filter && !opts.filter(val, el)) {\n-\t\t\t\t\treturn '';\n-\t\t\t\t}\n-\n-\t\t\t\tvar eol = objKeys.length - 1 === i ? '\\n' : ',\\n';\n-\t\t\t\tvar key = /^[a-z$_][a-z$_0-9]*$/i.test(el) ? el : stringify(el, opts);\n-\t\t\t\treturn pad + opts.indent + key + ': ' + stringify(val[el], opts, pad + opts.indent) + eol;\n-\t\t\t}).join('') + pad + '}';\n-\n-\t\t\tseen.pop(val);\n-\n-\t\t\treturn ret;\n-\t\t}\n-\n-\t\tval = String(val).replace(/[\\r\\n]/g, function (x) {\n-\t\t\treturn x === '\\n' ? '\\\\n' : '\\\\r';\n-\t\t});\n-\n-\t\tif (opts.singleQuotes === false) {\n-\t\t\treturn '\"' + val.replace(/\"/g, '\\\\\\\"') + '\"';\n-\t\t}\n-\n-\t\treturn '\\'' + val.replace(/'/g, '\\\\\\'') + '\\'';\n-\t})(val, opts, pad);\n+var stringify = module.exports = function (val, opts, pad, seen) {\n+    opts = opts || {};\n+    opts.indent = opts.indent || '\\t';\n+    pad = pad || '';\n+    seen = seen || [];\n+\n+    var type = stringify.type(val);\n+    return stringify[type](val, opts, pad, seen);\n+};\n+\n+stringify.types = [\n+    ['null',      function (val) { return val === null; }],\n+    ['undefined', function (val) { return val === undefined; }],\n+    ['boolean',   function (val) { return typeof val === 'boolean'; }],\n+    ['number',    function (val) { return typeof val === 'number'; }],\n+    ['function',  function (val) { return typeof val === 'function'; }],\n+    ['regex',     isRegexp],\n+    ['date',      function (val) { return val instanceof Date; }],\n+    ['array',     function (val) { return Array.isArray(val); }],\n+    ['object',    isPlainObj],\n+    ['string',    function (val) { return typeof val === 'string' || val instanceof String; }]\n+];\n+\n+stringify.type = function (val) {\n+    for (var i = 0; i < stringify.types.length; i++) {","path":"index.js","position":98,"original_position":98,"commit_id":"7f754667067a9b2782d204fb1ce0eb040ddba0d8","original_commit_id":"7f754667067a9b2782d204fb1ce0eb040ddba0d8","user":{"login":"sindresorhus","id":170270,"avatar_url":"https://avatars.githubusercontent.com/u/170270?v=3","gravatar_id":"","url":"https://api.github.com/users/sindresorhus","html_url":"https://github.com/sindresorhus","followers_url":"https://api.github.com/users/sindresorhus/followers","following_url":"https://api.github.com/users/sindresorhus/following{/other_user}","gists_url":"https://api.github.com/users/sindresorhus/gists{/gist_id}","starred_url":"https://api.github.com/users/sindresorhus/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sindresorhus/subscriptions","organizations_url":"https://api.github.com/users/sindresorhus/orgs","repos_url":"https://api.github.com/users/sindresorhus/repos","events_url":"https://api.github.com/users/sindresorhus/events{/privacy}","received_events_url":"https://api.github.com/users/sindresorhus/received_events","type":"User","site_admin":false},"body":"`[].some()`","created_at":"2015-07-30T16:39:23Z","updated_at":"2015-07-30T16:39:23Z","html_url":"https://github.com/yeoman/stringify-object/pull/22#discussion_r35891177","pull_request_url":"https://api.github.com/repos/yeoman/stringify-object/pulls/22","_links":{"self":{"href":"https://api.github.com/repos/yeoman/stringify-object/pulls/comments/35891177"},"html":{"href":"https://github.com/yeoman/stringify-object/pull/22#discussion_r35891177"},"pull_request":{"href":"https://api.github.com/repos/yeoman/stringify-object/pulls/22"}}},"pull_request":{"url":"https://api.github.com/repos/yeoman/stringify-object/pulls/22","id":41143512,"html_url":"https://github.com/yeoman/stringify-object/pull/22","diff_url":"https://github.com/yeoman/stringify-object/pull/22.diff","patch_url":"https://github.com/yeoman/stringify-object/pull/22.patch","issue_url":"https://api.github.com/repos/yeoman/stringify-object/issues/22","number":22,"state":"open","locked":false,"title":"Refactored to be more modular and extendable","user":{"login":"peterjwest","id":246023,"avatar_url":"https://avatars.githubusercontent.com/u/246023?v=3","gravatar_id":"","url":"https://api.github.com/users/peterjwest","html_url":"https://github.com/peterjwest","followers_url":"https://api.github.com/users/peterjwest/followers","following_url":"https://api.github.com/users/peterjwest/following{/other_user}","gists_url":"https://api.github.com/users/peterjwest/gists{/gist_id}","starred_url":"https://api.github.com/users/peterjwest/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/peterjwest/subscriptions","organizations_url":"https://api.github.com/users/peterjwest/orgs","repos_url":"https://api.github.com/users/peterjwest/repos","events_url":"https://api.github.com/users/peterjwest/events{/privacy}","received_events_url":"https://api.github.com/users/peterjwest/received_events","type":"User","site_admin":false},"body":"Refactored the module to expose its internals including type criteria. This will allow users to override parts of the behaviour of the module.\r\n\r\nFor example I would like to override this to support serialising a particular type of object in my application.\r\n\r\nAnother example I can think of is that someone might want to change the way functions are serialised in order to produce valid javascript (i.e. serialise them to `null` or `function() {}`).\r\n\r\nAlso changed the way `seen` objects are handled, using a more flexible recursive method rather than a variable in a closure.","created_at":"2015-07-29T16:26:59Z","updated_at":"2015-07-30T16:39:23Z","closed_at":null,"merged_at":null,"merge_commit_sha":"a478256ae8d81fc2b1050dfb51517eeda3a8ec2f","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/yeoman/stringify-object/pulls/22/commits","review_comments_url":"https://api.github.com/repos/yeoman/stringify-object/pulls/22/comments","review_comment_url":"https://api.github.com/repos/yeoman/stringify-object/pulls/comments{/number}","comments_url":"https://api.github.com/repos/yeoman/stringify-object/issues/22/comments","statuses_url":"https://api.github.com/repos/yeoman/stringify-object/statuses/7f754667067a9b2782d204fb1ce0eb040ddba0d8","head":{"label":"peterjwest:master","ref":"master","sha":"7f754667067a9b2782d204fb1ce0eb040ddba0d8","user":{"login":"peterjwest","id":246023,"avatar_url":"https://avatars.githubusercontent.com/u/246023?v=3","gravatar_id":"","url":"https://api.github.com/users/peterjwest","html_url":"https://github.com/peterjwest","followers_url":"https://api.github.com/users/peterjwest/followers","following_url":"https://api.github.com/users/peterjwest/following{/other_user}","gists_url":"https://api.github.com/users/peterjwest/gists{/gist_id}","starred_url":"https://api.github.com/users/peterjwest/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/peterjwest/subscriptions","organizations_url":"https://api.github.com/users/peterjwest/orgs","repos_url":"https://api.github.com/users/peterjwest/repos","events_url":"https://api.github.com/users/peterjwest/events{/privacy}","received_events_url":"https://api.github.com/users/peterjwest/received_events","type":"User","site_admin":false},"repo":{"id":39901338,"name":"stringify-object","full_name":"peterjwest/stringify-object","owner":{"login":"peterjwest","id":246023,"avatar_url":"https://avatars.githubusercontent.com/u/246023?v=3","gravatar_id":"","url":"https://api.github.com/users/peterjwest","html_url":"https://github.com/peterjwest","followers_url":"https://api.github.com/users/peterjwest/followers","following_url":"https://api.github.com/users/peterjwest/following{/other_user}","gists_url":"https://api.github.com/users/peterjwest/gists{/gist_id}","starred_url":"https://api.github.com/users/peterjwest/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/peterjwest/subscriptions","organizations_url":"https://api.github.com/users/peterjwest/orgs","repos_url":"https://api.github.com/users/peterjwest/repos","events_url":"https://api.github.com/users/peterjwest/events{/privacy}","received_events_url":"https://api.github.com/users/peterjwest/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/peterjwest/stringify-object","description":"Stringify an object/array like JSON.stringify just without all the double-quotes","fork":true,"url":"https://api.github.com/repos/peterjwest/stringify-object","forks_url":"https://api.github.com/repos/peterjwest/stringify-object/forks","keys_url":"https://api.github.com/repos/peterjwest/stringify-object/keys{/key_id}","collaborators_url":"https://api.github.com/repos/peterjwest/stringify-object/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/peterjwest/stringify-object/teams","hooks_url":"https://api.github.com/repos/peterjwest/stringify-object/hooks","issue_events_url":"https://api.github.com/repos/peterjwest/stringify-object/issues/events{/number}","events_url":"https://api.github.com/repos/peterjwest/stringify-object/events","assignees_url":"https://api.github.com/repos/peterjwest/stringify-object/assignees{/user}","branches_url":"https://api.github.com/repos/peterjwest/stringify-object/branches{/branch}","tags_url":"https://api.github.com/repos/peterjwest/stringify-object/tags","blobs_url":"https://api.github.com/repos/peterjwest/stringify-object/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/peterjwest/stringify-object/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/peterjwest/stringify-object/git/refs{/sha}","trees_url":"https://api.github.com/repos/peterjwest/stringify-object/git/trees{/sha}","statuses_url":"https://api.github.com/repos/peterjwest/stringify-object/statuses/{sha}","languages_url":"https://api.github.com/repos/peterjwest/stringify-object/languages","stargazers_url":"https://api.github.com/repos/peterjwest/stringify-object/stargazers","contributors_url":"https://api.github.com/repos/peterjwest/stringify-object/contributors","subscribers_url":"https://api.github.com/repos/peterjwest/stringify-object/subscribers","subscription_url":"https://api.github.com/repos/peterjwest/stringify-object/subscription","commits_url":"https://api.github.com/repos/peterjwest/stringify-object/commits{/sha}","git_commits_url":"https://api.github.com/repos/peterjwest/stringify-object/git/commits{/sha}","comments_url":"https://api.github.com/repos/peterjwest/stringify-object/comments{/number}","issue_comment_url":"https://api.github.com/repos/peterjwest/stringify-object/issues/comments{/number}","contents_url":"https://api.github.com/repos/peterjwest/stringify-object/contents/{+path}","compare_url":"https://api.github.com/repos/peterjwest/stringify-object/compare/{base}...{head}","merges_url":"https://api.github.com/repos/peterjwest/stringify-object/merges","archive_url":"https://api.github.com/repos/peterjwest/stringify-object/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/peterjwest/stringify-object/downloads","issues_url":"https://api.github.com/repos/peterjwest/stringify-object/issues{/number}","pulls_url":"https://api.github.com/repos/peterjwest/stringify-object/pulls{/number}","milestones_url":"https://api.github.com/repos/peterjwest/stringify-object/milestones{/number}","notifications_url":"https://api.github.com/repos/peterjwest/stringify-object/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/peterjwest/stringify-object/labels{/name}","releases_url":"https://api.github.com/repos/peterjwest/stringify-object/releases{/id}","created_at":"2015-07-29T15:33:14Z","updated_at":"2015-07-29T15:33:15Z","pushed_at":"2015-07-29T16:20:56Z","git_url":"git://github.com/peterjwest/stringify-object.git","ssh_url":"git@github.com:peterjwest/stringify-object.git","clone_url":"https://github.com/peterjwest/stringify-object.git","svn_url":"https://github.com/peterjwest/stringify-object","homepage":"","size":337,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"yeoman:master","ref":"master","sha":"85c32ed095a40af16b45acf3bbb12a3915dede6c","user":{"login":"yeoman","id":1714870,"avatar_url":"https://avatars.githubusercontent.com/u/1714870?v=3","gravatar_id":"","url":"https://api.github.com/users/yeoman","html_url":"https://github.com/yeoman","followers_url":"https://api.github.com/users/yeoman/followers","following_url":"https://api.github.com/users/yeoman/following{/other_user}","gists_url":"https://api.github.com/users/yeoman/gists{/gist_id}","starred_url":"https://api.github.com/users/yeoman/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yeoman/subscriptions","organizations_url":"https://api.github.com/users/yeoman/orgs","repos_url":"https://api.github.com/users/yeoman/repos","events_url":"https://api.github.com/users/yeoman/events{/privacy}","received_events_url":"https://api.github.com/users/yeoman/received_events","type":"Organization","site_admin":false},"repo":{"id":7118637,"name":"stringify-object","full_name":"yeoman/stringify-object","owner":{"login":"yeoman","id":1714870,"avatar_url":"https://avatars.githubusercontent.com/u/1714870?v=3","gravatar_id":"","url":"https://api.github.com/users/yeoman","html_url":"https://github.com/yeoman","followers_url":"https://api.github.com/users/yeoman/followers","following_url":"https://api.github.com/users/yeoman/following{/other_user}","gists_url":"https://api.github.com/users/yeoman/gists{/gist_id}","starred_url":"https://api.github.com/users/yeoman/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yeoman/subscriptions","organizations_url":"https://api.github.com/users/yeoman/orgs","repos_url":"https://api.github.com/users/yeoman/repos","events_url":"https://api.github.com/users/yeoman/events{/privacy}","received_events_url":"https://api.github.com/users/yeoman/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/yeoman/stringify-object","description":"Stringify an object/array like JSON.stringify just without all the double-quotes","fork":false,"url":"https://api.github.com/repos/yeoman/stringify-object","forks_url":"https://api.github.com/repos/yeoman/stringify-object/forks","keys_url":"https://api.github.com/repos/yeoman/stringify-object/keys{/key_id}","collaborators_url":"https://api.github.com/repos/yeoman/stringify-object/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/yeoman/stringify-object/teams","hooks_url":"https://api.github.com/repos/yeoman/stringify-object/hooks","issue_events_url":"https://api.github.com/repos/yeoman/stringify-object/issues/events{/number}","events_url":"https://api.github.com/repos/yeoman/stringify-object/events","assignees_url":"https://api.github.com/repos/yeoman/stringify-object/assignees{/user}","branches_url":"https://api.github.com/repos/yeoman/stringify-object/branches{/branch}","tags_url":"https://api.github.com/repos/yeoman/stringify-object/tags","blobs_url":"https://api.github.com/repos/yeoman/stringify-object/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/yeoman/stringify-object/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/yeoman/stringify-object/git/refs{/sha}","trees_url":"https://api.github.com/repos/yeoman/stringify-object/git/trees{/sha}","statuses_url":"https://api.github.com/repos/yeoman/stringify-object/statuses/{sha}","languages_url":"https://api.github.com/repos/yeoman/stringify-object/languages","stargazers_url":"https://api.github.com/repos/yeoman/stringify-object/stargazers","contributors_url":"https://api.github.com/repos/yeoman/stringify-object/contributors","subscribers_url":"https://api.github.com/repos/yeoman/stringify-object/subscribers","subscription_url":"https://api.github.com/repos/yeoman/stringify-object/subscription","commits_url":"https://api.github.com/repos/yeoman/stringify-object/commits{/sha}","git_commits_url":"https://api.github.com/repos/yeoman/stringify-object/git/commits{/sha}","comments_url":"https://api.github.com/repos/yeoman/stringify-object/comments{/number}","issue_comment_url":"https://api.github.com/repos/yeoman/stringify-object/issues/comments{/number}","contents_url":"https://api.github.com/repos/yeoman/stringify-object/contents/{+path}","compare_url":"https://api.github.com/repos/yeoman/stringify-object/compare/{base}...{head}","merges_url":"https://api.github.com/repos/yeoman/stringify-object/merges","archive_url":"https://api.github.com/repos/yeoman/stringify-object/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/yeoman/stringify-object/downloads","issues_url":"https://api.github.com/repos/yeoman/stringify-object/issues{/number}","pulls_url":"https://api.github.com/repos/yeoman/stringify-object/pulls{/number}","milestones_url":"https://api.github.com/repos/yeoman/stringify-object/milestones{/number}","notifications_url":"https://api.github.com/repos/yeoman/stringify-object/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/yeoman/stringify-object/labels{/name}","releases_url":"https://api.github.com/repos/yeoman/stringify-object/releases{/id}","created_at":"2012-12-11T20:16:53Z","updated_at":"2015-07-29T15:06:41Z","pushed_at":"2015-07-29T16:27:00Z","git_url":"git://github.com/yeoman/stringify-object.git","ssh_url":"git@github.com:yeoman/stringify-object.git","clone_url":"https://github.com/yeoman/stringify-object.git","svn_url":"https://github.com/yeoman/stringify-object","homepage":"","size":337,"stargazers_count":86,"watchers_count":86,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":10,"mirror_url":null,"open_issues_count":1,"forks":10,"open_issues":1,"watchers":86,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/yeoman/stringify-object/pulls/22"},"html":{"href":"https://github.com/yeoman/stringify-object/pull/22"},"issue":{"href":"https://api.github.com/repos/yeoman/stringify-object/issues/22"},"comments":{"href":"https://api.github.com/repos/yeoman/stringify-object/issues/22/comments"},"review_comments":{"href":"https://api.github.com/repos/yeoman/stringify-object/pulls/22/comments"},"review_comment":{"href":"https://api.github.com/repos/yeoman/stringify-object/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/yeoman/stringify-object/pulls/22/commits"},"statuses":{"href":"https://api.github.com/repos/yeoman/stringify-object/statuses/7f754667067a9b2782d204fb1ce0eb040ddba0d8"}}}}