Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

os-locale

Package Overview
Dependencies
Maintainers
3
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

os-locale - npm Package Compare versions

Comparing version 1.2.1 to 1.3.0

51

index.js
'use strict';
var childProcess = require('child_process');
var execFileSync = require('exec-file-sync');
var execFileSync = childProcess.execFileSync;
var lcid = require('lcid');
var defaultOpts = {spawn: true};
var cache;
function fallback() {
cache = 'en_US';
return cache;
}
function getEnvLocale() {

@@ -20,7 +26,9 @@ var env = process.env;

function getLocale(str) {
return (str && str.replace(/[.:].*/, '')) || 'en_US';
return (str && str.replace(/[.:].*/, '')) || fallback();
}
module.exports = function (cb) {
if (cache || getEnvLocale()) {
module.exports = function (cb, opts) {
opts = opts || defaultOpts;
if (cache || getEnvLocale() || opts.spawn === false) {
setImmediate(cb, null, cache);

@@ -33,7 +41,7 @@ return;

if (err) {
cb(err);
fallback();
return;
}
cache = stdout.trim() || 'en_US';
cache = stdout.trim() || fallback();
cb(null, cache);

@@ -46,3 +54,3 @@ });

if (err) {
cb(err);
fallback();
return;

@@ -52,3 +60,3 @@ }

var lcidCode = parseInt(stdout.replace('Locale', ''), 16);
cache = lcid.from(lcidCode) || 'en_US';
cache = lcid.from(lcidCode) || fallback();
cb(null, cache);

@@ -59,3 +67,3 @@ });

if (err) {
cb(err);
fallback();
return;

@@ -77,4 +85,6 @@ }

module.exports.sync = function () {
if (cache || getEnvLocale()) {
module.exports.sync = function (opts) {
opts = opts || defaultOpts;
if (cache || getEnvLocale() || !execFileSync || opts.spawn === false) {
return cache;

@@ -89,16 +99,23 @@ }

} catch (err) {
cache = 'en_US';
return cache;
return fallback();
}
var lcidCode = parseInt(stdout.replace('Locale', ''), 16);
cache = lcid.from(lcidCode) || 'en_US';
cache = lcid.from(lcidCode) || fallback();
return cache;
}
var res = parseLocale(execFileSync('locale', {encoding: 'utf8'}));
var res;
try {
res = parseLocale(execFileSync('locale', {encoding: 'utf8'}));
} catch (err) {}
if (!res && process.platform === 'darwin') {
cache = execFileSync('defaults', ['read', '-g', 'AppleLocale'], {encoding: 'utf8'}).trim() || 'en_US';
return cache;
try {
cache = execFileSync('defaults', ['read', '-g', 'AppleLocale'], {encoding: 'utf8'}).trim() || fallback();
return cache;
} catch (err) {
return fallback();
}
}

@@ -105,0 +122,0 @@

{
"name": "os-locale",
"version": "1.2.1",
"version": "1.3.0",
"description": "Get the system locale",

@@ -16,3 +16,3 @@ "license": "MIT",

"scripts": {
"test": "xo && node test.js"
"test": "xo && ava"
},

@@ -37,9 +37,9 @@ "files": [

"dependencies": {
"exec-file-sync": "^2.0.0",
"lcid": "^1.0.0"
},
"devDependencies": {
"ava": "0.0.4",
"ava": "*",
"require-uncached": "^1.0.2",
"xo": "*"
}
}

@@ -27,4 +27,20 @@ # os-locale [![Build Status](https://travis-ci.org/sindresorhus/os-locale.svg?branch=master)](https://travis-ci.org/sindresorhus/os-locale)

## API
### osLocale([options], callback(error, locale))
### osLocale.sync([options])
Returns the locale.
#### options.spawn
Type: `boolean`
Default: `true`
Set to `false` to avoid spawning subprocesses and instead only resolve the locale from environment variables.
## License
MIT © [Sindre Sorhus](http://sindresorhus.com)
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc