miniprogram-platform 0.0.1-beta → 1.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/README.md +105 -0
- package/dist/cjs/index.js +29 -4
- package/dist/esm/index.js +30 -1
- package/dist/index.d.ts +6 -3
- package/dist/miniprogram-platform.cjs.js +32 -0
- package/dist/miniprogram-platform.cjs.min.js +1 -0
- package/dist/miniprogram-platform.esm.js +30 -0
- package/dist/miniprogram-platform.esm.min.js +1 -0
- package/package.json +41 -30
- package/dist/cjs/platform.js +0 -23
- package/dist/esm/platform.js +0 -21
package/README.md
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
# miniprogram-platform
|
|
2
|
+
|
|
3
|
+
零依赖、极简的跨小程序平台检测工具。将各平台特有的全局变量(`wx`、`my`、`tt` 等)统一抽象为 `{ mp, name }`,方便跨小程序库的开发。
|
|
4
|
+
|
|
5
|
+
## 安装
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install miniprogram-platform
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## 使用
|
|
12
|
+
|
|
13
|
+
```js
|
|
14
|
+
import { getPlatform } from "miniprogram-platform";
|
|
15
|
+
|
|
16
|
+
const { mp, name } = getPlatform() || {};
|
|
17
|
+
|
|
18
|
+
if (mp) {
|
|
19
|
+
console.log(name); // "WeChat" | "Alipay" | "ByteDance" | ...
|
|
20
|
+
mp.request({ url: "https://api.example.com/data" });
|
|
21
|
+
}
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
> **注意**:`getPlatform()` 在首次调用时完成检测并缓存结果,后续调用均为 O(1)。
|
|
25
|
+
|
|
26
|
+
TypeScript 中可将 `mp` 断言为目标平台类型以获得完整的类型提示:
|
|
27
|
+
|
|
28
|
+
```ts
|
|
29
|
+
if (platform?.name === "WeChat") {
|
|
30
|
+
const wx = platform.mp as typeof wx;
|
|
31
|
+
wx.login({ ... }); // 完整的类型推断与补全
|
|
32
|
+
}
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
JavaScript 中可通过 JSDoc 达到同样效果:
|
|
36
|
+
|
|
37
|
+
```js
|
|
38
|
+
if (platform?.name === "WeChat") {
|
|
39
|
+
/** @type {typeof wx} */
|
|
40
|
+
const wx = platform.mp;
|
|
41
|
+
wx.login({ ... }); // VSCode 中同样有类型提示
|
|
42
|
+
}
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## API
|
|
46
|
+
|
|
47
|
+
### `getPlatform()`
|
|
48
|
+
|
|
49
|
+
返回当前运行环境的平台信息,若不在任何小程序环境中则返回 `undefined`。
|
|
50
|
+
|
|
51
|
+
```ts
|
|
52
|
+
function getPlatform(): { mp: unknown; name: string } | undefined;
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
| 属性 | 类型 | 说明 |
|
|
56
|
+
| ------ | --------- | ------------------------------------------- |
|
|
57
|
+
| `mp` | `unknown` | 平台全局 API 对象(如 `wx`、`my`、`tt` 等) |
|
|
58
|
+
| `name` | `string` | 平台名称 |
|
|
59
|
+
|
|
60
|
+
## 支持的平台
|
|
61
|
+
|
|
62
|
+
| 平台名称 | 全局对象 | 说明 |
|
|
63
|
+
| ----------- | -------- | ----------------- |
|
|
64
|
+
| WeChat | `wx` | 微信小程序 |
|
|
65
|
+
| Alipay | `my` | 支付宝小程序 |
|
|
66
|
+
| QQ | `qq` | QQ 小程序 |
|
|
67
|
+
| JD | `jd` | 京东小程序 |
|
|
68
|
+
| Baidu | `swan` | 百度智能小程序 |
|
|
69
|
+
| ByteDance | `tt` | 抖音 / 飞书小程序 |
|
|
70
|
+
| Kwai | `ks` | 快手小程序 |
|
|
71
|
+
| Qihu | `qh` | 360 小程序 |
|
|
72
|
+
| RedNote | `xhs` | 小红书小程序 |
|
|
73
|
+
| DingTalk | `dd` | 钉钉小程序 |
|
|
74
|
+
| BiliBili | `bl` | 哔哩哔哩小程序 |
|
|
75
|
+
| FinClip | `ft` | 泰坪小程序 |
|
|
76
|
+
| HarmonyASCF | `has` | 鸿蒙元服务 |
|
|
77
|
+
| UniApp | `uni` | UniApp 跨端框架 |
|
|
78
|
+
| Taro | `Taro` | Taro 跨端框架 |
|
|
79
|
+
|
|
80
|
+
检测逻辑:按优先级依次检查各平台的全局对象是否存在,并验证该对象是否具有 `request` 方法(钉钉例外,其请求 API 为 `httpRequest`)。
|
|
81
|
+
匹配到第一个即返回,若全部未匹配则返回 `undefined`。
|
|
82
|
+
|
|
83
|
+
## License
|
|
84
|
+
|
|
85
|
+
MIT License
|
|
86
|
+
|
|
87
|
+
Copyright (c) 2026
|
|
88
|
+
|
|
89
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
90
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
91
|
+
in the Software without restriction, including without limitation the rights
|
|
92
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
93
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
94
|
+
furnished to do so, subject to the following conditions:
|
|
95
|
+
|
|
96
|
+
The above copyright notice and this permission notice shall be included in all
|
|
97
|
+
copies or substantial portions of the Software.
|
|
98
|
+
|
|
99
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
100
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
101
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
102
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
103
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
104
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
105
|
+
SOFTWARE.
|
package/dist/cjs/index.js
CHANGED
|
@@ -1,7 +1,32 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
// @ts-nocheck
|
|
4
|
+
const platform = { value: null };
|
|
5
|
+
function isRequestExists(mp) {
|
|
6
|
+
return !!mp && typeof mp === "object" && typeof (mp === null || mp === void 0 ? void 0 : mp["request"]) === "function";
|
|
7
|
+
}
|
|
8
|
+
function getPlatform() {
|
|
9
|
+
if (platform.value !== null)
|
|
10
|
+
return platform.value;
|
|
11
|
+
const u = "undefined";
|
|
12
|
+
platform.value =
|
|
13
|
+
(typeof wx !== u && isRequestExists(wx) && { mp: wx, name: "WeChat" }) || // 微信
|
|
14
|
+
(typeof my !== u && isRequestExists(my) && { mp: my, name: "Alipay" }) || // 支付宝
|
|
15
|
+
(typeof qq !== u && isRequestExists(qq) && { mp: qq, name: "QQ" }) || // QQ
|
|
16
|
+
(typeof jd !== u && isRequestExists(jd) && { mp: jd, name: "JD" }) || // 京东
|
|
17
|
+
(typeof swan !== u && isRequestExists(swan) && { mp: swan, name: "Baidu" }) || // 百度
|
|
18
|
+
(typeof tt !== u && isRequestExists(tt) && { mp: tt, name: "ByteDance" }) || // 抖音 | 飞书
|
|
19
|
+
(typeof ks !== u && isRequestExists(ks) && { mp: ks, name: "Kwai" }) || // 快手
|
|
20
|
+
(typeof qh !== u && isRequestExists(qh) && { mp: qh, name: "Qihu" }) || // 360
|
|
21
|
+
(typeof xhs !== u && isRequestExists(xhs) && { mp: xhs, name: "RedNote" }) || // 小红书
|
|
22
|
+
(typeof dd !== u && (isRequestExists(dd) || typeof (dd === null || dd === void 0 ? void 0 : dd["httpRequest"]) === "function") && { mp: dd, name: "DingTalk" }) || // 钉钉
|
|
23
|
+
(typeof bl !== u && isRequestExists(bl) && { mp: bl, name: "BiliBili" }) || // 哔哩哔哩
|
|
24
|
+
(typeof ft !== u && isRequestExists(ft) && { mp: ft, name: "FinClip" }) || // 泰坪
|
|
25
|
+
(typeof has !== u && isRequestExists(has) && { mp: has, name: "HarmonyASCF" }) || // 鸿蒙元服务
|
|
26
|
+
(typeof uni !== u && isRequestExists(uni) && { mp: uni, name: "UniApp" }) || // UniApp
|
|
27
|
+
(typeof Taro !== u && isRequestExists(Taro) && { mp: Taro, name: "Taro" }) || // Taro
|
|
28
|
+
undefined;
|
|
29
|
+
return platform.value;
|
|
30
|
+
}
|
|
4
31
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
exports.getPlatform = platform.getPlatform;
|
|
32
|
+
exports.getPlatform = getPlatform;
|
package/dist/esm/index.js
CHANGED
|
@@ -1 +1,30 @@
|
|
|
1
|
-
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
const platform = { value: null };
|
|
3
|
+
function isRequestExists(mp) {
|
|
4
|
+
return !!mp && typeof mp === "object" && typeof (mp === null || mp === void 0 ? void 0 : mp["request"]) === "function";
|
|
5
|
+
}
|
|
6
|
+
function getPlatform() {
|
|
7
|
+
if (platform.value !== null)
|
|
8
|
+
return platform.value;
|
|
9
|
+
const u = "undefined";
|
|
10
|
+
platform.value =
|
|
11
|
+
(typeof wx !== u && isRequestExists(wx) && { mp: wx, name: "WeChat" }) || // 微信
|
|
12
|
+
(typeof my !== u && isRequestExists(my) && { mp: my, name: "Alipay" }) || // 支付宝
|
|
13
|
+
(typeof qq !== u && isRequestExists(qq) && { mp: qq, name: "QQ" }) || // QQ
|
|
14
|
+
(typeof jd !== u && isRequestExists(jd) && { mp: jd, name: "JD" }) || // 京东
|
|
15
|
+
(typeof swan !== u && isRequestExists(swan) && { mp: swan, name: "Baidu" }) || // 百度
|
|
16
|
+
(typeof tt !== u && isRequestExists(tt) && { mp: tt, name: "ByteDance" }) || // 抖音 | 飞书
|
|
17
|
+
(typeof ks !== u && isRequestExists(ks) && { mp: ks, name: "Kwai" }) || // 快手
|
|
18
|
+
(typeof qh !== u && isRequestExists(qh) && { mp: qh, name: "Qihu" }) || // 360
|
|
19
|
+
(typeof xhs !== u && isRequestExists(xhs) && { mp: xhs, name: "RedNote" }) || // 小红书
|
|
20
|
+
(typeof dd !== u && (isRequestExists(dd) || typeof (dd === null || dd === void 0 ? void 0 : dd["httpRequest"]) === "function") && { mp: dd, name: "DingTalk" }) || // 钉钉
|
|
21
|
+
(typeof bl !== u && isRequestExists(bl) && { mp: bl, name: "BiliBili" }) || // 哔哩哔哩
|
|
22
|
+
(typeof ft !== u && isRequestExists(ft) && { mp: ft, name: "FinClip" }) || // 泰坪
|
|
23
|
+
(typeof has !== u && isRequestExists(has) && { mp: has, name: "HarmonyASCF" }) || // 鸿蒙元服务
|
|
24
|
+
(typeof uni !== u && isRequestExists(uni) && { mp: uni, name: "UniApp" }) || // UniApp
|
|
25
|
+
(typeof Taro !== u && isRequestExists(Taro) && { mp: Taro, name: "Taro" }) || // Taro
|
|
26
|
+
undefined;
|
|
27
|
+
return platform.value;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export { getPlatform };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
declare
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
declare const platform: {
|
|
2
|
+
value: null | undefined | {
|
|
3
|
+
mp: unknown;
|
|
4
|
+
name: string;
|
|
5
|
+
};
|
|
4
6
|
};
|
|
7
|
+
declare function getPlatform(): NonNullable<typeof platform.value> | undefined;
|
|
5
8
|
|
|
6
9
|
export { getPlatform };
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// @ts-nocheck
|
|
4
|
+
const platform = { value: null };
|
|
5
|
+
function isRequestExists(mp) {
|
|
6
|
+
return !!mp && typeof mp === "object" && typeof (mp === null || mp === void 0 ? void 0 : mp["request"]) === "function";
|
|
7
|
+
}
|
|
8
|
+
function getPlatform() {
|
|
9
|
+
if (platform.value !== null)
|
|
10
|
+
return platform.value;
|
|
11
|
+
const u = "undefined";
|
|
12
|
+
platform.value =
|
|
13
|
+
(typeof wx !== u && isRequestExists(wx) && { mp: wx, name: "WeChat" }) || // 微信
|
|
14
|
+
(typeof my !== u && isRequestExists(my) && { mp: my, name: "Alipay" }) || // 支付宝
|
|
15
|
+
(typeof qq !== u && isRequestExists(qq) && { mp: qq, name: "QQ" }) || // QQ
|
|
16
|
+
(typeof jd !== u && isRequestExists(jd) && { mp: jd, name: "JD" }) || // 京东
|
|
17
|
+
(typeof swan !== u && isRequestExists(swan) && { mp: swan, name: "Baidu" }) || // 百度
|
|
18
|
+
(typeof tt !== u && isRequestExists(tt) && { mp: tt, name: "ByteDance" }) || // 抖音 | 飞书
|
|
19
|
+
(typeof ks !== u && isRequestExists(ks) && { mp: ks, name: "Kwai" }) || // 快手
|
|
20
|
+
(typeof qh !== u && isRequestExists(qh) && { mp: qh, name: "Qihu" }) || // 360
|
|
21
|
+
(typeof xhs !== u && isRequestExists(xhs) && { mp: xhs, name: "RedNote" }) || // 小红书
|
|
22
|
+
(typeof dd !== u && (isRequestExists(dd) || typeof (dd === null || dd === void 0 ? void 0 : dd["httpRequest"]) === "function") && { mp: dd, name: "DingTalk" }) || // 钉钉
|
|
23
|
+
(typeof bl !== u && isRequestExists(bl) && { mp: bl, name: "BiliBili" }) || // 哔哩哔哩
|
|
24
|
+
(typeof ft !== u && isRequestExists(ft) && { mp: ft, name: "FinClip" }) || // 泰坪
|
|
25
|
+
(typeof has !== u && isRequestExists(has) && { mp: has, name: "HarmonyASCF" }) || // 鸿蒙元服务
|
|
26
|
+
(typeof uni !== u && isRequestExists(uni) && { mp: uni, name: "UniApp" }) || // UniApp
|
|
27
|
+
(typeof Taro !== u && isRequestExists(Taro) && { mp: Taro, name: "Taro" }) || // Taro
|
|
28
|
+
undefined;
|
|
29
|
+
return platform.value;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
exports.getPlatform = getPlatform;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";const e={value:null};function t(e){return!!e&&"object"==typeof e&&"function"==typeof(null==e?void 0:e.request)}exports.getPlatform=function(){if(null!==e.value)return e.value;const n="undefined";return e.value=typeof wx!==n&&t(wx)&&{mp:wx,name:"WeChat"}||typeof my!==n&&t(my)&&{mp:my,name:"Alipay"}||typeof qq!==n&&t(qq)&&{mp:qq,name:"QQ"}||typeof jd!==n&&t(jd)&&{mp:jd,name:"JD"}||typeof swan!==n&&t(swan)&&{mp:swan,name:"Baidu"}||typeof tt!==n&&t(tt)&&{mp:tt,name:"ByteDance"}||typeof ks!==n&&t(ks)&&{mp:ks,name:"Kwai"}||typeof qh!==n&&t(qh)&&{mp:qh,name:"Qihu"}||typeof xhs!==n&&t(xhs)&&{mp:xhs,name:"RedNote"}||typeof dd!==n&&(t(dd)||"function"==typeof(null===dd||void 0===dd?void 0:dd.httpRequest))&&{mp:dd,name:"DingTalk"}||typeof bl!==n&&t(bl)&&{mp:bl,name:"BiliBili"}||typeof ft!==n&&t(ft)&&{mp:ft,name:"FinClip"}||typeof has!==n&&t(has)&&{mp:has,name:"HarmonyASCF"}||typeof uni!==n&&t(uni)&&{mp:uni,name:"UniApp"}||typeof Taro!==n&&t(Taro)&&{mp:Taro,name:"Taro"}||void 0,e.value};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
const platform = { value: null };
|
|
3
|
+
function isRequestExists(mp) {
|
|
4
|
+
return !!mp && typeof mp === "object" && typeof (mp === null || mp === void 0 ? void 0 : mp["request"]) === "function";
|
|
5
|
+
}
|
|
6
|
+
function getPlatform() {
|
|
7
|
+
if (platform.value !== null)
|
|
8
|
+
return platform.value;
|
|
9
|
+
const u = "undefined";
|
|
10
|
+
platform.value =
|
|
11
|
+
(typeof wx !== u && isRequestExists(wx) && { mp: wx, name: "WeChat" }) || // 微信
|
|
12
|
+
(typeof my !== u && isRequestExists(my) && { mp: my, name: "Alipay" }) || // 支付宝
|
|
13
|
+
(typeof qq !== u && isRequestExists(qq) && { mp: qq, name: "QQ" }) || // QQ
|
|
14
|
+
(typeof jd !== u && isRequestExists(jd) && { mp: jd, name: "JD" }) || // 京东
|
|
15
|
+
(typeof swan !== u && isRequestExists(swan) && { mp: swan, name: "Baidu" }) || // 百度
|
|
16
|
+
(typeof tt !== u && isRequestExists(tt) && { mp: tt, name: "ByteDance" }) || // 抖音 | 飞书
|
|
17
|
+
(typeof ks !== u && isRequestExists(ks) && { mp: ks, name: "Kwai" }) || // 快手
|
|
18
|
+
(typeof qh !== u && isRequestExists(qh) && { mp: qh, name: "Qihu" }) || // 360
|
|
19
|
+
(typeof xhs !== u && isRequestExists(xhs) && { mp: xhs, name: "RedNote" }) || // 小红书
|
|
20
|
+
(typeof dd !== u && (isRequestExists(dd) || typeof (dd === null || dd === void 0 ? void 0 : dd["httpRequest"]) === "function") && { mp: dd, name: "DingTalk" }) || // 钉钉
|
|
21
|
+
(typeof bl !== u && isRequestExists(bl) && { mp: bl, name: "BiliBili" }) || // 哔哩哔哩
|
|
22
|
+
(typeof ft !== u && isRequestExists(ft) && { mp: ft, name: "FinClip" }) || // 泰坪
|
|
23
|
+
(typeof has !== u && isRequestExists(has) && { mp: has, name: "HarmonyASCF" }) || // 鸿蒙元服务
|
|
24
|
+
(typeof uni !== u && isRequestExists(uni) && { mp: uni, name: "UniApp" }) || // UniApp
|
|
25
|
+
(typeof Taro !== u && isRequestExists(Taro) && { mp: Taro, name: "Taro" }) || // Taro
|
|
26
|
+
undefined;
|
|
27
|
+
return platform.value;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export { getPlatform };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const e={value:null};function n(e){return!!e&&"object"==typeof e&&"function"==typeof(null==e?void 0:e.request)}function t(){if(null!==e.value)return e.value;const t="undefined";return e.value=typeof wx!==t&&n(wx)&&{mp:wx,name:"WeChat"}||typeof my!==t&&n(my)&&{mp:my,name:"Alipay"}||typeof qq!==t&&n(qq)&&{mp:qq,name:"QQ"}||typeof jd!==t&&n(jd)&&{mp:jd,name:"JD"}||typeof swan!==t&&n(swan)&&{mp:swan,name:"Baidu"}||typeof tt!==t&&n(tt)&&{mp:tt,name:"ByteDance"}||typeof ks!==t&&n(ks)&&{mp:ks,name:"Kwai"}||typeof qh!==t&&n(qh)&&{mp:qh,name:"Qihu"}||typeof xhs!==t&&n(xhs)&&{mp:xhs,name:"RedNote"}||typeof dd!==t&&(n(dd)||"function"==typeof(null===dd||void 0===dd?void 0:dd.httpRequest))&&{mp:dd,name:"DingTalk"}||typeof bl!==t&&n(bl)&&{mp:bl,name:"BiliBili"}||typeof ft!==t&&n(ft)&&{mp:ft,name:"FinClip"}||typeof has!==t&&n(has)&&{mp:has,name:"HarmonyASCF"}||typeof uni!==t&&n(uni)&&{mp:uni,name:"UniApp"}||typeof Taro!==t&&n(Taro)&&{mp:Taro,name:"Taro"}||void 0,e.value}export{t as getPlatform};
|
package/package.json
CHANGED
|
@@ -1,30 +1,41 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "miniprogram-platform",
|
|
3
|
-
"version": "
|
|
4
|
-
"license": "MIT",
|
|
5
|
-
"author": "Xingzeng Bao",
|
|
6
|
-
"homepage": "",
|
|
7
|
-
"description": "",
|
|
8
|
-
"type": "module",
|
|
9
|
-
"main": "dist/cjs
|
|
10
|
-
"module": "dist/esm
|
|
11
|
-
"types": "dist/index.d.ts",
|
|
12
|
-
"files": [
|
|
13
|
-
"README.md",
|
|
14
|
-
"dist",
|
|
15
|
-
"!dist/types/**/*",
|
|
16
|
-
"!dist/cjs/types/**/*",
|
|
17
|
-
"!dist/esm/types/**/*"
|
|
18
|
-
],
|
|
19
|
-
"
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
"
|
|
29
|
-
|
|
30
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "miniprogram-platform",
|
|
3
|
+
"version": "1.0.1",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"author": "Xingzeng Bao",
|
|
6
|
+
"homepage": "https://github.com/baoxingzeng/miniprogram-platform",
|
|
7
|
+
"description": "Zero-dependency platform detection for mini-program ecosystems.",
|
|
8
|
+
"type": "module",
|
|
9
|
+
"main": "dist/miniprogram-platform.cjs.js",
|
|
10
|
+
"module": "dist/miniprogram-platform.esm.js",
|
|
11
|
+
"types": "dist/index.d.ts",
|
|
12
|
+
"files": [
|
|
13
|
+
"README.md",
|
|
14
|
+
"dist",
|
|
15
|
+
"!dist/types/**/*",
|
|
16
|
+
"!dist/cjs/types/**/*",
|
|
17
|
+
"!dist/esm/types/**/*"
|
|
18
|
+
],
|
|
19
|
+
"exports": {
|
|
20
|
+
".": {
|
|
21
|
+
"require": "./dist/cjs/index.js",
|
|
22
|
+
"import": "./dist/esm/index.js",
|
|
23
|
+
"types": "./dist/index.d.ts"
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
"sideEffects": false,
|
|
27
|
+
"scripts": {
|
|
28
|
+
"build": "rollup --config",
|
|
29
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
30
|
+
},
|
|
31
|
+
"keywords": [
|
|
32
|
+
"miniprogram"
|
|
33
|
+
],
|
|
34
|
+
"devDependencies": {
|
|
35
|
+
"@rollup/plugin-terser": "^1.0.0",
|
|
36
|
+
"@rollup/plugin-typescript": "^12.3.0",
|
|
37
|
+
"rollup": "^4.61.0",
|
|
38
|
+
"rollup-plugin-dts": "^6.4.1",
|
|
39
|
+
"tslib": "^2.8.1"
|
|
40
|
+
}
|
|
41
|
+
}
|
package/dist/cjs/platform.js
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
// @ts-nocheck
|
|
4
|
-
function getPlatform() {
|
|
5
|
-
let u = "undefined", f = "function", r = "request";
|
|
6
|
-
let platform;
|
|
7
|
-
platform =
|
|
8
|
-
(typeof wx !== u && typeof (wx === null || wx === void 0 ? void 0 : wx[r]) === f && wx && { mp: wx, name: "WeChat" }) || // 微信
|
|
9
|
-
(typeof my !== u && typeof (my === null || my === void 0 ? void 0 : my[r]) === f && my && { mp: my, name: "Alipay" }) || // 支付宝
|
|
10
|
-
(typeof qq !== u && typeof (qq === null || qq === void 0 ? void 0 : qq[r]) === f && qq && { mp: qq, name: "QQ" }) || // QQ
|
|
11
|
-
(typeof jd !== u && typeof (jd === null || jd === void 0 ? void 0 : jd[r]) === f && jd && { mp: jd, name: "JD" }) || // 京东
|
|
12
|
-
(typeof swan !== u && typeof (swan === null || swan === void 0 ? void 0 : swan[r]) === f && swan && { mp: swan, name: "Baidu" }) || // 百度
|
|
13
|
-
(typeof tt !== u && typeof (tt === null || tt === void 0 ? void 0 : tt[r]) === f && tt && { mp: tt, name: "ByteDance" }) || // 抖音 | 飞书
|
|
14
|
-
(typeof ks !== u && typeof (ks === null || ks === void 0 ? void 0 : ks[r]) === f && ks && { mp: ks, name: "Kwai" }) || // 快手
|
|
15
|
-
(typeof qh !== u && typeof (qh === null || qh === void 0 ? void 0 : qh[r]) === f && qh && { mp: qh, name: "Qihu" }) || // 360
|
|
16
|
-
(typeof xhs !== u && typeof (xhs === null || xhs === void 0 ? void 0 : xhs[r]) === f && xhs && { mp: xhs, name: "RedNote" }) || // 小红书
|
|
17
|
-
(typeof uni !== u && typeof (uni === null || uni === void 0 ? void 0 : uni[r]) === f && uni && { mp: uni, name: "UniApp" }) || // UniApp
|
|
18
|
-
(typeof Taro !== u && typeof (Taro === null || Taro === void 0 ? void 0 : Taro[r]) === f && Taro && { mp: Taro, name: "Taro" }) || // Taro
|
|
19
|
-
undefined;
|
|
20
|
-
return platform;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
exports.getPlatform = getPlatform;
|
package/dist/esm/platform.js
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
// @ts-nocheck
|
|
2
|
-
function getPlatform() {
|
|
3
|
-
let u = "undefined", f = "function", r = "request";
|
|
4
|
-
let platform;
|
|
5
|
-
platform =
|
|
6
|
-
(typeof wx !== u && typeof (wx === null || wx === void 0 ? void 0 : wx[r]) === f && wx && { mp: wx, name: "WeChat" }) || // 微信
|
|
7
|
-
(typeof my !== u && typeof (my === null || my === void 0 ? void 0 : my[r]) === f && my && { mp: my, name: "Alipay" }) || // 支付宝
|
|
8
|
-
(typeof qq !== u && typeof (qq === null || qq === void 0 ? void 0 : qq[r]) === f && qq && { mp: qq, name: "QQ" }) || // QQ
|
|
9
|
-
(typeof jd !== u && typeof (jd === null || jd === void 0 ? void 0 : jd[r]) === f && jd && { mp: jd, name: "JD" }) || // 京东
|
|
10
|
-
(typeof swan !== u && typeof (swan === null || swan === void 0 ? void 0 : swan[r]) === f && swan && { mp: swan, name: "Baidu" }) || // 百度
|
|
11
|
-
(typeof tt !== u && typeof (tt === null || tt === void 0 ? void 0 : tt[r]) === f && tt && { mp: tt, name: "ByteDance" }) || // 抖音 | 飞书
|
|
12
|
-
(typeof ks !== u && typeof (ks === null || ks === void 0 ? void 0 : ks[r]) === f && ks && { mp: ks, name: "Kwai" }) || // 快手
|
|
13
|
-
(typeof qh !== u && typeof (qh === null || qh === void 0 ? void 0 : qh[r]) === f && qh && { mp: qh, name: "Qihu" }) || // 360
|
|
14
|
-
(typeof xhs !== u && typeof (xhs === null || xhs === void 0 ? void 0 : xhs[r]) === f && xhs && { mp: xhs, name: "RedNote" }) || // 小红书
|
|
15
|
-
(typeof uni !== u && typeof (uni === null || uni === void 0 ? void 0 : uni[r]) === f && uni && { mp: uni, name: "UniApp" }) || // UniApp
|
|
16
|
-
(typeof Taro !== u && typeof (Taro === null || Taro === void 0 ? void 0 : Taro[r]) === f && Taro && { mp: Taro, name: "Taro" }) || // Taro
|
|
17
|
-
undefined;
|
|
18
|
-
return platform;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export { getPlatform };
|