-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathindex.d.ts
87 lines (81 loc) · 2.98 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
/**
* Macro namespace for grabbing an environment variable
*/
export namespace $env {
/**
* Attempts to fetch the given environment variable - if not set, it will be `undefined` or the default value if given.
* @param name The name of the variable
* @param defaultValue The default value to use if undefined
*/
export function string(name: string): string | undefined;
export function string(name: string, defaultValue: string): string;
// /**
// * Attempts to fetch the given environment variable as a string - will throw a compiler error otherwise.
// * @param name The name of the environment variable to expect
// */
// export function expectString<_TCompilerError extends string>(name: string, message?: _TCompilerError): string;
/**
* Converts the given environment variable to a boolean - if not set will be set `defaultValue` or `false`.
*
* ```ts
* if ($env.boolean("SOME_DEBUG_FLAG")) {
* // Use some debugging feature :-)
* }
* ```
*
* This can also be used to check if an environment variable is set, e.g.
*
* ```ts
* if ($env.boolean("ANALYTICS_API_URL")) {
* const ANALYTICS_API_URL = $env.string("ANALYTICS_API_URL")!;
* // Use our analytics API...
* }
* ```
* @param name The environment variable to use
* @param defaultValue The default value to use - otherwise `false`
*/
export function boolean(name: string): boolean;
export function boolean(name: string, defaultValue: boolean): boolean;
/**
* Attempts to convert the given environment variable to a number - if not set, it will be `undefined` or the default value if given.
*
* @param name The name of the variable
* @param defaultValue The default value to use if undefined
*/
export function number(name: string): number | undefined;
export function number(name: string, defaultValue: number): number;
// /**
// * Attempts to fetch the given environment variable as a number - will throw a compiler error otherwise.
// * @param name The name of the environment variable to expect
// */
// export function expectNumber(name: string): number;
}
/**
* Macro for rendering a block of code if the variable matches the specified value
* @param envVar The environment variable
* @param matches The value(s) to match
* @param runMatched The function containing the code to render
*
* **The third argument MUST be an arrow function.**
* e.g.
*
* ```ts
* $ifEnv("NODE_ENV", "development", () => {
* print("Example code that will be rendered only if NODE_ENV is 'development'")
* })
* ```
*
* will result in
* ```lua
* (function()
* print("Example code that will be rendered only if NODE_ENV is 'development'")
* end)()
* ```
* IF NODE_ENV is 'development', otherwise nothing will be emitted.
*/
// export function $ifEnv(envVar: string, matches: string, runMatched: () => void): void;
// export function $ifEnv(envVar: string, matches: readonly string[], runMatched: (matched: string) => void): void;
/**
* Returns the `NODE_ENV` variable
*/
export const $NODE_ENV: string;