{"action":"created","comment":{"url":"https://api.github.com/repos/kof/node-cjson/pulls/comments/56760719","id":56760719,"diff_hunk":"@@ -99,7 +99,10 @@ exports.parse = function(str, reviver) {\n  */\n exports.replace = function(str, data) {\n     return str.replace(/\\{\\{([^}]+)\\}\\}/g, function(match, search) {\n-        return data[search] ? data[search] : match;\n+        // if the variable is an object, it needs to be stringified first\n+        return data[search] ?\n+            data[search] === Object(data[search]) ? JSON.stringify(data[search]) : data[search]","path":"index.js","position":7,"original_position":7,"commit_id":"41232bd86e1384912fd24248c45920f03503a5f6","original_commit_id":"41232bd86e1384912fd24248c45920f03503a5f6","user":{"login":"kof","id":52824,"avatar_url":"https://avatars.githubusercontent.com/u/52824?v=3","gravatar_id":"","url":"https://api.github.com/users/kof","html_url":"https://github.com/kof","followers_url":"https://api.github.com/users/kof/followers","following_url":"https://api.github.com/users/kof/following{/other_user}","gists_url":"https://api.github.com/users/kof/gists{/gist_id}","starred_url":"https://api.github.com/users/kof/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kof/subscriptions","organizations_url":"https://api.github.com/users/kof/orgs","repos_url":"https://api.github.com/users/kof/repos","events_url":"https://api.github.com/users/kof/events{/privacy}","received_events_url":"https://api.github.com/users/kof/received_events","type":"User","site_admin":false},"body":"why not to use typeof?","created_at":"2016-03-20T08:20:22Z","updated_at":"2016-03-20T08:20:22Z","html_url":"https://github.com/kof/node-cjson/pull/22#discussion_r56760719","pull_request_url":"https://api.github.com/repos/kof/node-cjson/pulls/22","_links":{"self":{"href":"https://api.github.com/repos/kof/node-cjson/pulls/comments/56760719"},"html":{"href":"https://github.com/kof/node-cjson/pull/22#discussion_r56760719"},"pull_request":{"href":"https://api.github.com/repos/kof/node-cjson/pulls/22"}}},"pull_request":{"url":"https://api.github.com/repos/kof/node-cjson/pulls/22","id":63484972,"html_url":"https://github.com/kof/node-cjson/pull/22","diff_url":"https://github.com/kof/node-cjson/pull/22.diff","patch_url":"https://github.com/kof/node-cjson/pull/22.patch","issue_url":"https://api.github.com/repos/kof/node-cjson/issues/22","number":22,"state":"open","locked":false,"title":"Allow cjson.replace variables to be Objects or Arrays","user":{"login":"rafzi","id":7032201,"avatar_url":"https://avatars.githubusercontent.com/u/7032201?v=3","gravatar_id":"","url":"https://api.github.com/users/rafzi","html_url":"https://github.com/rafzi","followers_url":"https://api.github.com/users/rafzi/followers","following_url":"https://api.github.com/users/rafzi/following{/other_user}","gists_url":"https://api.github.com/users/rafzi/gists{/gist_id}","starred_url":"https://api.github.com/users/rafzi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rafzi/subscriptions","organizations_url":"https://api.github.com/users/rafzi/orgs","repos_url":"https://api.github.com/users/rafzi/repos","events_url":"https://api.github.com/users/rafzi/events{/privacy}","received_events_url":"https://api.github.com/users/rafzi/received_events","type":"User","site_admin":false},"body":"This allows for great composability of config files.\r\n\r\n```\r\nbase.cjson:\r\n{\r\n    \"opt\": 3,\r\n    \"ext\": {{ext}}\r\n}\r\n\r\next.cjson:\r\n{\r\n    \"ext\": {\r\n        \"more\": 5\r\n    }\r\n}\r\n```\r\n\r\nPreviously this was only possible by making a variable a single line string, which is not useful for big blocks.\r\n\r\nFirst I went for cjson.extend to manually add sub-objects where they belong, but this quickly got messy and unclear.\r\n\r\nRelated: What do you think about an operation similar to \"merge\" for replace, where you give it a base and ordered replacements? It would replace and extend from last to first file to gather all variables into a final file.","created_at":"2016-03-20T02:33:27Z","updated_at":"2016-03-20T08:20:22Z","closed_at":null,"merged_at":null,"merge_commit_sha":"1153c6718a5d1a627a76b81c50c0c9f93e09041e","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/kof/node-cjson/pulls/22/commits","review_comments_url":"https://api.github.com/repos/kof/node-cjson/pulls/22/comments","review_comment_url":"https://api.github.com/repos/kof/node-cjson/pulls/comments{/number}","comments_url":"https://api.github.com/repos/kof/node-cjson/issues/22/comments","statuses_url":"https://api.github.com/repos/kof/node-cjson/statuses/41232bd86e1384912fd24248c45920f03503a5f6","head":{"label":"rafzi:patch-1","ref":"patch-1","sha":"41232bd86e1384912fd24248c45920f03503a5f6","user":{"login":"rafzi","id":7032201,"avatar_url":"https://avatars.githubusercontent.com/u/7032201?v=3","gravatar_id":"","url":"https://api.github.com/users/rafzi","html_url":"https://github.com/rafzi","followers_url":"https://api.github.com/users/rafzi/followers","following_url":"https://api.github.com/users/rafzi/following{/other_user}","gists_url":"https://api.github.com/users/rafzi/gists{/gist_id}","starred_url":"https://api.github.com/users/rafzi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rafzi/subscriptions","organizations_url":"https://api.github.com/users/rafzi/orgs","repos_url":"https://api.github.com/users/rafzi/repos","events_url":"https://api.github.com/users/rafzi/events{/privacy}","received_events_url":"https://api.github.com/users/rafzi/received_events","type":"User","site_admin":false},"repo":{"id":54295827,"name":"node-cjson","full_name":"rafzi/node-cjson","owner":{"login":"rafzi","id":7032201,"avatar_url":"https://avatars.githubusercontent.com/u/7032201?v=3","gravatar_id":"","url":"https://api.github.com/users/rafzi","html_url":"https://github.com/rafzi","followers_url":"https://api.github.com/users/rafzi/followers","following_url":"https://api.github.com/users/rafzi/following{/other_user}","gists_url":"https://api.github.com/users/rafzi/gists{/gist_id}","starred_url":"https://api.github.com/users/rafzi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rafzi/subscriptions","organizations_url":"https://api.github.com/users/rafzi/orgs","repos_url":"https://api.github.com/users/rafzi/repos","events_url":"https://api.github.com/users/rafzi/events{/privacy}","received_events_url":"https://api.github.com/users/rafzi/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/rafzi/node-cjson","description":"Comments enabled json loader (Commented JavaScript Object Notation)","fork":true,"url":"https://api.github.com/repos/rafzi/node-cjson","forks_url":"https://api.github.com/repos/rafzi/node-cjson/forks","keys_url":"https://api.github.com/repos/rafzi/node-cjson/keys{/key_id}","collaborators_url":"https://api.github.com/repos/rafzi/node-cjson/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/rafzi/node-cjson/teams","hooks_url":"https://api.github.com/repos/rafzi/node-cjson/hooks","issue_events_url":"https://api.github.com/repos/rafzi/node-cjson/issues/events{/number}","events_url":"https://api.github.com/repos/rafzi/node-cjson/events","assignees_url":"https://api.github.com/repos/rafzi/node-cjson/assignees{/user}","branches_url":"https://api.github.com/repos/rafzi/node-cjson/branches{/branch}","tags_url":"https://api.github.com/repos/rafzi/node-cjson/tags","blobs_url":"https://api.github.com/repos/rafzi/node-cjson/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/rafzi/node-cjson/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/rafzi/node-cjson/git/refs{/sha}","trees_url":"https://api.github.com/repos/rafzi/node-cjson/git/trees{/sha}","statuses_url":"https://api.github.com/repos/rafzi/node-cjson/statuses/{sha}","languages_url":"https://api.github.com/repos/rafzi/node-cjson/languages","stargazers_url":"https://api.github.com/repos/rafzi/node-cjson/stargazers","contributors_url":"https://api.github.com/repos/rafzi/node-cjson/contributors","subscribers_url":"https://api.github.com/repos/rafzi/node-cjson/subscribers","subscription_url":"https://api.github.com/repos/rafzi/node-cjson/subscription","commits_url":"https://api.github.com/repos/rafzi/node-cjson/commits{/sha}","git_commits_url":"https://api.github.com/repos/rafzi/node-cjson/git/commits{/sha}","comments_url":"https://api.github.com/repos/rafzi/node-cjson/comments{/number}","issue_comment_url":"https://api.github.com/repos/rafzi/node-cjson/issues/comments{/number}","contents_url":"https://api.github.com/repos/rafzi/node-cjson/contents/{+path}","compare_url":"https://api.github.com/repos/rafzi/node-cjson/compare/{base}...{head}","merges_url":"https://api.github.com/repos/rafzi/node-cjson/merges","archive_url":"https://api.github.com/repos/rafzi/node-cjson/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/rafzi/node-cjson/downloads","issues_url":"https://api.github.com/repos/rafzi/node-cjson/issues{/number}","pulls_url":"https://api.github.com/repos/rafzi/node-cjson/pulls{/number}","milestones_url":"https://api.github.com/repos/rafzi/node-cjson/milestones{/number}","notifications_url":"https://api.github.com/repos/rafzi/node-cjson/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/rafzi/node-cjson/labels{/name}","releases_url":"https://api.github.com/repos/rafzi/node-cjson/releases{/id}","deployments_url":"https://api.github.com/repos/rafzi/node-cjson/deployments","created_at":"2016-03-20T01:57:08Z","updated_at":"2016-03-20T01:57:08Z","pushed_at":"2016-03-20T02:14:32Z","git_url":"git://github.com/rafzi/node-cjson.git","ssh_url":"git@github.com:rafzi/node-cjson.git","clone_url":"https://github.com/rafzi/node-cjson.git","svn_url":"https://github.com/rafzi/node-cjson","homepage":"","size":36,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":false,"has_downloads":true,"has_wiki":true,"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":"kof:master","ref":"master","sha":"e5bd478ce198c46ce698a2af51a79ae437e43f35","user":{"login":"kof","id":52824,"avatar_url":"https://avatars.githubusercontent.com/u/52824?v=3","gravatar_id":"","url":"https://api.github.com/users/kof","html_url":"https://github.com/kof","followers_url":"https://api.github.com/users/kof/followers","following_url":"https://api.github.com/users/kof/following{/other_user}","gists_url":"https://api.github.com/users/kof/gists{/gist_id}","starred_url":"https://api.github.com/users/kof/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kof/subscriptions","organizations_url":"https://api.github.com/users/kof/orgs","repos_url":"https://api.github.com/users/kof/repos","events_url":"https://api.github.com/users/kof/events{/privacy}","received_events_url":"https://api.github.com/users/kof/received_events","type":"User","site_admin":false},"repo":{"id":1509123,"name":"node-cjson","full_name":"kof/node-cjson","owner":{"login":"kof","id":52824,"avatar_url":"https://avatars.githubusercontent.com/u/52824?v=3","gravatar_id":"","url":"https://api.github.com/users/kof","html_url":"https://github.com/kof","followers_url":"https://api.github.com/users/kof/followers","following_url":"https://api.github.com/users/kof/following{/other_user}","gists_url":"https://api.github.com/users/kof/gists{/gist_id}","starred_url":"https://api.github.com/users/kof/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kof/subscriptions","organizations_url":"https://api.github.com/users/kof/orgs","repos_url":"https://api.github.com/users/kof/repos","events_url":"https://api.github.com/users/kof/events{/privacy}","received_events_url":"https://api.github.com/users/kof/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/kof/node-cjson","description":"Comments enabled json loader (Commented JavaScript Object Notation)","fork":false,"url":"https://api.github.com/repos/kof/node-cjson","forks_url":"https://api.github.com/repos/kof/node-cjson/forks","keys_url":"https://api.github.com/repos/kof/node-cjson/keys{/key_id}","collaborators_url":"https://api.github.com/repos/kof/node-cjson/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/kof/node-cjson/teams","hooks_url":"https://api.github.com/repos/kof/node-cjson/hooks","issue_events_url":"https://api.github.com/repos/kof/node-cjson/issues/events{/number}","events_url":"https://api.github.com/repos/kof/node-cjson/events","assignees_url":"https://api.github.com/repos/kof/node-cjson/assignees{/user}","branches_url":"https://api.github.com/repos/kof/node-cjson/branches{/branch}","tags_url":"https://api.github.com/repos/kof/node-cjson/tags","blobs_url":"https://api.github.com/repos/kof/node-cjson/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/kof/node-cjson/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/kof/node-cjson/git/refs{/sha}","trees_url":"https://api.github.com/repos/kof/node-cjson/git/trees{/sha}","statuses_url":"https://api.github.com/repos/kof/node-cjson/statuses/{sha}","languages_url":"https://api.github.com/repos/kof/node-cjson/languages","stargazers_url":"https://api.github.com/repos/kof/node-cjson/stargazers","contributors_url":"https://api.github.com/repos/kof/node-cjson/contributors","subscribers_url":"https://api.github.com/repos/kof/node-cjson/subscribers","subscription_url":"https://api.github.com/repos/kof/node-cjson/subscription","commits_url":"https://api.github.com/repos/kof/node-cjson/commits{/sha}","git_commits_url":"https://api.github.com/repos/kof/node-cjson/git/commits{/sha}","comments_url":"https://api.github.com/repos/kof/node-cjson/comments{/number}","issue_comment_url":"https://api.github.com/repos/kof/node-cjson/issues/comments{/number}","contents_url":"https://api.github.com/repos/kof/node-cjson/contents/{+path}","compare_url":"https://api.github.com/repos/kof/node-cjson/compare/{base}...{head}","merges_url":"https://api.github.com/repos/kof/node-cjson/merges","archive_url":"https://api.github.com/repos/kof/node-cjson/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/kof/node-cjson/downloads","issues_url":"https://api.github.com/repos/kof/node-cjson/issues{/number}","pulls_url":"https://api.github.com/repos/kof/node-cjson/pulls{/number}","milestones_url":"https://api.github.com/repos/kof/node-cjson/milestones{/number}","notifications_url":"https://api.github.com/repos/kof/node-cjson/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/kof/node-cjson/labels{/name}","releases_url":"https://api.github.com/repos/kof/node-cjson/releases{/id}","deployments_url":"https://api.github.com/repos/kof/node-cjson/deployments","created_at":"2011-03-21T23:44:46Z","updated_at":"2015-12-23T06:12:21Z","pushed_at":"2016-03-20T02:33:27Z","git_url":"git://github.com/kof/node-cjson.git","ssh_url":"git@github.com:kof/node-cjson.git","clone_url":"https://github.com/kof/node-cjson.git","svn_url":"https://github.com/kof/node-cjson","homepage":"","size":38,"stargazers_count":48,"watchers_count":48,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":12,"mirror_url":null,"open_issues_count":5,"forks":12,"open_issues":5,"watchers":48,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/kof/node-cjson/pulls/22"},"html":{"href":"https://github.com/kof/node-cjson/pull/22"},"issue":{"href":"https://api.github.com/repos/kof/node-cjson/issues/22"},"comments":{"href":"https://api.github.com/repos/kof/node-cjson/issues/22/comments"},"review_comments":{"href":"https://api.github.com/repos/kof/node-cjson/pulls/22/comments"},"review_comment":{"href":"https://api.github.com/repos/kof/node-cjson/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/kof/node-cjson/pulls/22/commits"},"statuses":{"href":"https://api.github.com/repos/kof/node-cjson/statuses/41232bd86e1384912fd24248c45920f03503a5f6"}}}}