@uni-helper/uni-env 0.0.3 → 0.1.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/README.md CHANGED
@@ -1,17 +1,16 @@
1
1
  # @uni-helper/uni-env
2
2
 
3
- > 在 uni-app 中优雅的判断当前环境
3
+ 在 uni-app 中优雅的判断当前环境
4
+
5
+ [![npm version][npm-version-src]][npm-version-href]
6
+ [![npm downloads][npm-downloads-src]][npm-downloads-href]
7
+ [![bundle][bundle-src]][bundle-href]
8
+ [![License][license-src]][license-href]
9
+ [![JSDocs][jsdocs-src]][jsdocs-href]
4
10
 
5
11
  ## 安装
6
12
 
7
13
  ```sh
8
- # Using Yarn
9
- yarn add @uni-helper/uni-env
10
-
11
- # Using npm
12
- npm i @uni-helper/uni-env
13
-
14
- # Using pnpm
15
14
  pnpm i @uni-helper/uni-env
16
15
  ```
17
16
 
@@ -19,20 +18,23 @@ pnpm i @uni-helper/uni-env
19
18
 
20
19
  ```js
21
20
  // ESM
22
- import { isMpWeixin } from "@uni-helper/uni-env";
21
+ import { isMpWeixin } from '@uni-helper/uni-env'
23
22
 
24
23
  // CommonJS
25
- const { isMp } = require("@uni-helper/uni-env");
24
+ const { isMp } = require('@uni-helper/uni-env')
26
25
  ```
27
26
 
