Skip to content

Commit

Permalink
Require Node.js 6
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed Aug 6, 2018
1 parent 7322d9e commit 3edb63c
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 45 deletions.
3 changes: 1 addition & 2 deletions .gitattributes
@@ -1,2 +1 @@
* text=auto
*.js text eol=lf
* text=auto eol=lf
1 change: 1 addition & 0 deletions .gitignore
@@ -1 +1,2 @@
node_modules
yarn.lock
1 change: 1 addition & 0 deletions .npmrc
@@ -0,0 +1 @@
package-lock=false
4 changes: 2 additions & 2 deletions .travis.yml
@@ -1,5 +1,5 @@
sudo: false
language: node_js
node_js:
- '10'
- '8'
- '6'
- '4'
24 changes: 11 additions & 13 deletions index.js
Expand Up @@ -3,7 +3,7 @@ const execa = require('execa');
const lcid = require('lcid');
const mem = require('mem');

const defaultOpts = {spawn: true};
const defaultOptions = {spawn: true};
const defaultLocale = 'en_US';

function getEnvLocale(env) {
Expand All @@ -20,8 +20,8 @@ function parseLocale(x) {
return getEnvLocale(env);
}

function getLocale(str) {
return (str && str.replace(/[.:].*/, ''));
function getLocale(string) {
return (string && string.replace(/[.:].*/, ''));
}

function getAppleLocale() {
Expand Down Expand Up @@ -58,17 +58,16 @@ function getWinLocale() {
}

function getWinLocaleSync() {
const stdout = execa.sync('wmic', ['os', 'get', 'locale']).stdout;
const {stdout} = execa.sync('wmic', ['os', 'get', 'locale']);
const lcidCode = parseInt(stdout.replace('Locale', ''), 16);
return lcid.from(lcidCode);
}

module.exports = mem(opts => {
opts = opts || defaultOpts;
module.exports = mem((options = defaultOptions) => {
const envLocale = getEnvLocale();
let thenable;

if (envLocale || opts.spawn === false) {
let thenable;
if (envLocale || options.spawn === false) {
thenable = Promise.resolve(getLocale(envLocale));
} else if (process.platform === 'win32') {
thenable = getWinLocale();
Expand All @@ -80,12 +79,11 @@ module.exports = mem(opts => {
.catch(() => defaultLocale);
});

module.exports.sync = mem(opts => {
opts = opts || defaultOpts;
module.exports.sync = mem((options = defaultOptions) => {
const envLocale = getEnvLocale();
let res;

if (envLocale || opts.spawn === false) {
let res;
if (envLocale || options.spawn === false) {
res = getLocale(envLocale);
} else {
try {
Expand All @@ -94,7 +92,7 @@ module.exports.sync = mem(opts => {
} else {
res = getUnixLocaleSync();
}
} catch (err) {}
} catch (_) {}
}

return res || defaultLocale;
Expand Down
20 changes: 4 additions & 16 deletions license
@@ -1,21 +1,9 @@
The MIT License (MIT)
MIT License

Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
8 changes: 4 additions & 4 deletions package.json
Expand Up @@ -10,7 +10,7 @@
"url": "sindresorhus.com"
},
"engines": {
"node": ">=4"
"node": ">=6"
},
"scripts": {
"test": "xo && ava"
Expand All @@ -33,9 +33,9 @@
"region"
],
"dependencies": {
"execa": "^0.7.0",
"lcid": "^1.0.0",
"mem": "^1.1.0"
"execa": "^0.10.0",
"lcid": "^2.0.0",
"mem": "^3.0.1"
},
"devDependencies": {
"ava": "*",
Expand Down
8 changes: 4 additions & 4 deletions readme.md
Expand Up @@ -10,7 +10,7 @@ POSIX systems: The returned locale refers to the [`LC_MESSAGE`](http://www.gnu.o
## Install

```
$ npm install --save os-locale
$ npm install os-locale
```


Expand All @@ -19,10 +19,10 @@ $ npm install --save os-locale
```js
const osLocale = require('os-locale');

osLocale().then(locale => {
console.log(locale);
(async () => {
console.log(await osLocale());
//=> 'en_US'
});
})();
```


Expand Down
8 changes: 4 additions & 4 deletions test.js
Expand Up @@ -6,20 +6,20 @@ const envVars = ['LC_ALL', 'LANGUAGE', 'LANG', 'LC_MESSAGES'];
const expectedFallback = 'en_US';

function unsetEnvVars(cache) {
envVars.forEach(envVar => {
for (const envVar of envVars) {
if (process.env[envVar]) {
cache[envVar] = process.env[envVar];
delete process.env[envVar];
}
});
}
}

function restoreEnvVars(cache) {
envVars.forEach(envVar => {
for (const envVar of envVars) {
if (cache[envVar]) {
process.env[envVar] = cache[envVar];
}
});
}
}

test('async', async t => {
Expand Down

0 comments on commit 3edb63c

Please sign in to comment.