-
-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Require Node.js 12.20 and move to ESM
- Loading branch information
1 parent
05056f1
commit 728ed42
Showing
10 changed files
with
114 additions
and
117 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import {osLocaleSync} from './index.js'; | ||
|
||
// TODO: Enable when ESLint supports top-level await. | ||
// console.log(await osLocale()); | ||
console.log(osLocaleSync()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// Mini wrapper around `child_process` to make it behave a little like `execa`. | ||
|
||
import {promisify} from 'node:util'; | ||
import childProcess from 'node:child_process'; | ||
|
||
const execFile = promisify(childProcess.execFile); | ||
|
||
/** | ||
@param {string} command | ||
@param {string[]} arguments_ | ||
@returns {Promise<import('child_process').ChildProcess>} | ||
*/ | ||
export async function exec(command, arguments_) { | ||
const subprocess = await execFile(command, arguments_, {encoding: 'utf8'}); | ||
subprocess.stdout = subprocess.stdout.trim(); | ||
return subprocess; | ||
} | ||
|
||
/** | ||
@param {string} command | ||
@param {string[]} arguments_ | ||
@returns {string} | ||
*/ | ||
export function execSync(command, arguments_) { | ||
return childProcess.execFileSync(command, arguments_, {encoding: 'utf8'}).trim(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,38 @@ | ||
declare namespace osLocale { | ||
interface Options { | ||
/** | ||
Set to `false` to avoid spawning subprocesses and instead only resolve the locale from environment variables. | ||
@default true | ||
*/ | ||
readonly spawn?: boolean; | ||
} | ||
export interface Options { | ||
/** | ||
Set to `false` to avoid spawning subprocesses and instead only resolve the locale from environment variables. | ||
@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. | ||
@example | ||
``` | ||
import {osLocaleSync} from 'os-locale'; | ||
export = osLocale; | ||
console.log(osLocaleSync()); | ||
//=> 'en-US' | ||
``` | ||
*/ | ||
export function osLocaleSync(options?: Options): string; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
import {expectType} from 'tsd'; | ||
import osLocale = require('.'); | ||
import {osLocale, osLocaleSync} from './index.js'; | ||
|
||
expectType<Promise<string>>(osLocale()); | ||
expectType<Promise<string>>(osLocale({spawn: false})); | ||
|
||
expectType<string>(osLocale.sync()); | ||
expectType<string>(osLocale.sync({spawn: false})); | ||
expectType<string>(osLocaleSync()); | ||
expectType<string>(osLocaleSync({spawn: false})); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,38 +10,39 @@ | |
"email": "[email protected]", | ||
"url": "https://sindresorhus.com" | ||
}, | ||
"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", | ||
"system", | ||
"os", | ||
"string", | ||
"str", | ||
"user", | ||
"country", | ||
"id", | ||
"identifier", | ||
"region" | ||
], | ||
"dependencies": { | ||
"execa": "^4.0.0", | ||
"lcid": "^3.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.38.2" | ||
"tsd": "^0.17.0", | ||
"xo": "^0.42.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.