28
- 你可以从 [./src/index.ts](./src/index.ts) 中查看更多标志以及如何判断的。
29
-
30
- ## 注意
31
-
32
- 这个包更多的是为插件开发者提供,如果你在运行时引入并不能做到条件编译。
33
-
34
- 要做条件编译的话,请使用官方的 [跨端兼容 - 条件编译](https://uniapp.dcloud.net.cn/tutorial/platform.html#preprocessor),如果你需要更好的条件编译,你可以使用 [vite-plugin-conditional-compiler](https://github.com/KeJunMao/vite-plugin-conditional-compile)
35
-
36
- ## 协议
37
-
38
- [MIT](./LICENSE)
27
+ > [!NOTE]
28
+ > 这个包更多的是为插件开发者提供,如果你在运行时引入并不能做到条件编译。
29
+ > 要做条件编译的话,请使用官方的 [跨端兼容 - 条件编译](https://uniapp.dcloud.net.cn/tutorial/platform.html#preprocessor),如果你需要更好的条件编译,你可以使用 [unplugin-preprocessor-directives](https://github.com/KeJunMao/unplugin-preprocessor-directives)
30
+
31
+ [npm-version-src]: https://img.shields.io/npm/v/@uni-helper/uni-env?style=flat&colorA=18181B&colorB=F0DB4F
32
+ [npm-version-href]: https://npmjs.com/package/@uni-helper/uni-env
33
+ [npm-downloads-src]: https://img.shields.io/npm/dm/@uni-helper/uni-env?style=flat&colorA=18181B&colorB=F0DB4F
34
+ [npm-downloads-href]: https://npmjs.com/package/@uni-helper/uni-env
35
+ [bundle-src]: https://img.shields.io/bundlephobia/minzip/@uni-helper/uni-env?style=flat&colorA=18181B&colorB=F0DB4F
36
+ [bundle-href]: https://bundlephobia.com/result?p=@uni-helper/uni-env
37
+ [license-src]: https://img.shields.io/github/license/uni-helper/uni-env.svg?style=flat&colorA=18181B&colorB=F0DB4F
38
+ [license-href]: https://github.com/uni-helper/uni-env/blob/main/LICENSE
39
+ [jsdocs-src]: https://img.shields.io/badge/jsDocs.io-reference-18181B?style=flat&colorA=18181B&colorB=F0DB4F
40
+ [jsdocs-href]: https://www.jsdocs.io/package/@uni-helper/uni-env
package/dist/index.cjs CHANGED
@@ -1,34 +1,29 @@
1
1
  'use strict';
2
2
 
3
- const processShim = typeof process !== "undefined" ? process : {};
4
- const envShim = processShim.env || {};
5
- const platform = envShim.UNI_PLATFORM;
6
- const utsPlatform = envShim.UNI_UTS_PLATFORM;
7
- const appPlatform = envShim.UNI_APP_PLATFORM;
8
- const subPlatform = envShim.UNI_SUB_PLATFORM;
9
- const cliContext = envShim.UNI_CLI_CONTEXT;
10
- const inputDir = envShim.UNI_INPUT_DIR;
11
- const outputDir = envShim.UNI_OUTPUT_DIR;
12
- const hasDarkMode = toBoolean(envShim.VUE_APP_DARK_MODE);
13
- const hasSourcemap = toBoolean(envShim.SOURCEMAP);
14
- const compiler = envShim.UNI_COMPILER;
15
- const nvueCompiler = envShim.UNI_NVUE_COMPILER;
16
- const nvueStyleCompiler = envShim.UNI_NVUE_STYLE_COMPILER;
17
- const compilerVersion = envShim.UNI_COMPILER_VERSION;
18
- const compilerVersionType = envShim.UNI_COMPILER_VERSION_TYPE;
19
- const statTitleJson = parseJSON(
20
- envShim.STAT_TITLE_JSON
21
- );
22
- const customContext = envShim.UNI_CUSTOM_CONTEXT;
23
- const customScript = envShim.UNI_CUSTOM_SCRIPT;
24
- const customDefine = envShim.UNI_CUSTOM_DEFINE;
25
- const subpackage = envShim.UNI_SUBPACKAGE;
26
- const isMpPlugin = toBoolean(envShim.UNI_MP_PLUGIN);
27
- const renderer = envShim.UNI_RENDERER;
28
- const rendererNative = envShim.UNI_RENDERER_NATIVE;
29
- const isMinimize = toBoolean(envShim.UNI_MINIMIZE);
30
- const isSSRClient = toBoolean(envShim.UNI_SSR_CLIENT);
31
- const isSSRServer = toBoolean(envShim.UNI_SSR_SERVER);
3
+ const stdEnv = require('std-env');
4
+
5
+ const builtInPlatforms = [
6
+ "app",
7
+ "app-plus",
8
+ "h5",
9
+ "mp-360",
10
+ "mp-alipay",
11
+ "mp-baidu",
12
+ "mp-jd",
13
+ "mp-kuaishou",
14
+ "mp-lark",
15
+ "mp-qq",
16
+ "mp-toutiao",
17
+ "mp-weixin",
18
+ "quickapp-webview",
19
+ "quickapp-webview-huawei",
20
+ "quickapp-webview-union"
21
+ ];
22
+
23
+ const platform = stdEnv.env.UNI_PLATFORM;
24
+ const utsPlatform = stdEnv.env.UNI_UTS_PLATFORM;
25
+ const appPlatform = stdEnv.env.UNI_APP_PLATFORM;
26
+ const subPlatform = stdEnv.env.UNI_SUB_PLATFORM;
32
27
  const isH5 = platform === "h5";
33
28
  const isApp = platform === "app";
34
29
  const isAppAndroid = appPlatform === "android" || utsPlatform === "app-android";
@@ -40,9 +35,10 @@ const isMpBaidu = platform === "mp-baidu";
40
35
  const isMpKuaishou = platform === "mp-kuaishou";
41
36
  const isMpQQ = platform === "mp-qq";
42
37
  const isMpToutiao = platform === "mp-toutiao";
43
- const isQuickapp = /^quickapp--webview/i.test(platform);
38
+ const isQuickapp = /^quickapp-webview/i.test(platform);
44
39
  const isQuickappUnion = platform === "quickapp-webview-union";
45
40
  const isQuickappHuawei = platform === "quickapp-webview-huawei";
41
+
46
42
  function toBoolean(val) {
47
43
  return val ? val !== "false" : false;
48
44
  }
@@ -56,7 +52,34 @@ function parseJSON(val) {
56
52
  return obj;
57
53
  }
58
54
 
55
+ const hasDarkMode = toBoolean(stdEnv.env.VUE_APP_DARK_MODE);
56
+ const hasSourcemap = toBoolean(stdEnv.env.SOURCEMAP);
57
+ const isMpPlugin = toBoolean(stdEnv.env.UNI_MP_PLUGIN);
58
+ const isMinimize = toBoolean(stdEnv.env.UNI_MINIMIZE);
59
+ const isSSRClient = toBoolean(stdEnv.env.UNI_SSR_CLIENT);
60
+ const isSSRServer = toBoolean(stdEnv.env.UNI_SSR_SERVER);
61
+
62
+ const compiler = stdEnv.env.UNI_COMPILER;
63
+ const nvueCompiler = stdEnv.env.UNI_NVUE_COMPILER;
64
+ const nvueStyleCompiler = stdEnv.env.UNI_NVUE_STYLE_COMPILER;
65
+ const compilerVersion = stdEnv.env.UNI_COMPILER_VERSION;
66
+ const compilerVersionType = stdEnv.env.UNI_COMPILER_VERSION_TYPE;
67
+
68
+ const cliContext = stdEnv.env.UNI_CLI_CONTEXT;
69
+ const inputDir = stdEnv.env.UNI_INPUT_DIR;
70
+ const outputDir = stdEnv.env.UNI_OUTPUT_DIR;
71
+ const statTitleJson = parseJSON(
72
+ stdEnv.env.STAT_TITLE_JSON
73
+ );
74
+ const customContext = stdEnv.env.UNI_CUSTOM_CONTEXT;
75
+ const customScript = stdEnv.env.UNI_CUSTOM_SCRIPT;
76
+ const customDefine = stdEnv.env.UNI_CUSTOM_DEFINE;
77
+ const subpackage = stdEnv.env.UNI_SUBPACKAGE;
78
+ const renderer = stdEnv.env.UNI_RENDERER;
79
+ const rendererNative = stdEnv.env.UNI_RENDERER_NATIVE;
80
+
59
81
  exports.appPlatform = appPlatform;
82
+ exports.builtInPlatforms = builtInPlatforms;
60
83
  exports.cliContext = cliContext;
61
84
  exports.compiler = compiler;
62
85
  exports.compilerVersion = compilerVersion;
@@ -0,0 +1,90 @@
1
+ declare const builtInPlatforms: readonly ["app", "app-plus", "h5", "mp-360", "mp-alipay", "mp-baidu", "mp-jd", "mp-kuaishou", "mp-lark", "mp-qq", "mp-toutiao", "mp-weixin", "quickapp-webview", "quickapp-webview-huawei", "quickapp-webview-union"];
2
+
3
+ type BuiltInPlatForm = typeof builtInPlatforms[number];
4
+ type UtsPlatform = BuiltInPlatForm | 'app-android' | 'app-ios' | 'web';
5
+ type AppPlatform = 'android' | 'ios' | undefined;
6
+ type SubPlatform = 'quickapp-webview-huawei' | 'quickapp-webview-union' | undefined;
7
+
8
+ /** Value of `process.env.UNI_PLATFORM` */
9
+ declare const platform: "app" | "app-plus" | "h5" | "mp-360" | "mp-alipay" | "mp-baidu" | "mp-jd" | "mp-kuaishou" | "mp-lark" | "mp-qq" | "mp-toutiao" | "mp-weixin" | "quickapp-webview" | "quickapp-webview-huawei" | "quickapp-webview-union";
10
+ /** Value of `process.env.UNI_UTS_PLATFORM` */
11
+ declare const utsPlatform: UtsPlatform;
12
+ /** Value of `process.env.UNI_APP_PLATFORM` */
13
+ declare const appPlatform: AppPlatform;
14
+ /** Value of `process.env.UNI_SUB_PLATFORM` */
15
+ declare const subPlatform: SubPlatform;
16
+ /** Detect if `process.env.UNI_PLATFORM` is `H5` */
17
+ declare const isH5: boolean;
18
+ /** Detect if `process.env.UNI_PLATFORM` is `APP` */
19
+ declare const isApp: boolean;
20
+ /** Detect if `process.env.UNI_APP_PLATFORM` is `android` or if `process.env.UNI_UTS_PLATFORM` is "app-android" */
21
+ declare const isAppAndroid: boolean;
22
+ /** Detect if `process.env.UNI_APP_PLATFORM` is `ios` or if `process.env.UNI_UTS_PLATFORM` is "app-ios" */
23
+ declare const isAppIOS: boolean;
24
+ /** Detect if `process.env.UNI_PLATFORM` is `小程序` */
25
+ declare const isMp: boolean;
26
+ /** Detect if `process.env.UNI_PLATFORM` is `微信小程序` */
27
+ declare const isMpWeixin: boolean;
28
+ /** Detect if `process.env.UNI_PLATFORM` is `支付宝小程序` */
29
+ declare const isMpAlipay: boolean;
30
+ /** Detect if `process.env.UNI_PLATFORM` is `百度小程序` */
31
+ declare const isMpBaidu: boolean;
32
+ /** Detect if `process.env.UNI_PLATFORM` is `快手小程序` */
33
+ declare const isMpKuaishou: boolean;
34
+ /** Detect if `process.env.UNI_PLATFORM` is `QQ小程序` */
35
+ declare const isMpQQ: boolean;
36
+ /** Detect if `process.env.UNI_PLATFORM` is `头条小程序` */
37
+ declare const isMpToutiao: boolean;
38
+ /** Detect if `process.env.UNI_PLATFORM` is `快应用` */
39
+ declare const isQuickapp: boolean;
40
+ /** Detect if `process.env.UNI_PLATFORM` is `快应用联盟` */
41
+ declare const isQuickappUnion: boolean;
42
+ /** Detect if `process.env.UNI_PLATFORM` is `快应用华为` */
43
+ declare const isQuickappHuawei: boolean;
44
+
45
+ /** Detect if `VUE_APP_DARK_MODE` environment variable is set */
46
+ declare const hasDarkMode: boolean;
47
+ /** Detect if `SOURCEMAP` environment variable is set */
48
+ declare const hasSourcemap: boolean;
49
+ /** Detect if `UNI_MP_PLUGIN` environment variable is set */
50
+ declare const isMpPlugin: boolean;
51
+ /** Detect if `UNI_MINIMIZE` environment variable is set */
52
+ declare const isMinimize: boolean;
53
+ /** Detect if `UNI_SSR_CLIENT` environment variable is set */
54
+ declare const isSSRClient: boolean;
55
+ /** Detect if `UNI_SSR_SERVER` environment variable is set */
56
+ declare const isSSRServer: boolean;
57
+
58
+ /** Value of `process.env.UNI_COMPILER` */
59
+ declare const compiler: "vue" | "nvue";
60
+ /** Value of `process.env.UNI_NVUE_COMPILER` */
61
+ declare const nvueCompiler: "vue" | "uni-app" | undefined;
62
+ /** Value of `process.env.UNI_NVUE_STYLE_COMPILER` */
63
+ declare const nvueStyleCompiler: "uni-app" | undefined;
64
+ /** Value of `process.env.UNI_COMPILER_VERSION` */
65
+ declare const compilerVersion: string;
66
+ /** Value of `process.env.UNI_COMPILER_VERSION_TYPE` */
67
+ declare const compilerVersionType: "a" | "r";
68
+
69
+ /** Value of `process.env.UNI_CLI_CONTEXT` */
70
+ declare const cliContext: string;
71
+ /** Value of `process.env.UNI_INPUT_DIR` */
72
+ declare const inputDir: string;
73
+ /** Value of `process.env.UNI_OUTPUT_DIR` */
74
+ declare const outputDir: string;
75
+ /** Value of `process.env.STAT_TITLE_JSON` */
76
+ declare const statTitleJson: Record<string, string>;
77
+ /** Value of `process.env.UNI_CUSTOM_CONTEXT` */
78
+ declare const customContext: string | undefined;
79
+ /** Value of `process.env.UNI_CUSTOM_SCRIPT` */
80
+ declare const customScript: string | undefined;
81
+ /** Value of `process.env.UNI_CUSTOM_DEFINE` */
82
+ declare const customDefine: string | undefined;
83
+ /** Value of `process.env.UNI_SUBPACKAGE` */
84
+ declare const subpackage: string | undefined;
85
+ /** Value of `process.env.UNI_RENDERER` */
86
+ declare const renderer: "native" | undefined;
87
+ /** Value of `process.env.UNI_RENDERER_NATIVE` */
88
+ declare const rendererNative: "appService" | "pages" | undefined;
89
+
90
+ export { type AppPlatform, type BuiltInPlatForm, type SubPlatform, type UtsPlatform, appPlatform, builtInPlatforms, cliContext, compiler, compilerVersion, compilerVersionType, customContext, customDefine, customScript, hasDarkMode, hasSourcemap, inputDir, isApp, isAppAndroid, isAppIOS, isH5, isMinimize, isMp, isMpAlipay, isMpBaidu, isMpKuaishou, isMpPlugin, isMpQQ, isMpToutiao, isMpWeixin, isQuickapp, isQuickappHuawei, isQuickappUnion, isSSRClient, isSSRServer, nvueCompiler, nvueStyleCompiler, outputDir, platform, renderer, rendererNative, statTitleJson, subPlatform, subpackage, utsPlatform };
@@ -0,0 +1,90 @@
1
+ declare const builtInPlatforms: readonly ["app", "app-plus", "h5", "mp-360", "mp-alipay", "mp-baidu", "mp-jd", "mp-kuaishou", "mp-lark", "mp-qq", "mp-toutiao", "mp-weixin", "quickapp-webview", "quickapp-webview-huawei", "quickapp-webview-union"];
2
+
3
+ type BuiltInPlatForm = typeof builtInPlatforms[number];
4
+ type UtsPlatform = BuiltInPlatForm | 'app-android' | 'app-ios' | 'web';
5
+ type AppPlatform = 'android' | 'ios' | undefined;
6
+ type SubPlatform = 'quickapp-webview-huawei' | 'quickapp-webview-union' | undefined;
7
+
8
+ /** Value of `process.env.UNI_PLATFORM` */
9
+ declare const platform: "app" | "app-plus" | "h5" | "mp-360" | "mp-alipay" | "mp-baidu" | "mp-jd" | "mp-kuaishou" | "mp-lark" | "mp-qq" | "mp-toutiao" | "mp-weixin" | "quickapp-webview" | "quickapp-webview-huawei" | "quickapp-webview-union";
10
+ /** Value of `process.env.UNI_UTS_PLATFORM` */
11
+ declare const utsPlatform: UtsPlatform;
12
+ /** Value of `process.env.UNI_APP_PLATFORM` */
13
+ declare const appPlatform: AppPlatform;
14
+ /** Value of `process.env.UNI_SUB_PLATFORM` */
15
+ declare const subPlatform: SubPlatform;
16
+ /** Detect if `process.env.UNI_PLATFORM` is `H5` */
17
+ declare const isH5: boolean;
18
+ /** Detect if `process.env.UNI_PLATFORM` is `APP` */
19
+ declare const isApp: boolean;
20
+ /** Detect if `process.env.UNI_APP_PLATFORM` is `android` or if `process.env.UNI_UTS_PLATFORM` is "app-android" */
21
+ declare const isAppAndroid: boolean;
22
+ /** Detect if `process.env.UNI_APP_PLATFORM` is `ios` or if `process.env.UNI_UTS_PLATFORM` is "app-ios" */
23
+ declare const isAppIOS: boolean;
24
+ /** Detect if `process.env.UNI_PLATFORM` is `小程序` */
25
+ declare const isMp: boolean;
26
+ /** Detect if `process.env.UNI_PLATFORM` is `微信小程序` */
27
+ declare const isMpWeixin: boolean;
28
+ /** Detect if `process.env.UNI_PLATFORM` is `支付宝小程序` */
29
+ declare const isMpAlipay: boolean;
30
+ /** Detect if `process.env.UNI_PLATFORM` is `百度小程序` */
31
+ declare const isMpBaidu: boolean;
32
+ /** Detect if `process.env.UNI_PLATFORM` is `快手小程序` */
33
+ declare const isMpKuaishou: boolean;
34
+ /** Detect if `process.env.UNI_PLATFORM` is `QQ小程序` */
35
+ declare const isMpQQ: boolean;
36
+ /** Detect if `process.env.UNI_PLATFORM` is `头条小程序` */
37
+ declare const isMpToutiao: boolean;
38
+ /** Detect if `process.env.UNI_PLATFORM` is `快应用` */
39
+ declare const isQuickapp: boolean;
40
+ /** Detect if `process.env.UNI_PLATFORM` is `快应用联盟` */
41
+ declare const isQuickappUnion: boolean;
42
+ /** Detect if `process.env.UNI_PLATFORM` is `快应用华为` */
43
+ declare const isQuickappHuawei: boolean;
44
+
45
+ /** Detect if `VUE_APP_DARK_MODE` environment variable is set */
46
+ declare const hasDarkMode: boolean;
47
+ /** Detect if `SOURCEMAP` environment variable is set */
48
+ declare const hasSourcemap: boolean;
49
+ /** Detect if `UNI_MP_PLUGIN` environment variable is set */
50
+ declare const isMpPlugin: boolean;
51
+ /** Detect if `UNI_MINIMIZE` environment variable is set */
52
+ declare const isMinimize: boolean;
53
+ /** Detect if `UNI_SSR_CLIENT` environment variable is set */
54
+ declare const isSSRClient: boolean;
55
+ /** Detect if `UNI_SSR_SERVER` environment variable is set */
56
+ declare const isSSRServer: boolean;
57
+
58
+ /** Value of `process.env.UNI_COMPILER` */
59
+ declare const compiler: "vue" | "nvue";
60
+ /** Value of `process.env.UNI_NVUE_COMPILER` */
61
+ declare const nvueCompiler: "vue" | "uni-app" | undefined;
62
+ /** Value of `process.env.UNI_NVUE_STYLE_COMPILER` */
63
+ declare const nvueStyleCompiler: "uni-app" | undefined;
64
+ /** Value of `process.env.UNI_COMPILER_VERSION` */
65
+ declare const compilerVersion: string;
66
+ /** Value of `process.env.UNI_COMPILER_VERSION_TYPE` */
67
+ declare const compilerVersionType: "a" | "r";
68
+
69
+ /** Value of `process.env.UNI_CLI_CONTEXT` */
70
+ declare const cliContext: string;
71
+ /** Value of `process.env.UNI_INPUT_DIR` */
72
+ declare const inputDir: string;
73
+ /** Value of `process.env.UNI_OUTPUT_DIR` */
74
+ declare const outputDir: string;
75
+ /** Value of `process.env.STAT_TITLE_JSON` */
76
+ declare const statTitleJson: Record<string, string>;
77
+ /** Value of `process.env.UNI_CUSTOM_CONTEXT` */
78
+ declare const customContext: string | undefined;
79
+ /** Value of `process.env.UNI_CUSTOM_SCRIPT` */
80
+ declare const customScript: string | undefined;
81
+ /** Value of `process.env.UNI_CUSTOM_DEFINE` */
82
+ declare const customDefine: string | undefined;
83
+ /** Value of `process.env.UNI_SUBPACKAGE` */
84
+ declare const subpackage: string | undefined;
85
+ /** Value of `process.env.UNI_RENDERER` */
86
+ declare const renderer: "native" | undefined;
87
+ /** Value of `process.env.UNI_RENDERER_NATIVE` */
88
+ declare const rendererNative: "appService" | "pages" | undefined;
89
+
90
+ export { type AppPlatform, type BuiltInPlatForm, type SubPlatform, type UtsPlatform, appPlatform, builtInPlatforms, cliContext, compiler, compilerVersion, compilerVersionType, customContext, customDefine, customScript, hasDarkMode, hasSourcemap, inputDir, isApp, isAppAndroid, isAppIOS, isH5, isMinimize, isMp, isMpAlipay, isMpBaidu, isMpKuaishou, isMpPlugin, isMpQQ, isMpToutiao, isMpWeixin, isQuickapp, isQuickappHuawei, isQuickappUnion, isSSRClient, isSSRServer, nvueCompiler, nvueStyleCompiler, outputDir, platform, renderer, rendererNative, statTitleJson, subPlatform, subpackage, utsPlatform };
package/dist/index.d.ts CHANGED
@@ -1,22 +1,60 @@
1
- type PLATFORM = "h5" | "app" | "mp-alipay" | "mp-baidu" | "mp-kuaishou" | "mp-lark" | "mp-qq" | "mp-toutiao" | "mp-weixin" | "quickapp-webview" | "quickapp-webview-huawei" | "quickapp-webview-union";
1
+ declare const builtInPlatforms: readonly ["app", "app-plus", "h5", "mp-360", "mp-alipay", "mp-baidu", "mp-jd", "mp-kuaishou", "mp-lark", "mp-qq", "mp-toutiao", "mp-weixin", "quickapp-webview", "quickapp-webview-huawei", "quickapp-webview-union"];
2
+
3
+ type BuiltInPlatForm = typeof builtInPlatforms[number];
4
+ type UtsPlatform = BuiltInPlatForm | 'app-android' | 'app-ios' | 'web';
5
+ type AppPlatform = 'android' | 'ios' | undefined;
6
+ type SubPlatform = 'quickapp-webview-huawei' | 'quickapp-webview-union' | undefined;
7
+
2
8
  /** Value of `process.env.UNI_PLATFORM` */
3
- declare const platform: PLATFORM;
9
+ declare const platform: "app" | "app-plus" | "h5" | "mp-360" | "mp-alipay" | "mp-baidu" | "mp-jd" | "mp-kuaishou" | "mp-lark" | "mp-qq" | "mp-toutiao" | "mp-weixin" | "quickapp-webview" | "quickapp-webview-huawei" | "quickapp-webview-union";
4
10
  /** Value of `process.env.UNI_UTS_PLATFORM` */
5
- declare const utsPlatform: PLATFORM | "app-android" | "app-ios" | "web";
11
+ declare const utsPlatform: UtsPlatform;
6
12
  /** Value of `process.env.UNI_APP_PLATFORM` */
7
- declare const appPlatform: "android" | "ios" | undefined;
13
+ declare const appPlatform: AppPlatform;
8
14
  /** Value of `process.env.UNI_SUB_PLATFORM` */
9
- declare const subPlatform: "quickapp-webview-huawei" | "quickapp-webview-union" | undefined;
10
- /** Value of `process.env.UNI_CLI_CONTEXT` */
11
- declare const cliContext: string;
12
- /** Value of `process.env.UNI_INPUT_DIR` */
13
- declare const inputDir: string;
14
- /** Value of `process.env.UNI_OUTPUT_DIR` */
15
- declare const outputDir: string;
15
+ declare const subPlatform: SubPlatform;
16
+ /** Detect if `process.env.UNI_PLATFORM` is `H5` */
17
+ declare const isH5: boolean;
18
+ /** Detect if `process.env.UNI_PLATFORM` is `APP` */
19
+ declare const isApp: boolean;
20
+ /** Detect if `process.env.UNI_APP_PLATFORM` is `android` or if `process.env.UNI_UTS_PLATFORM` is "app-android" */
21
+ declare const isAppAndroid: boolean;
22
+ /** Detect if `process.env.UNI_APP_PLATFORM` is `ios` or if `process.env.UNI_UTS_PLATFORM` is "app-ios" */
23
+ declare const isAppIOS: boolean;
24
+ /** Detect if `process.env.UNI_PLATFORM` is `小程序` */
25
+ declare const isMp: boolean;
26
+ /** Detect if `process.env.UNI_PLATFORM` is `微信小程序` */
27
+ declare const isMpWeixin: boolean;
28
+ /** Detect if `process.env.UNI_PLATFORM` is `支付宝小程序` */
29
+ declare const isMpAlipay: boolean;
30
+ /** Detect if `process.env.UNI_PLATFORM` is `百度小程序` */
31
+ declare const isMpBaidu: boolean;
32
+ /** Detect if `process.env.UNI_PLATFORM` is `快手小程序` */
33
+ declare const isMpKuaishou: boolean;
34
+ /** Detect if `process.env.UNI_PLATFORM` is `QQ小程序` */
35
+ declare const isMpQQ: boolean;
36
+ /** Detect if `process.env.UNI_PLATFORM` is `头条小程序` */
37
+ declare const isMpToutiao: boolean;
38
+ /** Detect if `process.env.UNI_PLATFORM` is `快应用` */
39
+ declare const isQuickapp: boolean;
40
+ /** Detect if `process.env.UNI_PLATFORM` is `快应用联盟` */
41
+ declare const isQuickappUnion: boolean;
42
+ /** Detect if `process.env.UNI_PLATFORM` is `快应用华为` */
43
+ declare const isQuickappHuawei: boolean;
44
+
16
45
  /** Detect if `VUE_APP_DARK_MODE` environment variable is set */
17
46
  declare const hasDarkMode: boolean;
18
47
  /** Detect if `SOURCEMAP` environment variable is set */
19
48
  declare const hasSourcemap: boolean;
49
+ /** Detect if `UNI_MP_PLUGIN` environment variable is set */
50
+ declare const isMpPlugin: boolean;
51
+ /** Detect if `UNI_MINIMIZE` environment variable is set */
52
+ declare const isMinimize: boolean;
53
+ /** Detect if `UNI_SSR_CLIENT` environment variable is set */
54
+ declare const isSSRClient: boolean;
55
+ /** Detect if `UNI_SSR_SERVER` environment variable is set */
56
+ declare const isSSRServer: boolean;
57
+
20
58
  /** Value of `process.env.UNI_COMPILER` */
21
59
  declare const compiler: "vue" | "nvue";
22
60
  /** Value of `process.env.UNI_NVUE_COMPILER` */
@@ -27,6 +65,13 @@ declare const nvueStyleCompiler: "uni-app" | undefined;
27
65
  declare const compilerVersion: string;
28
66
  /** Value of `process.env.UNI_COMPILER_VERSION_TYPE` */
29
67
  declare const compilerVersionType: "a" | "r";
68
+
69
+ /** Value of `process.env.UNI_CLI_CONTEXT` */
70
+ declare const cliContext: string;
71
+ /** Value of `process.env.UNI_INPUT_DIR` */
72
+ declare const inputDir: string;
73
+ /** Value of `process.env.UNI_OUTPUT_DIR` */
74
+ declare const outputDir: string;
30
75
  /** Value of `process.env.STAT_TITLE_JSON` */
31
76
  declare const statTitleJson: Record<string, string>;
32
77
  /** Value of `process.env.UNI_CUSTOM_CONTEXT` */
@@ -37,45 +82,9 @@ declare const customScript: string | undefined;
37
82
  declare const customDefine: string | undefined;
38
83
  /** Value of `process.env.UNI_SUBPACKAGE` */
39
84
  declare const subpackage: string | undefined;
40
- /** Detect if `UNI_MP_PLUGIN` environment variable is set */
41
- declare const isMpPlugin: boolean;
42
85
  /** Value of `process.env.UNI_RENDERER` */
43
86
  declare const renderer: "native" | undefined;
44
87
  /** Value of `process.env.UNI_RENDERER_NATIVE` */
45
88
  declare const rendererNative: "appService" | "pages" | undefined;
46
- /** Detect if `UNI_MINIMIZE` environment variable is set */
47
- declare const isMinimize: boolean;
48
- /** Detect if `UNI_SSR_CLIENT` environment variable is set */
49
- declare const isSSRClient: boolean;
50
- /** Detect if `UNI_SSR_SERVER` environment variable is set */
51
- declare const isSSRServer: boolean;
52
- /** Detect if `process.env.UNI_PLATFORM` is `H5` */
53
- declare const isH5: boolean;
54
- /** Detect if `process.env.UNI_PLATFORM` is `APP` */
55
- declare const isApp: boolean;
56
- /** Detect if `process.env.UNI_APP_PLATFORM` is `android` or if `process.env.UNI_UTS_PLATFORM` is "app-android" */
57
- declare const isAppAndroid: boolean;
58
- /** Detect if `process.env.UNI_APP_PLATFORM` is `ios` or if `process.env.UNI_UTS_PLATFORM` is "app-ios"*/
59
- declare const isAppIOS: boolean;
60
- /** Detect if `process.env.UNI_PLATFORM` is `小程序` */
61
- declare const isMp: boolean;
62
- /** Detect if `process.env.UNI_PLATFORM` is `微信小程序` */
63
- declare const isMpWeixin: boolean;
64
- /** Detect if `process.env.UNI_PLATFORM` is `支付宝小程序` */
65
- declare const isMpAlipay: boolean;
66
- /** Detect if `process.env.UNI_PLATFORM` is `百度小程序` */
67
- declare const isMpBaidu: boolean;
68
- /** Detect if `process.env.UNI_PLATFORM` is `快手小程序` */
69
- declare const isMpKuaishou: boolean;
70
- /** Detect if `process.env.UNI_PLATFORM` is `QQ小程序` */
71
- declare const isMpQQ: boolean;
72
- /** Detect if `process.env.UNI_PLATFORM` is `头条小程序` */
73
- declare const isMpToutiao: boolean;
74
- /** Detect if `process.env.UNI_PLATFORM` is `快应用` */
75
- declare const isQuickapp: boolean;
76
- /** Detect if `process.env.UNI_PLATFORM` is `快应用联盟` */
77
- declare const isQuickappUnion: boolean;
78
- /** Detect if `process.env.UNI_PLATFORM` is `快应用华为` */
79
- declare const isQuickappHuawei: boolean;
80
89
 
81
- export { appPlatform, cliContext, compiler, compilerVersion, compilerVersionType, customContext, customDefine, customScript, hasDarkMode, hasSourcemap, inputDir, isApp, isAppAndroid, isAppIOS, isH5, isMinimize, isMp, isMpAlipay, isMpBaidu, isMpKuaishou, isMpPlugin, isMpQQ, isMpToutiao, isMpWeixin, isQuickapp, isQuickappHuawei, isQuickappUnion, isSSRClient, isSSRServer, nvueCompiler, nvueStyleCompiler, outputDir, platform, renderer, rendererNative, statTitleJson, subPlatform, subpackage, utsPlatform };
90
+ export { type AppPlatform, type BuiltInPlatForm, type SubPlatform, type UtsPlatform, appPlatform, builtInPlatforms, cliContext, compiler, compilerVersion, compilerVersionType, customContext, customDefine, customScript, hasDarkMode, hasSourcemap, inputDir, isApp, isAppAndroid, isAppIOS, isH5, isMinimize, isMp, isMpAlipay, isMpBaidu, isMpKuaishou, isMpPlugin, isMpQQ, isMpToutiao, isMpWeixin, isQuickapp, isQuickappHuawei, isQuickappUnion, isSSRClient, isSSRServer, nvueCompiler, nvueStyleCompiler, outputDir, platform, renderer, rendererNative, statTitleJson, subPlatform, subpackage, utsPlatform };
package/dist/index.mjs CHANGED
@@ -1,32 +1,27 @@
1
- const processShim = typeof process !== "undefined" ? process : {};
2
- const envShim = processShim.env || {};
3
- const platform = envShim.UNI_PLATFORM;
4
- const utsPlatform = envShim.UNI_UTS_PLATFORM;
5
- const appPlatform = envShim.UNI_APP_PLATFORM;
6
- const subPlatform = envShim.UNI_SUB_PLATFORM;
7
- const cliContext = envShim.UNI_CLI_CONTEXT;
8
- const inputDir = envShim.UNI_INPUT_DIR;
9
- const outputDir = envShim.UNI_OUTPUT_DIR;
10
- const hasDarkMode = toBoolean(envShim.VUE_APP_DARK_MODE);
11
- const hasSourcemap = toBoolean(envShim.SOURCEMAP);
12
- const compiler = envShim.UNI_COMPILER;
13
- const nvueCompiler = envShim.UNI_NVUE_COMPILER;
14
- const nvueStyleCompiler = envShim.UNI_NVUE_STYLE_COMPILER;
15
- const compilerVersion = envShim.UNI_COMPILER_VERSION;
16
- const compilerVersionType = envShim.UNI_COMPILER_VERSION_TYPE;
17
- const statTitleJson = parseJSON(
18
- envShim.STAT_TITLE_JSON
19
- );
20
- const customContext = envShim.UNI_CUSTOM_CONTEXT;
21
- const customScript = envShim.UNI_CUSTOM_SCRIPT;
22
- const customDefine = envShim.UNI_CUSTOM_DEFINE;
23
- const subpackage = envShim.UNI_SUBPACKAGE;
24
- const isMpPlugin = toBoolean(envShim.UNI_MP_PLUGIN);
25
- const renderer = envShim.UNI_RENDERER;
26
- const rendererNative = envShim.UNI_RENDERER_NATIVE;
27
- const isMinimize = toBoolean(envShim.UNI_MINIMIZE);
28
- const isSSRClient = toBoolean(envShim.UNI_SSR_CLIENT);
29
- const isSSRServer = toBoolean(envShim.UNI_SSR_SERVER);
1
+ import { env } from 'std-env';
2
+
3
+ const builtInPlatforms = [
4
+ "app",
5
+ "app-plus",
6
+ "h5",
7
+ "mp-360",
8
+ "mp-alipay",
9
+ "mp-baidu",
10
+ "mp-jd",
11
+ "mp-kuaishou",
12
+ "mp-lark",
13
+ "mp-qq",
14
+ "mp-toutiao",
15
+ "mp-weixin",
16
+ "quickapp-webview",
17
+ "quickapp-webview-huawei",
18
+ "quickapp-webview-union"
19
+ ];
20
+
21
+ const platform = env.UNI_PLATFORM;
22
+ const utsPlatform = env.UNI_UTS_PLATFORM;
23
+ const appPlatform = env.UNI_APP_PLATFORM;
24
+ const subPlatform = env.UNI_SUB_PLATFORM;
30
25
  const isH5 = platform === "h5";
31
26
  const isApp = platform === "app";
32
27
  const isAppAndroid = appPlatform === "android" || utsPlatform === "app-android";
@@ -38,9 +33,10 @@ const isMpBaidu = platform === "mp-baidu";
38
33
  const isMpKuaishou = platform === "mp-kuaishou";
39
34
  const isMpQQ = platform === "mp-qq";
40
35
  const isMpToutiao = platform === "mp-toutiao";
41
- const isQuickapp = /^quickapp--webview/i.test(platform);
36
+ const isQuickapp = /^quickapp-webview/i.test(platform);
42
37
  const isQuickappUnion = platform === "quickapp-webview-union";
43
38
  const isQuickappHuawei = platform === "quickapp-webview-huawei";
39
+
44
40
  function toBoolean(val) {
45
41
  return val ? val !== "false" : false;
46
42
  }
@@ -54,4 +50,30 @@ function parseJSON(val) {
54
50
  return obj;
55
51
  }
56
52
 
57
- export { appPlatform, cliContext, compiler, compilerVersion, compilerVersionType, customContext, customDefine, customScript, hasDarkMode, hasSourcemap, inputDir, isApp, isAppAndroid, isAppIOS, isH5, isMinimize, isMp, isMpAlipay, isMpBaidu, isMpKuaishou, isMpPlugin, isMpQQ, isMpToutiao, isMpWeixin, isQuickapp, isQuickappHuawei, isQuickappUnion, isSSRClient, isSSRServer, nvueCompiler, nvueStyleCompiler, outputDir, platform, renderer, rendererNative, statTitleJson, subPlatform, subpackage, utsPlatform };
53
+ const hasDarkMode = toBoolean(env.VUE_APP_DARK_MODE);
54
+ const hasSourcemap = toBoolean(env.SOURCEMAP);
55
+ const isMpPlugin = toBoolean(env.UNI_MP_PLUGIN);
56
+ const isMinimize = toBoolean(env.UNI_MINIMIZE);
57
+ const isSSRClient = toBoolean(env.UNI_SSR_CLIENT);
58
+ const isSSRServer = toBoolean(env.UNI_SSR_SERVER);
59
+
60
+ const compiler = env.UNI_COMPILER;
61
+ const nvueCompiler = env.UNI_NVUE_COMPILER;
62
+ const nvueStyleCompiler = env.UNI_NVUE_STYLE_COMPILER;
63
+ const compilerVersion = env.UNI_COMPILER_VERSION;
64
+ const compilerVersionType = env.UNI_COMPILER_VERSION_TYPE;
65
+
66
+ const cliContext = env.UNI_CLI_CONTEXT;
67
+ const inputDir = env.UNI_INPUT_DIR;
68
+ const outputDir = env.UNI_OUTPUT_DIR;
69
+ const statTitleJson = parseJSON(
70
+ env.STAT_TITLE_JSON
71
+ );
72
+ const customContext = env.UNI_CUSTOM_CONTEXT;
73
+ const customScript = env.UNI_CUSTOM_SCRIPT;
74
+ const customDefine = env.UNI_CUSTOM_DEFINE;
75
+ const subpackage = env.UNI_SUBPACKAGE;
76
+ const renderer = env.UNI_RENDERER;
77
+ const rendererNative = env.UNI_RENDERER_NATIVE;
78
+
79
+ export { appPlatform, builtInPlatforms, cliContext, compiler, compilerVersion, compilerVersionType, customContext, customDefine, customScript, hasDarkMode, hasSourcemap, inputDir, isApp, isAppAndroid, isAppIOS, isH5, isMinimize, isMp, isMpAlipay, isMpBaidu, isMpKuaishou, isMpPlugin, isMpQQ, isMpToutiao, isMpWeixin, isQuickapp, isQuickappHuawei, isQuickappUnion, isSSRClient, isSSRServer, nvueCompiler, nvueStyleCompiler, outputDir, platform, renderer, rendererNative, statTitleJson, subPlatform, subpackage, utsPlatform };
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "@uni-helper/uni-env",
3
3
  "type": "module",
4
- "version": "0.0.3",
5
- "packageManager": "pnpm@8.1.1",
4
+ "version": "0.1.1",
5
+ "packageManager": "pnpm@8.9.2",
6
6
  "description": "",
7
7
  "author": "KeJun",
8
8
  "license": "MIT",
@@ -12,41 +12,48 @@
12
12
  "url": "git+https://github.com/uni-helper/uni-env.git"
13
13
  },
14
14
  "bugs": "https://github.com/uni-helper/uni-env/issues",
15
- "keywords": [],
15
+ "keywords": [
16
+ "uni-app",
17
+ "env"
18
+ ],
16
19
  "sideEffects": false,
17
20
  "exports": {
18
21
  ".": {
19
- "types": "./dist/index.d.ts",
20
- "require": "./dist/index.cjs",
21
- "import": "./dist/index.mjs"
22
+ "import": {
23
+ "types": "./dist/index.d.mts",
24
+ "default": "./dist/index.mjs"
25
+ },
26
+ "require": {
27
+ "types": "./dist/index.d.cts",
28
+ "default": "./dist/index.cjs"
29
+ }
22
30
  }
23
31
  },
24
- "main": "./dist/index.mjs",
32
+ "main": "./dist/index.cjs",
25
33
  "module": "./dist/index.mjs",
26
34
  "types": "./dist/index.d.ts",
27
- "typesVersions": {
28
- "*": {
29
- "*": [
30
- "./dist/*",
31
- "./dist/index.d.ts"
32
- ]
33
- }
34
- },
35
35
  "files": [
36
36
  "dist"
37
37
  ],
38
+ "dependencies": {
39
+ "@antfu/eslint-config": "1.0.0-beta.27",
40
+ "eslint": "^8.51.0",
41
+ "std-env": "^3.4.3"
42
+ },
38
43
  "devDependencies": {
39
- "@types/node": "^18.15.11",
40
- "bumpp": "^9.1.0",
41
- "esno": "^0.16.3",
42
- "typescript": "^5.0.4",
43
- "unbuild": "^1.2.1",
44
- "vitest": "^0.30.1"
44
+ "@types/node": "^20.8.6",
45
+ "bumpp": "^9.2.0",
46
+ "esno": "^0.17.0",
47
+ "typescript": "^5.2.2",
48
+ "unbuild": "^2.0.0",
49
+ "vitest": "^0.34.6"
45
50
  },
46
51
  "scripts": {
47
52
  "build": "unbuild",
48
53
  "dev": "unbuild --stub",
49
54
  "release": "bumpp",
50
- "start": "esno src/index.ts"
55
+ "start": "esno src/index.ts",
56
+ "lint": "eslint .",
57
+ "lint:fix": "eslint . --fix"
51
58
  }
52
59
  }