Comparing version 3.0.1 to 3.1.0
43
index.js
@@ -9,13 +9,13 @@ 'use strict'; | ||
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); | ||
@@ -28,8 +28,26 @@ } | ||
function getLocales() { | ||
return execa.stdout('locale', ['-a']); | ||
} | ||
function getLocalesSync() { | ||
return execa.sync('locale', ['-a']).stdout; | ||
} | ||
function getSupportedLocale(locale, locales = '') { | ||
return locales.includes(locale) ? locale : defaultLocale; | ||
} | ||
function getAppleLocale() { | ||
return execa.stdout('defaults', ['read', '-g', 'AppleLocale']); | ||
return Promise.all([ | ||
execa.stdout('defaults', ['read', '-globalDomain', 'AppleLocale']), | ||
getLocales() | ||
]).then(results => getSupportedLocale(results[0], results[1])); | ||
} | ||
function getAppleLocaleSync() { | ||
return execa.sync('defaults', ['read', '-g', 'AppleLocale']).stdout; | ||
return getSupportedLocale( | ||
execa.sync('defaults', ['read', '-globalDomain', 'AppleLocale']).stdout, | ||
getLocalesSync() | ||
); | ||
} | ||
@@ -80,3 +98,4 @@ | ||
return thenable.then(locale => locale || defaultLocale) | ||
return thenable | ||
.then(locale => locale || defaultLocale) | ||
.catch(() => defaultLocale); | ||
@@ -93,7 +112,3 @@ }); | ||
try { | ||
if (process.platform === 'win32') { | ||
res = getWinLocaleSync(); | ||
} else { | ||
res = getUnixLocaleSync(); | ||
} | ||
res = process.platform === 'win32' ? getWinLocaleSync() : getUnixLocaleSync(); | ||
} catch (_) {} | ||
@@ -100,0 +115,0 @@ } |
{ | ||
"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.1.0", | ||
"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" | ||
} | ||
} |
@@ -9,3 +9,16 @@ # os-locale [![Build Status](https://travis-ci.org/sindresorhus/os-locale.svg?branch=master)](https://travis-ci.org/sindresorhus/os-locale) | ||
--- | ||
<div align="center"> | ||
<b> | ||
<a href="https://tidelift.com/subscription/pkg/npm-os-locale?utm_source=npm-os-locale&utm_medium=referral&utm_campaign=readme">Get professional support for 'os-locale' with a Tidelift subscription</a> | ||
</b> | ||
<br> | ||
<sub> | ||
Tidelift helps make open source sustainable for maintainers while giving companies<br>assurances about security, maintenance, and licensing for their dependencies. | ||
</sub> | ||
</div> | ||
--- | ||
## Install | ||
@@ -52,4 +65,9 @@ | ||
## Security | ||
To report a security vulnerability, please use the [Tidelift security contact](https://tidelift.com/security). Tidelift will coordinate the fix and disclosure. | ||
## License | ||
MIT © [Sindre Sorhus](https://sindresorhus.com) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
6183
92
72
+ Addedend-of-stream@1.4.4(transitive)
+ Addedexeca@1.0.0(transitive)
+ Addedget-stream@4.1.0(transitive)
+ Addedonce@1.4.0(transitive)
+ Addedpump@3.0.2(transitive)
+ Addedwrappy@1.0.2(transitive)
- Removedexeca@0.10.0(transitive)
- Removedget-stream@3.0.0(transitive)
Updatedexeca@^1.0.0