This commit is contained in:
136
node_modules/os-locale-s-fix/cjs/index.js
generated
vendored
Normal file
136
node_modules/os-locale-s-fix/cjs/index.js
generated
vendored
Normal file
@@ -0,0 +1,136 @@
|
||||
"use strict";
|
||||
/*!
|
||||
// Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
|
||||
// Released under the MIT license
|
||||
// https://opensource.org/licenses/mit-license.php
|
||||
*/
|
||||
/*!
|
||||
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
Copyright (C) 2020 jeffy-g <hirotom1107@gmail.com>
|
||||
Released under the MIT license
|
||||
https://opensource.org/licenses/mit-license.php
|
||||
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
*/
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
|
||||
const lcid = require("lcid");
|
||||
const child_process_1 = require("child_process");
|
||||
const defaultLocale = "en_US";
|
||||
const getStdOut = async (command, args) => await new Promise((resolve) => {
|
||||
child_process_1.execFile(command, args, (err, stdout) => {
|
||||
resolve(err || stdout);
|
||||
});
|
||||
});
|
||||
const getStdOutSync = (command, args) => {
|
||||
try {
|
||||
return child_process_1.execFileSync(command, args);
|
||||
}
|
||||
catch (e) {
|
||||
return e;
|
||||
}
|
||||
};
|
||||
const normalise = (input) => input.replace(/_/, "-");
|
||||
function validate(result, processor) {
|
||||
if (typeof result === "string" || result.length) {
|
||||
return processor ? processor(result.toString()) : result.toString().trim();
|
||||
}
|
||||
return defaultLocale;
|
||||
}
|
||||
const getEnvLocale = (env = process.env) => env.LC_ALL || env.LC_MESSAGES || env.LANG || env.LANGUAGE || "";
|
||||
function parseLocale(str) {
|
||||
const env = str.split("\n").reduce((env, definition) => {
|
||||
const [key, value] = definition.split("=");
|
||||
if (key && value) {
|
||||
env[key] = value.replace(/^"|"$/g, "");
|
||||
}
|
||||
return env;
|
||||
}, {});
|
||||
return getEnvLocale(env);
|
||||
}
|
||||
const purgeExtraToken = (str) => (str && str.replace(/[.:].*/, "")) || defaultLocale;
|
||||
const getSupportedLocale = (locale, locales) => locales.includes(locale) ? locale : defaultLocale;
|
||||
const [getAppleLocale, getAppleLocaleSync] = ((cmd0, args0, cmd1, args1) => {
|
||||
return [
|
||||
async () => {
|
||||
const results = await Promise.all([
|
||||
getStdOut(cmd0, args0).then(ret => validate(ret)),
|
||||
getStdOut(cmd1, args1).then(ret => validate(ret))
|
||||
]);
|
||||
return getSupportedLocale(results[0], results[1]);
|
||||
},
|
||||
() => getSupportedLocale(validate(getStdOutSync(cmd0, args0)), validate(getStdOutSync(cmd1, args1)))
|
||||
];
|
||||
})("defaults", ["read", "-globalDomain", "AppleLocale"], "locale", ["-a"]);
|
||||
const getUnixLocale = async () => purgeExtraToken(parseLocale(await getStdOut("locale").then(ret => validate(ret))));
|
||||
const getUnixLocaleSync = () => purgeExtraToken(parseLocale(validate(getStdOutSync("locale"))));
|
||||
const parseLCID = (result) => {
|
||||
const lcidCode = parseInt(result.replace("Locale", ""), 16);
|
||||
return lcid.from(lcidCode);
|
||||
};
|
||||
const [getWinLocale, getWinLocaleSync] = ((cmd0, args0) => {
|
||||
return [
|
||||
async () => validate(await getStdOut(cmd0, args0), parseLCID),
|
||||
() => validate(getStdOutSync(cmd0, args0), parseLCID)
|
||||
];
|
||||
})("wmic", ["os", "get", "locale"]);
|
||||
let detector;
|
||||
{
|
||||
const gettersSlot = [
|
||||
{
|
||||
win32: getWinLocaleSync,
|
||||
darwin: getAppleLocaleSync,
|
||||
linux: getUnixLocaleSync,
|
||||
}, {
|
||||
win32: getWinLocale,
|
||||
darwin: getAppleLocale,
|
||||
linux: getUnixLocale,
|
||||
}
|
||||
];
|
||||
const typeString = {}.toString;
|
||||
const isPromise = (o) => typeString.call(o) === "[object Promise]";
|
||||
let cacheLocal;
|
||||
const base = (async) => (options = {}) => {
|
||||
options = { spawn: true, cache: true, ...options };
|
||||
const cache = options.cache;
|
||||
if (cache && (cacheLocal === null || cacheLocal === void 0 ? void 0 : cacheLocal.length)) {
|
||||
return (async ? Promise.resolve(cacheLocal) : cacheLocal);
|
||||
}
|
||||
const functions = gettersSlot[+(!!async)];
|
||||
let locale;
|
||||
const withCache = (l, mustPromise) => {
|
||||
l = normalise(l);
|
||||
cacheLocal = cache ? l : void 0;
|
||||
return (mustPromise ? Promise.resolve(l) : l);
|
||||
};
|
||||
const envLocale = getEnvLocale();
|
||||
if (envLocale || !options.spawn) {
|
||||
locale = purgeExtraToken(envLocale);
|
||||
}
|
||||
else {
|
||||
let { platform } = process;
|
||||
if (platform !== "win32" && platform !== "darwin") {
|
||||
platform = "linux";
|
||||
}
|
||||
locale = functions[platform]();
|
||||
}
|
||||
if (isPromise(locale)) {
|
||||
return locale.then(result => withCache(result));
|
||||
}
|
||||
else {
|
||||
return withCache(locale, async === true || void 0);
|
||||
}
|
||||
};
|
||||
detector = (base(true));
|
||||
detector.sync = base();
|
||||
Object.defineProperties(detector, {
|
||||
purge: {
|
||||
value: () => cacheLocal = void 0,
|
||||
enumerable: false,
|
||||
},
|
||||
version: {
|
||||
value: "v1.0.8",
|
||||
enumerable: true,
|
||||
},
|
||||
});
|
||||
}
|
||||
exports.osLocale = Object.freeze(detector);
|
||||
133
node_modules/os-locale-s-fix/esm/index.js
generated
vendored
Normal file
133
node_modules/os-locale-s-fix/esm/index.js
generated
vendored
Normal file
@@ -0,0 +1,133 @@
|
||||
/*!
|
||||
// Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
|
||||
// Released under the MIT license
|
||||
// https://opensource.org/licenses/mit-license.php
|
||||
*/
|
||||
/*!
|
||||
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
Copyright (C) 2020 jeffy-g <hirotom1107@gmail.com>
|
||||
Released under the MIT license
|
||||
https://opensource.org/licenses/mit-license.php
|
||||
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
*/
|
||||
import * as lcid from "lcid";
|
||||
import { execFile, execFileSync, } from "child_process";
|
||||
const defaultLocale = "en_US";
|
||||
const getStdOut = async (command, args) => await new Promise((resolve) => {
|
||||
execFile(command, args, (err, stdout) => {
|
||||
resolve(err || stdout);
|
||||
});
|
||||
});
|
||||
const getStdOutSync = (command, args) => {
|
||||
try {
|
||||
return execFileSync(command, args);
|
||||
}
|
||||
catch (e) {
|
||||
return e;
|
||||
}
|
||||
};
|
||||
const normalise = (input) => input.replace(/_/, "-");
|
||||
function validate(result, processor) {
|
||||
if (typeof result === "string" && result.length) {
|
||||
return processor ? processor(result) : result.trim();
|
||||
}
|
||||
return defaultLocale;
|
||||
}
|
||||
const getEnvLocale = (env = process.env) => env.LC_ALL || env.LC_MESSAGES || env.LANG || env.LANGUAGE || "";
|
||||
function parseLocale(str) {
|
||||
const env = str.split("\n").reduce((env, definition) => {
|
||||
const [key, value] = definition.split("=");
|
||||
if (key && value) {
|
||||
env[key] = value.replace(/^"|"$/g, "");
|
||||
}
|
||||
return env;
|
||||
}, {});
|
||||
return getEnvLocale(env);
|
||||
}
|
||||
const purgeExtraToken = (str) => (str && str.replace(/[.:].*/, "")) || defaultLocale;
|
||||
const getSupportedLocale = (locale, locales) => locales.includes(locale) ? locale : defaultLocale;
|
||||
const [getAppleLocale, getAppleLocaleSync] = ((cmd0, args0, cmd1, args1) => {
|
||||
return [
|
||||
async () => {
|
||||
const results = await Promise.all([
|
||||
getStdOut(cmd0, args0).then(ret => validate(ret)),
|
||||
getStdOut(cmd1, args1).then(ret => validate(ret))
|
||||
]);
|
||||
return getSupportedLocale(results[0], results[1]);
|
||||
},
|
||||
() => getSupportedLocale(validate(getStdOutSync(cmd0, args0)), validate(getStdOutSync(cmd1, args1)))
|
||||
];
|
||||
})("defaults", ["read", "-globalDomain", "AppleLocale"], "locale", ["-a"]);
|
||||
const getUnixLocale = async () => purgeExtraToken(parseLocale(await getStdOut("locale").then(ret => validate(ret))));
|
||||
const getUnixLocaleSync = () => purgeExtraToken(parseLocale(validate(getStdOutSync("locale"))));
|
||||
const parseLCID = (result) => {
|
||||
const lcidCode = parseInt(result.replace("Locale", ""), 16);
|
||||
return lcid.from(lcidCode);
|
||||
};
|
||||
const [getWinLocale, getWinLocaleSync] = ((cmd0, args0) => {
|
||||
return [
|
||||
async () => validate(await getStdOut(cmd0, args0), parseLCID),
|
||||
() => validate(getStdOutSync(cmd0, args0), parseLCID)
|
||||
];
|
||||
})("wmic", ["os", "get", "locale"]);
|
||||
let detector;
|
||||
{
|
||||
const gettersSlot = [
|
||||
{
|
||||
win32: getWinLocaleSync,
|
||||
darwin: getAppleLocaleSync,
|
||||
linux: getUnixLocaleSync,
|
||||
}, {
|
||||
win32: getWinLocale,
|
||||
darwin: getAppleLocale,
|
||||
linux: getUnixLocale,
|
||||
}
|
||||
];
|
||||
const typeString = {}.toString;
|
||||
const isPromise = (o) => typeString.call(o) === "[object Promise]";
|
||||
let cacheLocal;
|
||||
const base = (async) => (options = {}) => {
|
||||
options = { spawn: true, cache: true, ...options };
|
||||
const cache = options.cache;
|
||||
if (cache && (cacheLocal === null || cacheLocal === void 0 ? void 0 : cacheLocal.length)) {
|
||||
return (async ? Promise.resolve(cacheLocal) : cacheLocal);
|
||||
}
|
||||
const functions = gettersSlot[+(!!async)];
|
||||
let locale;
|
||||
const withCache = (l, mustPromise) => {
|
||||
l = normalise(l);
|
||||
cacheLocal = cache ? l : void 0;
|
||||
return (mustPromise ? Promise.resolve(l) : l);
|
||||
};
|
||||
const envLocale = getEnvLocale();
|
||||
if (envLocale || !options.spawn) {
|
||||
locale = purgeExtraToken(envLocale);
|
||||
}
|
||||
else {
|
||||
let { platform } = process;
|
||||
if (platform !== "win32" && platform !== "darwin") {
|
||||
platform = "linux";
|
||||
}
|
||||
locale = functions[platform]();
|
||||
}
|
||||
if (isPromise(locale)) {
|
||||
return locale.then(result => withCache(result));
|
||||
}
|
||||
else {
|
||||
return withCache(locale, async === true || void 0);
|
||||
}
|
||||
};
|
||||
detector = (base(true));
|
||||
detector.sync = base();
|
||||
Object.defineProperties(detector, {
|
||||
purge: {
|
||||
value: () => cacheLocal = void 0,
|
||||
enumerable: false,
|
||||
},
|
||||
version: {
|
||||
value: "v1.0.8",
|
||||
enumerable: true,
|
||||
},
|
||||
});
|
||||
}
|
||||
export const osLocale = Object.freeze(detector);
|
||||
59
node_modules/os-locale-s-fix/index.d.ts
generated
vendored
Normal file
59
node_modules/os-locale-s-fix/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,59 @@
|
||||
//
|
||||
// Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
|
||||
// Released under the MIT license
|
||||
// https://opensource.org/licenses/mit-license.php
|
||||
//
|
||||
/*!
|
||||
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
Copyright (C) 2020 jeffy-g <hirotom1107@gmail.com>
|
||||
Released under the MIT license
|
||||
https://opensource.org/licenses/mit-license.php
|
||||
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
*/
|
||||
export declare interface LocaleDetectorOptions {
|
||||
/**
|
||||
* Set to `false` to avoid spawning subprocesses and instead only resolve the locale from environment variables.
|
||||
*
|
||||
* @default true
|
||||
*/
|
||||
readonly spawn?: boolean;
|
||||
/**
|
||||
* @default true
|
||||
*/
|
||||
readonly cache?: boolean;
|
||||
}
|
||||
export declare interface LocaleDetectorBase {
|
||||
/**
|
||||
* Get the system [locale](https://en.wikipedia.org/wiki/Locale_(computer_software)).
|
||||
*
|
||||
* @returns The locale.
|
||||
*
|
||||
* @example
|
||||
* ```
|
||||
* import { osLocale } = require("os-locale-s");
|
||||
*
|
||||
* (async () => {
|
||||
* console.log(await osLocale());
|
||||
* //=> 'en-US'
|
||||
* })();
|
||||
* ```
|
||||
*/
|
||||
(options?: LocaleDetectorOptions): Promise<string>;
|
||||
/**
|
||||
*
|
||||
*/
|
||||
readonly version: string;
|
||||
}
|
||||
|
||||
export declare interface LocaleDetector extends LocaleDetectorBase {
|
||||
/**
|
||||
* Synchronously get the system [locale](https://en.wikipedia.org/wiki/Locale_(computer_software)).
|
||||
*
|
||||
* @returns The locale.
|
||||
*/
|
||||
sync(options?: LocaleDetectorOptions): string;
|
||||
}
|
||||
|
||||
export declare const osLocale: LocaleDetector;
|
||||
|
||||
export as namespace NsOsLocale;
|
||||
21
node_modules/os-locale-s-fix/license
generated
vendored
Normal file
21
node_modules/os-locale-s-fix/license
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (C) 2020 jeffy-g <hirotom1107@gmail.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:
|
||||
|
||||
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.
|
||||
59
node_modules/os-locale-s-fix/package.json
generated
vendored
Normal file
59
node_modules/os-locale-s-fix/package.json
generated
vendored
Normal file
@@ -0,0 +1,59 @@
|
||||
{
|
||||
"name": "os-locale-s-fix",
|
||||
"version": "1.0.8-fix-1",
|
||||
"description": "Its a light weight version that minimizes the dependency module of `os-locale`",
|
||||
"private": false,
|
||||
"main": "./cjs/index.js",
|
||||
"module": "./esm/index.js",
|
||||
"sideEffects": false,
|
||||
"types": "./index.d.ts",
|
||||
"author": {
|
||||
"name": "jeffy-g",
|
||||
"email": "hirotom1107@gmail.com"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=10",
|
||||
"yarn": "^1.22.4"
|
||||
},
|
||||
"license": "MIT",
|
||||
"bugs": {
|
||||
"url": "https://github.com/jeffy-g/os-locale-s/issues"
|
||||
},
|
||||
"homepage": "https://github.com/jeffy-g/os-locale-s#readme",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/jeffy-g/os-locale-s.git"
|
||||
},
|
||||
"files": [
|
||||
"package.json",
|
||||
"license",
|
||||
"reamd.md",
|
||||
"cjs",
|
||||
"esm",
|
||||
"*.d.ts"
|
||||
],
|
||||
"keywords": [
|
||||
"typescript",
|
||||
"javascript",
|
||||
"locale",
|
||||
"lang",
|
||||
"language",
|
||||
"system",
|
||||
"os",
|
||||
"string",
|
||||
"user",
|
||||
"country",
|
||||
"id",
|
||||
"identifier",
|
||||
"region"
|
||||
],
|
||||
"dependencies": {
|
||||
"lcid": "^3.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"jest": "^26.4.2"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "jest --coverage --silent=false --colors -c=jest.configjs.js"
|
||||
}
|
||||
}
|
||||
83
node_modules/os-locale-s-fix/readme.md
generated
vendored
Normal file
83
node_modules/os-locale-s-fix/readme.md
generated
vendored
Normal file
@@ -0,0 +1,83 @@
|
||||
# OS locale detector (os-locale-s)
|
||||
[](https://lgtm.com/projects/g/jeffy-g/os-locale-s/context:javascript)  
|
||||
|
||||
__Its a light weight version that minimizes the dependency module of `os-locale`__
|
||||
|
||||
|
||||
> Get the system [locale](https://en.wikipedia.org/wiki/Locale_(computer_software))
|
||||
|
||||
Useful for localizing your module or app.
|
||||
|
||||
POSIX systems: The returned locale refers to the [`LC_MESSAGE`](http://www.gnu.org/software/libc/manual/html_node/Locale-Categories.html#Locale-Categories) category, suitable for selecting the language used in the user interface for message translation.
|
||||
|
||||
## Motivacion
|
||||
|
||||
I was creating a module package and needed to detect the **locale**.
|
||||
|
||||
At that time, I found a module `os-locale` that provides the corresponding function in the npm package.
|
||||
|
||||
I just wanted to detect locale token such as "cs", "de", "es", "fr" etc but
|
||||
`os-locale` installs as many as 27 npm packages, including indirectly dependent modules
|
||||
+ e.g - `yarn add os-locale`
|
||||
|
||||
I just wanted to detect a simple locale token but thought this was overwork and decided to rewrite the code.
|
||||
|
||||
At the same time, has been migrate to `TypeScript` as well.
|
||||
|
||||
> As a result, the number of npm packages installed in `os-locale-s` has been reduced to 3 including `os-locale-s`
|
||||
|
||||
|
||||
## Install
|
||||
|
||||
```
|
||||
$ npm install os-locale-s
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
```js
|
||||
// node (commenjs)
|
||||
const { osLocale } = require("os-locale-s");
|
||||
(async () => {
|
||||
console.log(await osLocale());
|
||||
//=> 'en-US'
|
||||
})();
|
||||
```
|
||||
|
||||
```ts
|
||||
// ECMA module
|
||||
import { osLocale } from "os-locale-s";
|
||||
(async () => {
|
||||
console.log(await osLocale());
|
||||
//=> 'en-US'
|
||||
})();
|
||||
```
|
||||
## API
|
||||
|
||||
### osLocale(options?)
|
||||
|
||||
Returns a `Promise` for the locale.
|
||||
|
||||
### osLocale.sync(options?)
|
||||
|
||||
Returns the locale.
|
||||
|
||||
#### options
|
||||
|
||||
Type: `object`
|
||||
|
||||
##### spawn
|
||||
|
||||
Type: `boolean`\
|
||||
Default: `true`
|
||||
|
||||
Set to `false` to avoid spawning subprocesses and instead only resolve the locale from environment variables. (`process.env`)
|
||||
|
||||
##### cache
|
||||
|
||||
Type: `boolean`\
|
||||
Default: `true`
|
||||
|
||||
Once the locale is detected, its value is retained and reused at the second and subsequent detections.
|
||||
|
||||
If set to `false`, the last held value will be ignored and do locale detection again (and the resulting value is not preserved)
|
||||
Reference in New Issue
Block a user