Comparing version 4.0.0 to 5.0.0
47
index.js
@@ -9,2 +9,10 @@ 'use strict'; | ||
async function getStdOut(command, args) { | ||
return (await execa(command, args)).stdout; | ||
} | ||
function getStdOutSync(command, args) { | ||
return execa.sync(command, args).stdout; | ||
} | ||
function getEnvLocale(env = process.env) { | ||
@@ -29,7 +37,7 @@ return env.LC_ALL || env.LC_MESSAGES || env.LANG || env.LANGUAGE; | ||
async function getLocales() { | ||
return execa.stdout('locale', ['-a']); | ||
return getStdOut('locale', ['-a']); | ||
} | ||
function getLocalesSync() { | ||
return execa.sync('locale', ['-a']).stdout; | ||
return getStdOutSync('locale', ['-a']); | ||
} | ||
@@ -43,3 +51,3 @@ | ||
const results = await Promise.all([ | ||
execa.stdout('defaults', ['read', '-globalDomain', 'AppleLocale']), | ||
getStdOut('defaults', ['read', '-globalDomain', 'AppleLocale']), | ||
getLocales() | ||
@@ -53,3 +61,3 @@ ]); | ||
return getSupportedLocale( | ||
execa.sync('defaults', ['read', '-globalDomain', 'AppleLocale']).stdout, | ||
getStdOutSync('defaults', ['read', '-globalDomain', 'AppleLocale']), | ||
getLocalesSync() | ||
@@ -60,20 +68,13 @@ ); | ||
async function getUnixLocale() { | ||
if (process.platform === 'darwin') { | ||
return getAppleLocale(); | ||
} | ||
return getLocale(parseLocale(await execa.stdout('locale'))); | ||
return getLocale(parseLocale(await getStdOut('locale'))); | ||
} | ||
function getUnixLocaleSync() { | ||
if (process.platform === 'darwin') { | ||
return getAppleLocaleSync(); | ||
} | ||
return getLocale(parseLocale(execa.sync('locale').stdout)); | ||
return getLocale(parseLocale(getStdOutSync('locale'))); | ||
} | ||
async function getWinLocale() { | ||
const stdout = await execa.stdout('wmic', ['os', 'get', 'locale']); | ||
const stdout = await getStdOut('wmic', ['os', 'get', 'locale']); | ||
const lcidCode = parseInt(stdout.replace('Locale', ''), 16); | ||
return lcid.from(lcidCode); | ||
@@ -83,9 +84,15 @@ } | ||
function getWinLocaleSync() { | ||
const {stdout} = execa.sync('wmic', ['os', 'get', 'locale']); | ||
const stdout = getStdOutSync('wmic', ['os', 'get', 'locale']); | ||
const lcidCode = parseInt(stdout.replace('Locale', ''), 16); | ||
return lcid.from(lcidCode); | ||
} | ||
function normalise(input) { | ||
return input.replace(/_/, '-'); | ||
} | ||
const osLocale = mem(async (options = defaultOptions) => { | ||
let locale; | ||
try { | ||
@@ -98,2 +105,4 @@ const envLocale = getEnvLocale(); | ||
locale = await getWinLocale(); | ||
} else if (process.platform === 'darwin') { | ||
locale = await getAppleLocale(); | ||
} else { | ||
@@ -104,3 +113,3 @@ locale = await getUnixLocale(); | ||
return (locale || defaultLocale).replace(/_/, '-'); | ||
return normalise(locale || defaultLocale); | ||
}, {cachePromiseRejection: false}); | ||
@@ -119,2 +128,4 @@ | ||
locale = getWinLocaleSync(); | ||
} else if (process.platform === 'darwin') { | ||
locale = getAppleLocaleSync(); | ||
} else { | ||
@@ -125,3 +136,3 @@ locale = getUnixLocaleSync(); | ||
return (locale || defaultLocale).replace(/_/, '-'); | ||
return normalise(locale || defaultLocale); | ||
}); |
{ | ||
"name": "os-locale", | ||
"version": "4.0.0", | ||
"version": "5.0.0", | ||
"description": "Get the system locale", | ||
"license": "MIT", | ||
"repository": "sindresorhus/os-locale", | ||
"funding": "https://github.com/sponsors/sindresorhus", | ||
"author": { | ||
"name": "Sindre Sorhus", | ||
"email": "sindresorhus@gmail.com", | ||
"url": "sindresorhus.com" | ||
"url": "https://sindresorhus.com" | ||
}, | ||
"engines": { | ||
"node": ">=8" | ||
"node": ">=10" | ||
}, | ||
@@ -37,3 +38,3 @@ "scripts": { | ||
"dependencies": { | ||
"execa": "^1.0.0", | ||
"execa": "^4.0.0", | ||
"lcid": "^3.0.0", | ||
@@ -44,6 +45,6 @@ "mem": "^5.0.0" | ||
"ava": "^2.1.0", | ||
"import-fresh": "^3.0.0", | ||
"tsd": "^0.7.2", | ||
"xo": "^0.24.0" | ||
"proxyquire": "^2.1.3", | ||
"tsd": "^0.11.0", | ||
"xo": "^0.28.0" | ||
} | ||
} |
@@ -9,3 +9,2 @@ # os-locale [![Build Status](https://travis-ci.org/sindresorhus/os-locale.svg?branch=master)](https://travis-ci.org/sindresorhus/os-locale) | ||
## Install | ||
@@ -17,3 +16,2 @@ | ||
## Usage | ||
@@ -29,4 +27,2 @@ | ||
``` | ||
## API | ||
@@ -44,7 +40,7 @@ | ||
Type: `Object` | ||
Type: `object` | ||
##### spawn | ||
Type: `boolean`<br> | ||
Type: `boolean`\ | ||
Default: `true` | ||
@@ -54,13 +50,6 @@ | ||
## os-locale for enterprise | ||
--- | ||
Available as part of the Tidelift Subscription. | ||
<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> | ||
The maintainers of os-locale and thousands of other packages are working with Tidelift to deliver commercial support and maintenance for the open source dependencies you use to build your applications. Save time, reduce risk, and improve code health, while paying the maintainers of the exact dependencies you use. [Learn more.](https://tidelift.com/subscription/pkg/npm-os-locale?utm_source=npm-os-locale&utm_medium=referral&utm_campaign=enterprise&utm_term=repo) |
Sorry, the diff of this file is not supported yet
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
7238
130
51
+ Addedcross-spawn@7.0.3(transitive)
+ Addedexeca@4.1.0(transitive)
+ Addedget-stream@5.2.0(transitive)
+ Addedhuman-signals@1.1.1(transitive)
+ Addedis-stream@2.0.1(transitive)
+ Addedmerge-stream@2.0.0(transitive)
+ Addednpm-run-path@4.0.1(transitive)
+ Addedonetime@5.1.2(transitive)
+ Addedpath-key@3.1.1(transitive)
+ Addedshebang-command@2.0.0(transitive)
+ Addedshebang-regex@3.0.0(transitive)
+ Addedstrip-final-newline@2.0.0(transitive)
+ Addedwhich@2.0.2(transitive)
- Removedcross-spawn@6.0.5(transitive)
- Removedexeca@1.0.0(transitive)
- Removedget-stream@4.1.0(transitive)
- Removedis-stream@1.1.0(transitive)
- Removednice-try@1.0.5(transitive)
- Removednpm-run-path@2.0.2(transitive)
- Removedp-finally@1.0.0(transitive)
- Removedpath-key@2.0.1(transitive)
- Removedsemver@5.7.2(transitive)
- Removedshebang-command@1.2.0(transitive)
- Removedshebang-regex@1.0.0(transitive)
- Removedstrip-eof@1.0.0(transitive)
- Removedwhich@1.3.1(transitive)
Updatedexeca@^4.0.0