@uni-helper/uni-env 0.1.0 → 0.1.2

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
 
@@ -25,14 +24,17 @@ import { isMpWeixin } from '@uni-helper/uni-env'
25
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
@@ -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
@@ -87,4 +87,4 @@ declare const renderer: "native" | undefined;
87
87
  /** Value of `process.env.UNI_RENDERER_NATIVE` */
88
88
  declare const rendererNative: "appService" | "pages" | undefined;
89
89
 
90
- export { AppPlatform, BuiltInPlatForm, SubPlatform, 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 };
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/package.json CHANGED
@@ -1,8 +1,7 @@
1
1
  {
2
2
  "name": "@uni-helper/uni-env",
3
3
  "type": "module",
4
- "version": "0.1.0",
5
- "packageManager": "pnpm@8.9.0",
4
+ "version": "0.1.2",
6
5
  "description": "",
7
6
  "author": "KeJun",
8
7
  "license": "MIT",
@@ -12,41 +11,41 @@
12
11
  "url": "git+https://github.com/uni-helper/uni-env.git"
13
12
  },
14
13
  "bugs": "https://github.com/uni-helper/uni-env/issues",
15
- "keywords": [],
14
+ "keywords": [
15
+ "uni-app",
16
+ "env"
17
+ ],
16
18
  "sideEffects": false,
17
19
  "exports": {
18
20
  ".": {
19
- "types": "./dist/index.d.ts",
20
- "import": "./dist/index.mjs",
21
- "require": "./dist/index.cjs"
21
+ "import": {
22
+ "types": "./dist/index.d.mts",
23
+ "default": "./dist/index.mjs"
24
+ },
25
+ "require": {
26
+ "types": "./dist/index.d.cts",
27
+ "default": "./dist/index.cjs"
28
+ }
22
29
  }
23
30
  },
24
- "main": "./dist/index.mjs",
31
+ "main": "./dist/index.cjs",
25
32
  "module": "./dist/index.mjs",
26
33
  "types": "./dist/index.d.ts",
27
- "typesVersions": {
28
- "*": {
29
- "*": [
30
- "./dist/*",
31
- "./dist/index.d.ts"
32
- ]
33
- }
34
- },
35
34
  "files": [
36
35
  "dist"
37
36
  ],
38
37
  "dependencies": {
39
- "@antfu/eslint-config": "1.0.0-beta.27",
40
- "eslint": "^8.51.0",
41
- "std-env": "^3.4.3"
38
+ "std-env": "^3.7.0"
42
39
  },
43
40
  "devDependencies": {
44
- "@types/node": "^18.18.5",
45
- "bumpp": "^9.2.0",
46
- "esno": "^0.16.3",
47
- "typescript": "^5.2.2",
48
- "unbuild": "^1.2.1",
49
- "vitest": "^0.32.4"
41
+ "@antfu/eslint-config": "^2.18.1",
42
+ "@types/node": "^20.12.12",
43
+ "bumpp": "^9.4.1",
44
+ "eslint": "^8.57.0",
45
+ "esno": "^4.7.0",
46
+ "typescript": "^5.4.5",
47
+ "unbuild": "^2.0.0",
48
+ "vitest": "^1.6.0"
50
49
  },
51
50
  "scripts": {
52
51
  "build": "unbuild",
@@ -54,6 +53,7 @@
54
53
  "release": "bumpp",
55
54
  "start": "esno src/index.ts",
56
55
  "lint": "eslint .",
57
- "lint:fix": "eslint . --fix"
56
+ "lint:fix": "eslint . --fix",
57
+ "test": "vitest run"
58
58
  }
59
59
  }