-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.d.ts
101 lines (95 loc) · 2.92 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
//
// Copyright (c) Sindre Sorhus <[email protected]> (https://sindresorhus.com)
// Released under the MIT license
// https://opensource.org/licenses/mit-license.php
//
/*!
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Copyright (C) 2020 jeffy-g <[email protected]>
Released under the MIT license
https://opensource.org/licenses/mit-license.php
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
*/
declare global {
/**
* T is falsy then return A, trusy then B
*
* ```ts
* type ConditionalX<T, A, B> = T extends (void | false | undefined) ? A : B // <- maybe not works
* type Conditional<T, A, B> = void extends T ? A : T extends (void | false | undefined) ? A : B;
*
* function x<T extends true | void, R extends ConditionalX<T, string, string[]>>(need?: T): R {
* return (need? "": [""]) as R;
* }
* // string | string[]
* const xret = x();
* // string[]
* const xret2 = x(true);
*
* function ok<T extends true | void, R extends Conditional<T, string, string[]>>(need?: T): R {
* return (need? "": [""]) as R;
* }
* // string
* const okret = ok();
* // string[]
* const okret2 = ok(true);
* ```
*
* @date 20/03/31
*/
type Conditional<T, A, B> = void extends T ? A : T extends (void | false | undefined) ? A : B;
}
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;
}
/**
* @internal
*/
export type TInternalLocaleDetectorSig = {
bivarianceHack<IsAsync extends true | void, R extends Conditional<IsAsync, string, Promise<string>>>(async?: IsAsync): (options?: LocaleDetectorOptions) => R;
}["bivarianceHack"];
// /**
// * @internal
// */
// export type TInternalLocaleDetectorResult = ReturnType<ReturnType<TInternalLocaleDetectorSig>>;
export declare const osLocale: LocaleDetector;
export as namespace NsOsLocale;