Socket
Socket
Sign inDemoInstall

os-locale

Package Overview
Dependencies
2
Maintainers
3
Versions
18
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 5.0.0 to 6.0.0

exec.js

58

index.d.ts

@@ -1,38 +0,38 @@

declare namespace osLocale {
interface Options {
/**
Set to `false` to avoid spawning subprocesses and instead only resolve the locale from environment variables.
export interface Options {
/**
Set to `false` to avoid spawning subprocesses and instead only resolve the locale from environment variables.
@default true
*/
readonly spawn?: boolean;
}
@default true
*/
readonly spawn?: boolean;
}
declare const osLocale: {
/**
Get the system [locale](https://en.wikipedia.org/wiki/Locale_(computer_software)).
/**
Get the system [locale](https://en.wikipedia.org/wiki/Locale_(computer_software)).
@returns The locale.
@returns The locale.
@example
```
import osLocale = require('os-locale');
@example
```
import {osLocale} from 'os-locale';
(async () => {
console.log(await osLocale());
//=> 'en-US'
})();
```
*/
(options?: osLocale.Options): Promise<string>;
console.log(await osLocale());
//=> 'en-US'
```
*/
export function osLocale(options?: Options): Promise<string>;
/**
Synchronously get the system [locale](https://en.wikipedia.org/wiki/Locale_(computer_software)).
/**
Synchronously get the system [locale](https://en.wikipedia.org/wiki/Locale_(computer_software)).
@returns The locale.
*/
sync(options?: osLocale.Options): string;
};
@returns The locale.
export = osLocale;
@example
```
import {osLocaleSync} from 'os-locale';
console.log(osLocaleSync());
//=> 'en-US'
```
*/
export function osLocaleSync(options?: Options): string;

@@ -1,5 +0,3 @@

'use strict';
const execa = require('execa');
const lcid = require('lcid');
const mem = require('mem');
import lcid from 'lcid';
import {exec, execSync} from './exec.js';

@@ -10,7 +8,7 @@ const defaultOptions = {spawn: true};

async function getStdOut(command, args) {
return (await execa(command, args)).stdout;
return (await exec(command, args)).stdout;
}
function getStdOutSync(command, args) {
return execa.sync(command, args).stdout;
return execSync(command, args).stdout;
}

@@ -23,7 +21,7 @@

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

@@ -52,3 +50,3 @@ return getEnvLocale(env);

getStdOut('defaults', ['read', '-globalDomain', 'AppleLocale']),
getLocales()
getLocales(),
]);

@@ -62,3 +60,3 @@

getStdOutSync('defaults', ['read', '-globalDomain', 'AppleLocale']),
getLocalesSync()
getLocalesSync(),
);

@@ -77,3 +75,3 @@ }

const stdout = await getStdOut('wmic', ['os', 'get', 'locale']);
const lcidCode = parseInt(stdout.replace('Locale', ''), 16);
const lcidCode = Number.parseInt(stdout.replace('Locale', ''), 16);

@@ -85,3 +83,3 @@ return lcid.from(lcidCode);

const stdout = getStdOutSync('wmic', ['os', 'get', 'locale']);
const lcidCode = parseInt(stdout.replace('Locale', ''), 16);
const lcidCode = Number.parseInt(stdout.replace('Locale', ''), 16);

@@ -95,3 +93,9 @@ return lcid.from(lcidCode);

const osLocale = mem(async (options = defaultOptions) => {
const cache = new Map();
export async function osLocale(options = defaultOptions) {
if (cache.has(options.spawn)) {
return cache.get(options.spawn);
}
let locale;

@@ -111,10 +115,14 @@

}
} catch (_) {}
} catch {}
return normalise(locale || defaultLocale);
}, {cachePromiseRejection: false});
const normalised = normalise(locale || defaultLocale);
cache.set(options.spawn, normalised);
return normalised;
}
module.exports = osLocale;
export function osLocaleSync(options = defaultOptions) {
if (cache.has(options.spawn)) {
return cache.get(options.spawn);
}
module.exports.sync = mem((options = defaultOptions) => {
let locale;

@@ -133,5 +141,7 @@ try {

}
} catch (_) {}
} catch {}
return normalise(locale || defaultLocale);
});
const normalised = normalise(locale || defaultLocale);
cache.set(options.spawn, normalised);
return normalised;
}
{
"name": "os-locale",
"version": "5.0.0",
"version": "6.0.0",
"description": "Get the system locale",

@@ -13,15 +13,18 @@ "license": "MIT",

},
"type": "module",
"exports": "./index.js",
"engines": {
"node": ">=10"
"node": ">=12.20"
},
"scripts": {
"test": "xo && ava && tsd"
"//test": "xo && ava && tsd",
"test": "xo && tsd"
},
"files": [
"index.js",
"index.d.ts"
"index.d.ts",
"exec.js"
],
"keywords": [
"locale",
"lang",
"language",

@@ -31,3 +34,2 @@ "system",

"string",
"str",
"user",

@@ -40,12 +42,10 @@ "country",

"dependencies": {
"execa": "^4.0.0",
"lcid": "^3.0.0",
"mem": "^5.0.0"
"lcid": "^3.1.1"
},
"devDependencies": {
"ava": "^2.1.0",
"ava": "^3.15.0",
"proxyquire": "^2.1.3",
"tsd": "^0.11.0",
"xo": "^0.28.0"
"tsd": "^0.17.0",
"xo": "^0.42.0"
}
}

@@ -1,2 +0,2 @@

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

@@ -18,8 +18,6 @@ > Get the system [locale](https://en.wikipedia.org/wiki/Locale_(computer_software))

```js
const osLocale = require('os-locale');
import {osLocale} from 'os-locale';
(async () => {
console.log(await osLocale());
//=> 'en-US'
})();
console.log(await osLocale());
//=> 'en-US'
```

@@ -26,0 +24,0 @@ ## API

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc