@js-toolkit/configs 3.89.0 → 3.89.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/appEnv.d.ts +7 -3
- package/appEnv.js +1 -1
- package/package.json +1 -1
package/appEnv.d.ts
CHANGED
|
@@ -4,12 +4,16 @@ export type EnvVarType = string | number | boolean | undefined;
|
|
|
4
4
|
export interface AppEnvVars {
|
|
5
5
|
NODE_ENV: NodeEnv;
|
|
6
6
|
APP_SSR: boolean;
|
|
7
|
+
APP_TEST: boolean;
|
|
7
8
|
}
|
|
9
|
+
type CustomAppEnvVars = {
|
|
10
|
+
[P in string as `APP_${P}`]: EnvVarType;
|
|
11
|
+
};
|
|
8
12
|
type ValueGetter<T> = () => T;
|
|
9
13
|
type ValueOrGetter<T> = T | ValueGetter<T>;
|
|
10
14
|
export interface AppEnvironment {
|
|
11
15
|
/** Object with keys and their default values so we can feed into Webpack EnvironmentPlugin. */
|
|
12
|
-
raw: AppEnvVars &
|
|
16
|
+
raw: AppEnvVars & CustomAppEnvVars;
|
|
13
17
|
/** Stringify all values that we can feed into Webpack DefinePlugin. */
|
|
14
18
|
envStringify(): {
|
|
15
19
|
'process.env': Record<string, string>;
|
|
@@ -20,13 +24,13 @@ export interface AppEnvironment {
|
|
|
20
24
|
ssr: boolean;
|
|
21
25
|
/** Use NODE_ENV environment variable. */
|
|
22
26
|
dev: boolean;
|
|
23
|
-
/** Use NODE_ENV environment variable
|
|
27
|
+
/** Use NODE_ENV environment variable and `APP_TEST`. */
|
|
24
28
|
test: boolean;
|
|
25
29
|
/** Use NODE_ENV environment variable. */
|
|
26
30
|
prod: boolean;
|
|
27
31
|
/** Use NODE_ENV environment variable. */
|
|
28
32
|
ifDev<T>(devModeValue: ValueOrGetter<T>, elseValue: ValueOrGetter<T>): T;
|
|
29
|
-
/** Use NODE_ENV environment variable
|
|
33
|
+
/** Use NODE_ENV environment variable and `APP_TEST`. */
|
|
30
34
|
ifTest<T>(testModeValue: ValueOrGetter<T>, elseValue: ValueOrGetter<T>): T;
|
|
31
35
|
/** Use NODE_ENV environment variable. */
|
|
32
36
|
ifProd<T>(prodModeValue: ValueOrGetter<T>, elseValue: ValueOrGetter<T>): T;
|
package/appEnv.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";function parseJson(
|
|
1
|
+
"use strict";function parseJson(t){if(null==t)return t;try{return JSON.parse(t)}catch(e){return t}}function getAppEnvironment(){const t=/^APP_/i,e=process.env,n=Object.keys(e).filter((e=>t.test(e))).reduce(((t,n)=>(t[n]=parseJson(e[n]),t)),{NODE_ENV:parseJson(e.NODE_ENV||"development"),APP_SSR:!1,APP_TEST:!1}),r={raw:n,envStringify(){return{"process.env":Object.keys(this.raw).reduce(((t,e)=>{const n=e;return t[e]=JSON.stringify(this.raw[n]),t}),{})}},has:t=>t in n,get:t=>n[t],get ssr(){return!0===this.raw.APP_SSR},get dev(){return"development"===this.raw.NODE_ENV},get test(){return"test"===this.raw.NODE_ENV||!0===this.raw.APP_TEST},get prod(){return"production"===this.raw.NODE_ENV},ifDev(t,e){return this.dev?"function"==typeof t?t():t:"function"==typeof e?e():e},ifTest(t,e){return this.test?"function"==typeof t?t():t:"function"==typeof e?e():e},ifProd(t,e){return this.prod?"function"==typeof t?t():t:"function"==typeof e?e():e}};return("undefined"==typeof window?global:window).Proxy?new Proxy(r,{get:(t,e)=>"string"!=typeof e||e in t?t[e]:t.raw[e],has:(t,e)=>e in t||e in t.raw}):r}Object.defineProperty(exports,"__esModule",{value:!0}),exports.getAppEnvironment=void 0,exports.getAppEnvironment=getAppEnvironment;const appEnv=getAppEnvironment();exports.default=appEnv;
|