@uni-helper/uni-env 0.0.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/LICENSE +21 -0
- package/README.md +32 -0
- package/dist/index.cjs +79 -0
- package/dist/index.d.ts +63 -0
- package/dist/index.mjs +48 -0
- package/package.json +52 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2022 KeJun <https://github.com/kejunmao>
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# @uni-helper/uni-env
|
|
2
|
+
|
|
3
|
+
> 检测当前 uni-app 的环境变量
|
|
4
|
+
|
|
5
|
+
## 安装
|
|
6
|
+
|
|
7
|
+
```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
|
+
pnpm i @uni-helper/uni-env
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## 使用
|
|
19
|
+
|
|
20
|
+
```js
|
|
21
|
+
// ESM
|
|
22
|
+
import { isMpWeixin } from "@uni-helper/uni-env";
|
|
23
|
+
|
|
24
|
+
// CommonJS
|
|
25
|
+
const { isMp } = require("@uni-helper/uni-env");
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
你可以从 [./src/index.ts](./src/index.ts) 中查看更多标志以及如何判断的。
|
|
29
|
+
|
|
30
|
+
## 协议
|
|
31
|
+
|
|
32
|
+
[MIT](./LICENSE)
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
'use strict';
|
|
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);
|
|
32
|
+
const isH5 = platform === "h5";
|
|
33
|
+
const isApp = platform === "app";
|
|
34
|
+
const isMp = /^mp-/i.test(platform);
|
|
35
|
+
const isMpWeixin = platform === "mp-weixin";
|
|
36
|
+
const isMpAlipay = platform === "mp-alipay";
|
|
37
|
+
function toBoolean(val) {
|
|
38
|
+
return val ? val !== "false" : false;
|
|
39
|
+
}
|
|
40
|
+
function parseJSON(val) {
|
|
41
|
+
let obj;
|
|
42
|
+
try {
|
|
43
|
+
obj = JSON.parse(val || "{}");
|
|
44
|
+
} catch (error) {
|
|
45
|
+
obj = {};
|
|
46
|
+
}
|
|
47
|
+
return obj;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
exports.appPlatform = appPlatform;
|
|
51
|
+
exports.cliContext = cliContext;
|
|
52
|
+
exports.compiler = compiler;
|
|
53
|
+
exports.compilerVersion = compilerVersion;
|
|
54
|
+
exports.compilerVersionType = compilerVersionType;
|
|
55
|
+
exports.customContext = customContext;
|
|
56
|
+
exports.customDefine = customDefine;
|
|
57
|
+
exports.customScript = customScript;
|
|
58
|
+
exports.hasDarkMode = hasDarkMode;
|
|
59
|
+
exports.hasSourcemap = hasSourcemap;
|
|
60
|
+
exports.inputDir = inputDir;
|
|
61
|
+
exports.isApp = isApp;
|
|
62
|
+
exports.isH5 = isH5;
|
|
63
|
+
exports.isMinimize = isMinimize;
|
|
64
|
+
exports.isMp = isMp;
|
|
65
|
+
exports.isMpAlipay = isMpAlipay;
|
|
66
|
+
exports.isMpPlugin = isMpPlugin;
|
|
67
|
+
exports.isMpWeixin = isMpWeixin;
|
|
68
|
+
exports.isSSRClient = isSSRClient;
|
|
69
|
+
exports.isSSRServer = isSSRServer;
|
|
70
|
+
exports.nvueCompiler = nvueCompiler;
|
|
71
|
+
exports.nvueStyleCompiler = nvueStyleCompiler;
|
|
72
|
+
exports.outputDir = outputDir;
|
|
73
|
+
exports.platform = platform;
|
|
74
|
+
exports.renderer = renderer;
|
|
75
|
+
exports.rendererNative = rendererNative;
|
|
76
|
+
exports.statTitleJson = statTitleJson;
|
|
77
|
+
exports.subPlatform = subPlatform;
|
|
78
|
+
exports.subpackage = subpackage;
|
|
79
|
+
exports.utsPlatform = utsPlatform;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
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";
|
|
2
|
+
/** Value of `process.env.UNI_PLATFORM` */
|
|
3
|
+
declare const platform: PLATFORM;
|
|
4
|
+
/** Value of `process.env.UNI_UTS_PLATFORM` */
|
|
5
|
+
declare const utsPlatform: PLATFORM | "app-android" | "app-ios" | "web";
|
|
6
|
+
/** Value of `process.env.UNI_APP_PLATFORM` */
|
|
7
|
+
declare const appPlatform: "android" | "ios" | undefined;
|
|
8
|
+
/** 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;
|
|
16
|
+
/** Detect if `VUE_APP_DARK_MODE` environment variable is set */
|
|
17
|
+
declare const hasDarkMode: boolean;
|
|
18
|
+
/** Detect if `SOURCEMAP` environment variable is set */
|
|
19
|
+
declare const hasSourcemap: boolean;
|
|
20
|
+
/** Value of `process.env.UNI_COMPILER` */
|
|
21
|
+
declare const compiler: "vue" | "nvue";
|
|
22
|
+
/** Value of `process.env.UNI_NVUE_COMPILER` */
|
|
23
|
+
declare const nvueCompiler: "vue" | "uni-app" | undefined;
|
|
24
|
+
/** Value of `process.env.UNI_NVUE_STYLE_COMPILER` */
|
|
25
|
+
declare const nvueStyleCompiler: "uni-app" | undefined;
|
|
26
|
+
/** Value of `process.env.UNI_COMPILER_VERSION` */
|
|
27
|
+
declare const compilerVersion: string;
|
|
28
|
+
/** Value of `process.env.UNI_COMPILER_VERSION_TYPE` */
|
|
29
|
+
declare const compilerVersionType: "a" | "r";
|
|
30
|
+
/** Value of `process.env.STAT_TITLE_JSON` */
|
|
31
|
+
declare const statTitleJson: Record<string, string>;
|
|
32
|
+
/** Value of `process.env.UNI_CUSTOM_CONTEXT` */
|
|
33
|
+
declare const customContext: string | undefined;
|
|
34
|
+
/** Value of `process.env.UNI_CUSTOM_SCRIPT` */
|
|
35
|
+
declare const customScript: string | undefined;
|
|
36
|
+
/** Value of `process.env.UNI_CUSTOM_DEFINE` */
|
|
37
|
+
declare const customDefine: string | undefined;
|
|
38
|
+
/** Value of `process.env.UNI_SUBPACKAGE` */
|
|
39
|
+
declare const subpackage: string | undefined;
|
|
40
|
+
/** Detect if `UNI_MP_PLUGIN` environment variable is set */
|
|
41
|
+
declare const isMpPlugin: boolean;
|
|
42
|
+
/** Value of `process.env.UNI_RENDERER` */
|
|
43
|
+
declare const renderer: "native" | undefined;
|
|
44
|
+
/** Value of `process.env.UNI_RENDERER_NATIVE` */
|
|
45
|
+
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 H5 */
|
|
55
|
+
declare const isApp: boolean;
|
|
56
|
+
/** Detect if `process.env.UNI_PLATFORM` is 小程序 */
|
|
57
|
+
declare const isMp: boolean;
|
|
58
|
+
/** Detect if `process.env.UNI_PLATFORM` is 微信小程序 */
|
|
59
|
+
declare const isMpWeixin: boolean;
|
|
60
|
+
/** Detect if `process.env.UNI_PLATFORM` is 支付宝小程序 */
|
|
61
|
+
declare const isMpAlipay: boolean;
|
|
62
|
+
|
|
63
|
+
export { appPlatform, cliContext, compiler, compilerVersion, compilerVersionType, customContext, customDefine, customScript, hasDarkMode, hasSourcemap, inputDir, isApp, isH5, isMinimize, isMp, isMpAlipay, isMpPlugin, isMpWeixin, isSSRClient, isSSRServer, nvueCompiler, nvueStyleCompiler, outputDir, platform, renderer, rendererNative, statTitleJson, subPlatform, subpackage, utsPlatform };
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
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);
|
|
30
|
+
const isH5 = platform === "h5";
|
|
31
|
+
const isApp = platform === "app";
|
|
32
|
+
const isMp = /^mp-/i.test(platform);
|
|
33
|
+
const isMpWeixin = platform === "mp-weixin";
|
|
34
|
+
const isMpAlipay = platform === "mp-alipay";
|
|
35
|
+
function toBoolean(val) {
|
|
36
|
+
return val ? val !== "false" : false;
|
|
37
|
+
}
|
|
38
|
+
function parseJSON(val) {
|
|
39
|
+
let obj;
|
|
40
|
+
try {
|
|
41
|
+
obj = JSON.parse(val || "{}");
|
|
42
|
+
} catch (error) {
|
|
43
|
+
obj = {};
|
|
44
|
+
}
|
|
45
|
+
return obj;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export { appPlatform, cliContext, compiler, compilerVersion, compilerVersionType, customContext, customDefine, customScript, hasDarkMode, hasSourcemap, inputDir, isApp, isH5, isMinimize, isMp, isMpAlipay, isMpPlugin, isMpWeixin, isSSRClient, isSSRServer, nvueCompiler, nvueStyleCompiler, outputDir, platform, renderer, rendererNative, statTitleJson, subPlatform, subpackage, utsPlatform };
|
package/package.json
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@uni-helper/uni-env",
|
|
3
|
+
"type": "module",
|
|
4
|
+
"version": "0.0.1",
|
|
5
|
+
"packageManager": "pnpm@8.1.1",
|
|
6
|
+
"description": "",
|
|
7
|
+
"author": "KeJun",
|
|
8
|
+
"license": "MIT",
|
|
9
|
+
"homepage": "https://github.com/kejunmao/@uni-helper/uni-env#readme",
|
|
10
|
+
"repository": {
|
|
11
|
+
"type": "git",
|
|
12
|
+
"url": "git+https://github.com/kejunmao/@uni-helper/uni-env.git"
|
|
13
|
+
},
|
|
14
|
+
"bugs": "https://github.com/kejunmao/@uni-helper/uni-env/issues",
|
|
15
|
+
"keywords": [],
|
|
16
|
+
"sideEffects": false,
|
|
17
|
+
"exports": {
|
|
18
|
+
".": {
|
|
19
|
+
"types": "./dist/index.d.ts",
|
|
20
|
+
"require": "./dist/index.cjs",
|
|
21
|
+
"import": "./dist/index.mjs"
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
"main": "./dist/index.mjs",
|
|
25
|
+
"module": "./dist/index.mjs",
|
|
26
|
+
"types": "./dist/index.d.ts",
|
|
27
|
+
"typesVersions": {
|
|
28
|
+
"*": {
|
|
29
|
+
"*": [
|
|
30
|
+
"./dist/*",
|
|
31
|
+
"./dist/index.d.ts"
|
|
32
|
+
]
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
"files": [
|
|
36
|
+
"dist"
|
|
37
|
+
],
|
|
38
|
+
"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"
|
|
45
|
+
},
|
|
46
|
+
"scripts": {
|
|
47
|
+
"build": "unbuild",
|
|
48
|
+
"dev": "unbuild --stub",
|
|
49
|
+
"release": "bumpp",
|
|
50
|
+
"start": "esno src/index.ts"
|
|
51
|
+
}
|
|
52
|
+
}
|