Skip to content

Commit

Permalink
Minor code style tweaks and update dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed Dec 26, 2018
1 parent c1dfe21 commit 6d95fac
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 57 deletions.
25 changes: 11 additions & 14 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@ const mem = require('mem');
const defaultOptions = {spawn: true};
const defaultLocale = 'en_US';

function getEnvLocale(env) {
env = env || process.env;
function getEnvLocale(env = process.env) {
return env.LC_ALL || env.LC_MESSAGES || env.LANG || env.LANGUAGE;
}

function parseLocale(x) {
const env = x.split('\n').reduce((env, def) => {
def = def.split('=');
env[def[0]] = def[1].replace(/^"|"$/g, '');
function parseLocale(string) {
const env = string.split('\n').reduce((env, def) => {
const [key, value] = def.split('=');
env[key] = value.replace(/^"|"$/g, '');
return env;
}, {});

return getEnvLocale(env);
}

Expand All @@ -25,11 +25,11 @@ function getLocale(string) {
}

function getAppleLocale() {
return execa.stdout('defaults', ['read', '-g', 'AppleLocale']);
return execa.stdout('defaults', ['read', '-globalDomain', 'AppleLocale']);
}

function getAppleLocaleSync() {
return execa.sync('defaults', ['read', '-g', 'AppleLocale']).stdout;
return execa.sync('defaults', ['read', '-globalDomain', 'AppleLocale']).stdout;
}

function getUnixLocale() {
Expand Down Expand Up @@ -75,7 +75,8 @@ module.exports = mem((options = defaultOptions) => {
thenable = getUnixLocale();
}

return thenable.then(locale => locale || defaultLocale)
return thenable
.then(locale => locale || defaultLocale)
.catch(() => defaultLocale);
});

Expand All @@ -87,11 +88,7 @@ module.exports.sync = mem((options = defaultOptions) => {
res = getLocale(envLocale);
} else {
try {
if (process.platform === 'win32') {
res = getWinLocaleSync();
} else {
res = getUnixLocaleSync();
}
res = process.platform === 'win32' ? getWinLocaleSync() : getUnixLocaleSync();
} catch (_) {}
}

Expand Down
86 changes: 43 additions & 43 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,45 +1,45 @@
{
"name": "os-locale",
"version": "3.0.1",
"description": "Get the system locale",
"license": "MIT",
"repository": "sindresorhus/os-locale",
"author": {
"name": "Sindre Sorhus",
"email": "sindresorhus@gmail.com",
"url": "sindresorhus.com"
},
"engines": {
"node": ">=6"
},
"scripts": {
"test": "xo && ava"
},
"files": [
"index.js"
],
"keywords": [
"locale",
"lang",
"language",
"system",
"os",
"string",
"str",
"user",
"country",
"id",
"identifier",
"region"
],
"dependencies": {
"execa": "^0.10.0",
"lcid": "^2.0.0",
"mem": "^4.0.0"
},
"devDependencies": {
"ava": "*",
"import-fresh": "^2.0.0",
"xo": "*"
}
"name": "os-locale",
"version": "3.0.1",
"description": "Get the system locale",
"license": "MIT",
"repository": "sindresorhus/os-locale",
"author": {
"name": "Sindre Sorhus",
"email": "sindresorhus@gmail.com",
"url": "sindresorhus.com"
},
"engines": {
"node": ">=6"
},
"scripts": {
"test": "xo && ava"
},
"files": [
"index.js"
],
"keywords": [
"locale",
"lang",
"language",
"system",
"os",
"string",
"str",
"user",
"country",
"id",
"identifier",
"region"
],
"dependencies": {
"execa": "^1.0.0",
"lcid": "^2.0.0",
"mem": "^4.0.0"
},
"devDependencies": {
"ava": "^1.0.1",
"import-fresh": "^3.0.0",
"xo": "^0.23.0"
}
}

0 comments on commit 6d95fac

Please sign in to comment.