{"action":"created","comment":{"url":"https://api.github.com/repos/sindresorhus/os-locale/pulls/comments/86692276","pull_request_review_id":7337724,"id":86692276,"diff_hunk":"@@ -28,101 +24,90 @@ function parseLocale(x) {\n }\n \n function getLocale(str) {\n-\treturn (str && str.replace(/[.:].*/, '')) || fallback();\n+\treturn (str && str.replace(/[\"]?(.*)[.:].*/, '$1')) || fallback();\n }\n \n-module.exports = function (opts, cb) {\n-\tif (typeof opts === 'function') {\n-\t\tcb = opts;\n-\t\topts = defaultOpts;\n-\t} else {\n-\t\topts = opts || defaultOpts;\n-\t}\n+module.exports = mem(opts => {\n+\topts = opts || defaultOpts;\n \n-\tif (cache || getEnvLocale() || opts.spawn === false) {\n-\t\tsetImmediate(cb, null, cache);\n-\t\treturn;\n-\t}\n+\tconst envLocale = getEnvLocale();\n+\tlet locale;\n \n-\tvar getAppleLocale = function () {\n-\t\tchildProcess.execFile('defaults', ['read', '-g', 'AppleLocale'], function (err, stdout) {\n-\t\t\tif (err) {\n-\t\t\t\tfallback();\n-\t\t\t\treturn;\n-\t\t\t}\n+\tif (envLocale || opts.spawn === false) {\n+\t\tlocale = getLocale(envLocale);\n+\t\treturn Promise.resolve(locale);\n+\t}\n \n-\t\t\tcache = stdout.trim() || fallback();\n-\t\t\tcb(null, cache);\n-\t\t});\n-\t};\n+\tconst getAppleLocale = () => execa.stdout('defaults', ['read', '-g', 'AppleLocale'])\n+\t\t\t.then(stdout => {\n+\t\t\t\tlocale = stdout.trim() || fallback();\n+\t\t\t\treturn locale;\n+\t\t\t})\n+\t\t\t.catch(() => fallback());\n \n \tif (process.platform === 'win32') {\n-\t\tchildProcess.execFile('wmic', ['os', 'get', 'locale'], function (err, stdout) {\n-\t\t\tif (err) {\n-\t\t\t\tfallback();\n-\t\t\t\treturn;\n-\t\t\t}\n-\n-\t\t\tvar lcidCode = parseInt(stdout.replace('Locale', ''), 16);\n-\t\t\tcache = lcid.from(lcidCode) || fallback();\n-\t\t\tcb(null, cache);\n-\t\t});\n-\t} else {\n-\t\tchildProcess.execFile('locale', function (err, stdout) {\n-\t\t\tif (err) {\n-\t\t\t\tfallback();\n-\t\t\t\treturn;\n-\t\t\t}\n-\n-\t\t\tvar res = parseLocale(stdout);\n+\t\treturn execa.stdout('wmic', ['os', 'get', 'locale'])\n+\t\t\t.then(stdout => {\n+\t\t\t\tconst lcidCode = parseInt(stdout.replace('Locale', ''), 16);\n+\t\t\t\tlocale = lcid.from(lcidCode) || fallback();\n+\t\t\t\treturn locale;\n+\t\t\t})\n+\t\t\t.catch(() => fallback());\n+\t}\n \n+\treturn execa.stdout('locale')\n+\t\t.then(stdout => {\n+\t\t\tconst res = parseLocale(stdout);\n \t\t\tif (!res && process.platform === 'darwin') {\n-\t\t\t\tgetAppleLocale();\n-\t\t\t\treturn;\n+\t\t\t\treturn getAppleLocale();\n \t\t\t}\n \n-\t\t\tcache = getLocale(res);\n-\t\t\tcb(null, cache);\n-\t\t});\n-\t}\n-};\n+\t\t\tlocale = getLocale(res);\n+\t\t\treturn locale;\n+\t\t})\n+\t\t.catch(() => fallback());\n+});\n \n-module.exports.sync = function (opts) {\n+module.exports.sync = mem(opts => {\n \topts = opts || defaultOpts;\n \n-\tif (cache || getEnvLocale() || !execFileSync || opts.spawn === false) {\n-\t\treturn cache;\n+\tconst envLocale = getEnvLocale();\n+\tlet locale;\n+\n+\tif (envLocale || !execa.sync || opts.spawn === false) {","path":"index.js","position":137,"original_position":137,"commit_id":"0c35321fb8bf1ec3d4e1b0912449cc340064e68a","original_commit_id":"0c35321fb8bf1ec3d4e1b0912449cc340064e68a","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":"`!execa.sync` is not needed as `execa.sync` always exists.","created_at":"2016-11-06T18:16:21Z","updated_at":"2016-11-06T18:25:29Z","html_url":"https://github.com/sindresorhus/os-locale/pull/21#discussion_r86692276","pull_request_url":"https://api.github.com/repos/sindresorhus/os-locale/pulls/21","_links":{"self":{"href":"https://api.github.com/repos/sindresorhus/os-locale/pulls/comments/86692276"},"html":{"href":"https://github.com/sindresorhus/os-locale/pull/21#discussion_r86692276"},"pull_request":{"href":"https://api.github.com/repos/sindresorhus/os-locale/pulls/21"}}},"pull_request":{"url":"https://api.github.com/repos/sindresorhus/os-locale/pulls/21","id":92264057,"html_url":"https://github.com/sindresorhus/os-locale/pull/21","diff_url":"https://github.com/sindresorhus/os-locale/pull/21.diff","patch_url":"https://github.com/sindresorhus/os-locale/pull/21.patch","issue_url":"https://api.github.com/repos/sindresorhus/os-locale/issues/21","number":21,"state":"open","locked":false,"title":"Implement Promise interface","user":{"login":"opedromiranda","id":3029838,"avatar_url":"https://avatars.githubusercontent.com/u/3029838?v=3","gravatar_id":"","url":"https://api.github.com/users/opedromiranda","html_url":"https://github.com/opedromiranda","followers_url":"https://api.github.com/users/opedromiranda/followers","following_url":"https://api.github.com/users/opedromiranda/following{/other_user}","gists_url":"https://api.github.com/users/opedromiranda/gists{/gist_id}","starred_url":"https://api.github.com/users/opedromiranda/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/opedromiranda/subscriptions","organizations_url":"https://api.github.com/users/opedromiranda/orgs","repos_url":"https://api.github.com/users/opedromiranda/repos","events_url":"https://api.github.com/users/opedromiranda/events{/privacy}","received_events_url":"https://api.github.com/users/opedromiranda/received_events","type":"User","site_admin":false},"body":"As mentioned in #20 .\r\n\r\n```cache``` global removed. Using [```mem```](https://github.com/sindresorhus/mem) to cache return values.\r\n\r\n[```execa```](https://github.com/sindresorhus/execa) being used instead of ```child_process ```.\r\n\r\n\r\n#### getLocale regex\r\n\r\nThe regex was updated.\r\n\r\nThe system's ```locale``` command returns a set of lines like:\r\n```\r\n...\r\nLC_COLLATE=\"en_GB.UTF-8\"\r\nLC_CTYPE=\"en_GB.UTF-8\"\r\nLC_MESSAGES=\"en_GB.UTF-8\"\r\n...\r\n```\r\n\r\nEach line is split by the ```=``` sign.\r\n\r\nGiven the string ```\"en_GB.UTF-8\"```,  replace would return ```\"en_GB```.\r\n\r\n\r\n```javascript\r\nstr = \"\\\"en_GB.UTF-8\\\"\";\r\n\r\nstr.replace(/[.:].*/, ''); // returns \"en_GB\r\nstr.replace(/[\"]?(.*)[.:].*/, '$1'); // returns en_GB\r\n```","created_at":"2016-11-04T00:11:36Z","updated_at":"2016-11-06T18:25:29Z","closed_at":null,"merged_at":null,"merge_commit_sha":"d87b5a30659aec91c9eef17c7489b0f1ac8aceb0","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/sindresorhus/os-locale/pulls/21/commits","review_comments_url":"https://api.github.com/repos/sindresorhus/os-locale/pulls/21/comments","review_comment_url":"https://api.github.com/repos/sindresorhus/os-locale/pulls/comments{/number}","comments_url":"https://api.github.com/repos/sindresorhus/os-locale/issues/21/comments","statuses_url":"https://api.github.com/repos/sindresorhus/os-locale/statuses/0c35321fb8bf1ec3d4e1b0912449cc340064e68a","head":{"label":"opedromiranda:promise-interface","ref":"promise-interface","sha":"0c35321fb8bf1ec3d4e1b0912449cc340064e68a","user":{"login":"opedromiranda","id":3029838,"avatar_url":"https://avatars.githubusercontent.com/u/3029838?v=3","gravatar_id":"","url":"https://api.github.com/users/opedromiranda","html_url":"https://github.com/opedromiranda","followers_url":"https://api.github.com/users/opedromiranda/followers","following_url":"https://api.github.com/users/opedromiranda/following{/other_user}","gists_url":"https://api.github.com/users/opedromiranda/gists{/gist_id}","starred_url":"https://api.github.com/users/opedromiranda/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/opedromiranda/subscriptions","organizations_url":"https://api.github.com/users/opedromiranda/orgs","repos_url":"https://api.github.com/users/opedromiranda/repos","events_url":"https://api.github.com/users/opedromiranda/events{/privacy}","received_events_url":"https://api.github.com/users/opedromiranda/received_events","type":"User","site_admin":false},"repo":{"id":72795043,"name":"os-locale","full_name":"opedromiranda/os-locale","owner":{"login":"opedromiranda","id":3029838,"avatar_url":"https://avatars.githubusercontent.com/u/3029838?v=3","gravatar_id":"","url":"https://api.github.com/users/opedromiranda","html_url":"https://github.com/opedromiranda","followers_url":"https://api.github.com/users/opedromiranda/followers","following_url":"https://api.github.com/users/opedromiranda/following{/other_user}","gists_url":"https://api.github.com/users/opedromiranda/gists{/gist_id}","starred_url":"https://api.github.com/users/opedromiranda/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/opedromiranda/subscriptions","organizations_url":"https://api.github.com/users/opedromiranda/orgs","repos_url":"https://api.github.com/users/opedromiranda/repos","events_url":"https://api.github.com/users/opedromiranda/events{/privacy}","received_events_url":"https://api.github.com/users/opedromiranda/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/opedromiranda/os-locale","description":"Get the system locale","fork":true,"url":"https://api.github.com/repos/opedromiranda/os-locale","forks_url":"https://api.github.com/repos/opedromiranda/os-locale/forks","keys_url":"https://api.github.com/repos/opedromiranda/os-locale/keys{/key_id}","collaborators_url":"https://api.github.com/repos/opedromiranda/os-locale/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/opedromiranda/os-locale/teams","hooks_url":"https://api.github.com/repos/opedromiranda/os-locale/hooks","issue_events_url":"https://api.github.com/repos/opedromiranda/os-locale/issues/events{/number}","events_url":"https://api.github.com/repos/opedromiranda/os-locale/events","assignees_url":"https://api.github.com/repos/opedromiranda/os-locale/assignees{/user}","branches_url":"https://api.github.com/repos/opedromiranda/os-locale/branches{/branch}","tags_url":"https://api.github.com/repos/opedromiranda/os-locale/tags","blobs_url":"https://api.github.com/repos/opedromiranda/os-locale/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/opedromiranda/os-locale/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/opedromiranda/os-locale/git/refs{/sha}","trees_url":"https://api.github.com/repos/opedromiranda/os-locale/git/trees{/sha}","statuses_url":"https://api.github.com/repos/opedromiranda/os-locale/statuses/{sha}","languages_url":"https://api.github.com/repos/opedromiranda/os-locale/languages","stargazers_url":"https://api.github.com/repos/opedromiranda/os-locale/stargazers","contributors_url":"https://api.github.com/repos/opedromiranda/os-locale/contributors","subscribers_url":"https://api.github.com/repos/opedromiranda/os-locale/subscribers","subscription_url":"https://api.github.com/repos/opedromiranda/os-locale/subscription","commits_url":"https://api.github.com/repos/opedromiranda/os-locale/commits{/sha}","git_commits_url":"https://api.github.com/repos/opedromiranda/os-locale/git/commits{/sha}","comments_url":"https://api.github.com/repos/opedromiranda/os-locale/comments{/number}","issue_comment_url":"https://api.github.com/repos/opedromiranda/os-locale/issues/comments{/number}","contents_url":"https://api.github.com/repos/opedromiranda/os-locale/contents/{+path}","compare_url":"https://api.github.com/repos/opedromiranda/os-locale/compare/{base}...{head}","merges_url":"https://api.github.com/repos/opedromiranda/os-locale/merges","archive_url":"https://api.github.com/repos/opedromiranda/os-locale/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/opedromiranda/os-locale/downloads","issues_url":"https://api.github.com/repos/opedromiranda/os-locale/issues{/number}","pulls_url":"https://api.github.com/repos/opedromiranda/os-locale/pulls{/number}","milestones_url":"https://api.github.com/repos/opedromiranda/os-locale/milestones{/number}","notifications_url":"https://api.github.com/repos/opedromiranda/os-locale/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/opedromiranda/os-locale/labels{/name}","releases_url":"https://api.github.com/repos/opedromiranda/os-locale/releases{/id}","deployments_url":"https://api.github.com/repos/opedromiranda/os-locale/deployments","created_at":"2016-11-03T23:12:08Z","updated_at":"2016-11-03T23:12:08Z","pushed_at":"2016-11-03T23:51:16Z","git_url":"git://github.com/opedromiranda/os-locale.git","ssh_url":"git@github.com:opedromiranda/os-locale.git","clone_url":"https://github.com/opedromiranda/os-locale.git","svn_url":"https://github.com/opedromiranda/os-locale","homepage":null,"size":19,"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":"sindresorhus:master","ref":"master","sha":"6958baf114596d1b14210fbbda151e17550f3014","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},"repo":{"id":32307472,"name":"os-locale","full_name":"sindresorhus/os-locale","owner":{"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},"private":false,"html_url":"https://github.com/sindresorhus/os-locale","description":"Get the system locale","fork":false,"url":"https://api.github.com/repos/sindresorhus/os-locale","forks_url":"https://api.github.com/repos/sindresorhus/os-locale/forks","keys_url":"https://api.github.com/repos/sindresorhus/os-locale/keys{/key_id}","collaborators_url":"https://api.github.com/repos/sindresorhus/os-locale/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/sindresorhus/os-locale/teams","hooks_url":"https://api.github.com/repos/sindresorhus/os-locale/hooks","issue_events_url":"https://api.github.com/repos/sindresorhus/os-locale/issues/events{/number}","events_url":"https://api.github.com/repos/sindresorhus/os-locale/events","assignees_url":"https://api.github.com/repos/sindresorhus/os-locale/assignees{/user}","branches_url":"https://api.github.com/repos/sindresorhus/os-locale/branches{/branch}","tags_url":"https://api.github.com/repos/sindresorhus/os-locale/tags","blobs_url":"https://api.github.com/repos/sindresorhus/os-locale/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/sindresorhus/os-locale/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/sindresorhus/os-locale/git/refs{/sha}","trees_url":"https://api.github.com/repos/sindresorhus/os-locale/git/trees{/sha}","statuses_url":"https://api.github.com/repos/sindresorhus/os-locale/statuses/{sha}","languages_url":"https://api.github.com/repos/sindresorhus/os-locale/languages","stargazers_url":"https://api.github.com/repos/sindresorhus/os-locale/stargazers","contributors_url":"https://api.github.com/repos/sindresorhus/os-locale/contributors","subscribers_url":"https://api.github.com/repos/sindresorhus/os-locale/subscribers","subscription_url":"https://api.github.com/repos/sindresorhus/os-locale/subscription","commits_url":"https://api.github.com/repos/sindresorhus/os-locale/commits{/sha}","git_commits_url":"https://api.github.com/repos/sindresorhus/os-locale/git/commits{/sha}","comments_url":"https://api.github.com/repos/sindresorhus/os-locale/comments{/number}","issue_comment_url":"https://api.github.com/repos/sindresorhus/os-locale/issues/comments{/number}","contents_url":"https://api.github.com/repos/sindresorhus/os-locale/contents/{+path}","compare_url":"https://api.github.com/repos/sindresorhus/os-locale/compare/{base}...{head}","merges_url":"https://api.github.com/repos/sindresorhus/os-locale/merges","archive_url":"https://api.github.com/repos/sindresorhus/os-locale/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/sindresorhus/os-locale/downloads","issues_url":"https://api.github.com/repos/sindresorhus/os-locale/issues{/number}","pulls_url":"https://api.github.com/repos/sindresorhus/os-locale/pulls{/number}","milestones_url":"https://api.github.com/repos/sindresorhus/os-locale/milestones{/number}","notifications_url":"https://api.github.com/repos/sindresorhus/os-locale/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/sindresorhus/os-locale/labels{/name}","releases_url":"https://api.github.com/repos/sindresorhus/os-locale/releases{/id}","deployments_url":"https://api.github.com/repos/sindresorhus/os-locale/deployments","created_at":"2015-03-16T07:09:09Z","updated_at":"2016-11-04T10:51:19Z","pushed_at":"2016-11-04T00:11:36Z","git_url":"git://github.com/sindresorhus/os-locale.git","ssh_url":"git@github.com:sindresorhus/os-locale.git","clone_url":"https://github.com/sindresorhus/os-locale.git","svn_url":"https://github.com/sindresorhus/os-locale","homepage":null,"size":25,"stargazers_count":68,"watchers_count":68,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":13,"mirror_url":null,"open_issues_count":3,"forks":13,"open_issues":3,"watchers":68,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/sindresorhus/os-locale/pulls/21"},"html":{"href":"https://github.com/sindresorhus/os-locale/pull/21"},"issue":{"href":"https://api.github.com/repos/sindresorhus/os-locale/issues/21"},"comments":{"href":"https://api.github.com/repos/sindresorhus/os-locale/issues/21/comments"},"review_comments":{"href":"https://api.github.com/repos/sindresorhus/os-locale/pulls/21/comments"},"review_comment":{"href":"https://api.github.com/repos/sindresorhus/os-locale/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/sindresorhus/os-locale/pulls/21/commits"},"statuses":{"href":"https://api.github.com/repos/sindresorhus/os-locale/statuses/0c35321fb8bf1ec3d4e1b0912449cc340064e68a"}}}}
{"actor":{"display_login":"sindresorhus"}}