Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support isByteDance #60

Merged
merged 3 commits into from
Mar 26, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 20 additions & 13 deletions packages/env/README-zh_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
判断和获取运行时环境

## 支持
<img alt="browser" src="https://gw.alicdn.com/tfs/TB1uYFobGSs3KVjSZPiXXcsiVXa-200-200.svg" width="25px" height="25px" /> <img alt="weex" src="https://gw.alicdn.com/tfs/TB1jM0ebMaH3KVjSZFjXXcFWpXa-200-200.svg" width="25px" height="25px" /> <img alt="miniApp" src="https://gw.alicdn.com/tfs/TB1bBpmbRCw3KVjSZFuXXcAOpXa-200-200.svg" width="25px" height="25px" /> <img alt="wechatMiniprogram" src="https://img.alicdn.com/tfs/TB1slcYdxv1gK0jSZFFXXb0sXXa-200-200.svg" width="25px" height="25px"> <img alt="quickApp" src="https://gw.alicdn.com/tfs/TB1MP7EwQT2gK0jSZPcXXcKkpXa-200-200.svg" width="25px" height="25px">
<img alt="browser" src="https://gw.alicdn.com/tfs/TB1uYFobGSs3KVjSZPiXXcsiVXa-200-200.svg" width="25px" height="25px" /> <img alt="weex" src="https://gw.alicdn.com/tfs/TB1jM0ebMaH3KVjSZFjXXcFWpXa-200-200.svg" width="25px" height="25px" /> <img alt="miniApp" src="https://gw.alicdn.com/tfs/TB1bBpmbRCw3KVjSZFuXXcAOpXa-200-200.svg" width="25px" height="25px" /> <img alt="wechatMiniprogram" src="https://img.alicdn.com/tfs/TB1slcYdxv1gK0jSZFFXXb0sXXa-200-200.svg" width="25px" height="25px"> <img alt="bytedanceMiniprogram" src="https://gw.alicdn.com/tfs/TB1jFtVzO_1gK0jSZFqXXcpaXXa-200-200.svg" width="25px" height="25px"> <img alt="quickApp" src="https://gw.alicdn.com/tfs/TB1MP7EwQT2gK0jSZPcXXcKkpXa-200-200.svg" width="25px" height="25px">

## 安装
```bash
Expand All @@ -12,7 +12,7 @@ $ npm install universal-env --save

## 示例
```javascript
import { isWeex, isWeb, isMiniApp, isNode, isWeChatMiniProgram, isQuickApp } from 'universal-env';
import { isWeex, isWeb, isMiniApp, isNode, isWeChatMiniProgram, isByteDance, isQuickApp } from 'universal-env';

```

Expand All @@ -29,6 +29,9 @@ import { isWeex, isWeb, isMiniApp, isNode, isWeChatMiniProgram, isQuickApp } fro
### `isWeChatMiniProgram: boolean`
校验微信小程序环境

### `isByteDance: boolean`
校验字节跳动小程序环境

### `isQuickApp: boolean`
校验快应用环境

Expand All @@ -37,17 +40,21 @@ import { isWeex, isWeb, isMiniApp, isNode, isWeChatMiniProgram, isQuickApp } fro

## 各容器内返回结果

| | isMiniApp | isWeChatMiniProgram | isQuickApp | isWeb | isWeex | isNode |
| ------------------ | --------- | ------------------- | ---------- | ----- | ------ | ------ |
| 阿里小程序 | ✔️ | ✘ | ✘ | ✘ | ✘ | ✘ |
| 阿里小程序 WebView | ✔️ | ✘ | ✘ | ✔️ | ✘ | ✘ |
| 微信小程序 | ✘ | ✔️ | ✘ | ✘ | ✘ | ✘ |
| 微信小程序 WebView | ✘ | ✔️ | ✘ | ✔️ | ✘ | ✘ |
| 快应用 | ✘ | ✘ | ✔️ | ✘ | ✘ | ✘ |
| 快应用 WebView | ✘ | ✘ | ✘ | ✔️ | ✘ | ✘ |
| Weex | ✘ | ✘ | ✘ | ✘ | ✔️ | ✘ |
| Node | ✘ | ✘ | ✘ | ✘ | ✘ | ✔️ |
| Web | ✘ | ✘ | ✘ | ✔️ | ✘ | ✘ |
注:以下各小程序 WebView 内容器判断依赖 WebView 中注入容器的JS SDK。

| | isMiniApp | isWeChatMiniProgram | isByteDance | isQuickApp | isWeb | isWeex | isNode |
| ------------------- | --------- | ------------------- | ---------- | ---------- | ----- | ------ | ------ |
| 阿里小程序 | ✔️ | ✘ | ✘ | ✘ | ✘ | ✘ | ✘ |
| 阿里小程序 WebView | ✔️ | ✘ | ✘ | ✘ | ✔️ | ✘ | ✘ |
| 微信小程序 | ✘ | ✔️ | ✘ | ✘ | ✘ | ✘ | ✘ |
| 微信小程序 WebView | ✘ | ✔️ | ✘ | ✘ | ✔️ | ✘ | ✘ |
| 字节跳动小程序 | ✘ | ✘ | ✔️ | ✘ | ✘ | ✘ | ✘ |
| 字节跳动小程序 WebView | ✘ | ✘ | ✔️ | ✘ | ✔️ | ✘ | ✘ |
| 快应用 | ✘ | ✘ | ✘ | ✔️ | ✘ | ✘ | ✘ |
| 快应用 WebView | ✘ | ✘ | ✘ | ✘ | ✔️ | ✘ | ✘ |
| Weex | ✘ | ✘ | ✘ | ✘ | ✘ | ✔️ | ✘ |
| Node | ✘ | ✘ | ✘ | ✘ | ✘ | ✘ | ✔️ |
| Web | ✘ | ✘ | ✘ | ✘ | ✔️ | ✘ | ✘ |



34 changes: 20 additions & 14 deletions packages/env/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
Judge runtime environment

## Support

<img alt="browser" src="https://gw.alicdn.com/tfs/TB1uYFobGSs3KVjSZPiXXcsiVXa-200-200.svg" width="25px" height="25px" /> <img alt="weex" src="https://gw.alicdn.com/tfs/TB1jM0ebMaH3KVjSZFjXXcFWpXa-200-200.svg" width="25px" height="25px" /> <img alt="miniApp" src="https://gw.alicdn.com/tfs/TB1bBpmbRCw3KVjSZFuXXcAOpXa-200-200.svg" width="25px" height="25px" /> <img alt="wechatMiniprogram" src="https://img.alicdn.com/tfs/TB1slcYdxv1gK0jSZFFXXb0sXXa-200-200.svg" width="25px" height="25px"> <img alt="quickApp" src="https://gw.alicdn.com/tfs/TB1MP7EwQT2gK0jSZPcXXcKkpXa-200-200.svg" width="25px" height="25px">
<img alt="browser" src="https://gw.alicdn.com/tfs/TB1uYFobGSs3KVjSZPiXXcsiVXa-200-200.svg" width="25px" height="25px" /> <img alt="weex" src="https://gw.alicdn.com/tfs/TB1jM0ebMaH3KVjSZFjXXcFWpXa-200-200.svg" width="25px" height="25px" /> <img alt="miniApp" src="https://gw.alicdn.com/tfs/TB1bBpmbRCw3KVjSZFuXXcAOpXa-200-200.svg" width="25px" height="25px" /> <img alt="wechatMiniprogram" src="https://img.alicdn.com/tfs/TB1slcYdxv1gK0jSZFFXXb0sXXa-200-200.svg" width="25px" height="25px"> <img alt="bytedanceMiniprogram" src="https://gw.alicdn.com/tfs/TB1jFtVzO_1gK0jSZFqXXcpaXXa-200-200.svg" width="25px" height="25px"> <img alt="quickApp" src="https://gw.alicdn.com/tfs/TB1MP7EwQT2gK0jSZPcXXcKkpXa-200-200.svg" width="25px" height="25px">

## Install
```bash
Expand All @@ -13,7 +12,7 @@ $ npm install universal-env --save

## Usage
```javascript
import { isWeex, isWeb, isMiniApp, isNode, isWeChatMiniProgram, isQuickApp } from 'universal-env';
import { isWeex, isWeb, isMiniApp, isNode, isWeChatMiniProgram, isByteDance, isQuickApp } from 'universal-env';

```

Expand All @@ -30,6 +29,9 @@ Checks if environment is an alibaba miniprogram environment.
### `isWeChatMiniProgram: boolean`
Checks if environment is a wechat miniprogram environment.

### `isByteDance: boolean`
Checks if environment is a ByteDance miniprogram environment.

### `isQuickApp: boolean`
Checks if environment is a quickapp environment.

Expand All @@ -38,16 +40,20 @@ Checks if environment is a Node.js environment.

## Results in each container

| | isMiniApp | isWeChatMiniProgram | isQuickApp | isWeb | isWeex | isNode |
| ---------------------------- | --------- | ------------------- | ---------- | ----- | ------ | ------ |
| Alibaba MiniApp | ✔️ | ✘ | ✘ | ✘ | ✘ | ✘ |
| Alibaba MiniApp WebView | ✔️ | ✘ | ✘ | ✔️ | ✘ | ✘ |
| Wechat MiniProgram | ✘ | ✔️ | ✘ | ✘ | ✘ | ✘ |
| Wechat MiniProgram WebView | ✘ | ✔️ | ✘ | ✔️ | ✘ | ✘ |
| QuickApp | ✘ | ✘ | ✔️ | ✘ | ✘ | ✘ |
| QuickApp WebView | ✘ | ✘ | ✘ | ✔️ | ✘ | ✘ |
| Weex | ✘ | ✘ | ✘ | ✘ | ✔️ | ✘ |
| Node | ✘ | ✘ | ✘ | ✘ | ✘ | ✔️ |
| Web | ✘ | ✘ | ✘ | ✔️ | ✘ | ✘ |
Note:To judge MiniProgram env in WebView, please insert JS SDK accordingly.

| | isMiniApp | isWeChatMiniProgram | isByteDance | isQuickApp | isWeb | isWeex | isNode |
| ----------------------------- | --------- | ------------------- | ----------- | ---------- | ----- | ------ | ------ |
| Alibaba MiniApp | ✔️ | ✘ | ✘ | ✘ | ✘ | ✘ | ✘ |
| Alibaba MiniApp WebView | ✔️ | ✘ | ✘ | ✘ | ✔️ | ✘ | ✘ |
| Wechat MiniProgram | ✘ | ✔️ | ✘ | ✘ | ✘ | ✘ | ✘ |
| Wechat MiniProgram WebView | ✘ | ✔️ | ✘ | ✘ | ✔️ | ✘ | ✘ |
| ByteDance MiniProgram | ✘ | ✘ | ✔️ | ✘ | ✘ | ✘ | ✘ |
| ByteDance MiniProgram WebView | ✘ | ✘ | ✔️ | ✘ | ✔️ | ✘ | ✘ |
| QuickApp | ✘ | ✘ | ✘ | ✔️ | ✘ | ✘ | ✘ |
| QuickApp WebView | ✘ | ✘ | ✘ | ✘ | ✔️ | ✘ | ✘ |
| Weex | ✘ | ✘ | ✘ | ✘ | ✘ | ✔️ | ✘ |
| Node | ✘ | ✘ | ✘ | ✘ | ✘ | ✘ | ✔️ |
| Web | ✘ | ✘ | ✘ | ✘ | ✔️ | ✘ | ✘ |


33 changes: 20 additions & 13 deletions packages/env/docs-template/README-zh_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
判断和获取运行时环境

## 支持
__icon_web__ __icon_weex__ __icon_miniapp_mp__ __icon_miniapp_wx__ __icon_quick_app__
__icon_web__ __icon_weex__ __icon_miniapp_mp__ __icon_miniapp_wx__ __icon_miniapp_tt__ __icon_quick_app__

## 安装
```bash
Expand All @@ -12,7 +12,7 @@ $ npm install universal-env --save

## 示例
```javascript
import { isWeex, isWeb, isMiniApp, isNode, isWeChatMiniProgram, isQuickApp } from 'universal-env';
import { isWeex, isWeb, isMiniApp, isNode, isWeChatMiniProgram, isByteDance, isQuickApp } from 'universal-env';

```

Expand All @@ -29,6 +29,9 @@ import { isWeex, isWeb, isMiniApp, isNode, isWeChatMiniProgram, isQuickApp } fro
### `isWeChatMiniProgram: boolean`
校验微信小程序环境

### `isByteDance: boolean`
校验字节跳动小程序环境

### `isQuickApp: boolean`
校验快应用环境

Expand All @@ -37,17 +40,21 @@ import { isWeex, isWeb, isMiniApp, isNode, isWeChatMiniProgram, isQuickApp } fro

## 各容器内返回结果

| | isMiniApp | isWeChatMiniProgram | isQuickApp | isWeb | isWeex | isNode |
| ------------------ | --------- | ------------------- | ---------- | ----- | ------ | ------ |
| 阿里小程序 | ✔️ | ✘ | ✘ | ✘ | ✘ | ✘ |
| 阿里小程序 WebView | ✔️ | ✘ | ✘ | ✔️ | ✘ | ✘ |
| 微信小程序 | ✘ | ✔️ | ✘ | ✘ | ✘ | ✘ |
| 微信小程序 WebView | ✘ | ✔️ | ✘ | ✔️ | ✘ | ✘ |
| 快应用 | ✘ | ✘ | ✔️ | ✘ | ✘ | ✘ |
| 快应用 WebView | ✘ | ✘ | ✘ | ✔️ | ✘ | ✘ |
| Weex | ✘ | ✘ | ✘ | ✘ | ✔️ | ✘ |
| Node | ✘ | ✘ | ✘ | ✘ | ✘ | ✔️ |
| Web | ✘ | ✘ | ✘ | ✔️ | ✘ | ✘ |
注:以下各小程序 WebView 内容器判断依赖 WebView 中注入容器的JS SDK。

| | isMiniApp | isWeChatMiniProgram | isByteDance | isQuickApp | isWeb | isWeex | isNode |
| ------------------- | --------- | ------------------- | ---------- | ---------- | ----- | ------ | ------ |
| 阿里小程序 | ✔️ | ✘ | ✘ | ✘ | ✘ | ✘ | ✘ |
| 阿里小程序 WebView | ✔️ | ✘ | ✘ | ✘ | ✔️ | ✘ | ✘ |
| 微信小程序 | ✘ | ✔️ | ✘ | ✘ | ✘ | ✘ | ✘ |
| 微信小程序 WebView | ✘ | ✔️ | ✘ | ✘ | ✔️ | ✘ | ✘ |
| 字节跳动小程序 | ✘ | ✘ | ✔️ | ✘ | ✘ | ✘ | ✘ |
| 字节跳动小程序 WebView | ✘ | ✘ | ✔️ | ✘ | ✔️ | ✘ | ✘ |
| 快应用 | ✘ | ✘ | ✘ | ✔️ | ✘ | ✘ | ✘ |
| 快应用 WebView | ✘ | ✘ | ✘ | ✘ | ✔️ | ✘ | ✘ |
| Weex | ✘ | ✘ | ✘ | ✘ | ✘ | ✔️ | ✘ |
| Node | ✘ | ✘ | ✘ | ✘ | ✘ | ✘ | ✔️ |
| Web | ✘ | ✘ | ✘ | ✘ | ✔️ | ✘ | ✘ |



33 changes: 20 additions & 13 deletions packages/env/docs-template/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Judge runtime environment

## Support
__icon_web__ __icon_weex__ __icon_miniapp_mp__ __icon_miniapp_wx__ __icon_quick_app__
__icon_web__ __icon_weex__ __icon_miniapp_mp__ __icon_miniapp_wx__ __icon_miniapp_tt__ __icon_quick_app__

## Install
```bash
Expand All @@ -12,7 +12,7 @@ $ npm install universal-env --save

## Usage
```javascript
import { isWeex, isWeb, isMiniApp, isNode, isWeChatMiniProgram, isQuickApp } from 'universal-env';
import { isWeex, isWeb, isMiniApp, isNode, isWeChatMiniProgram, isByteDance, isQuickApp } from 'universal-env';

```

Expand All @@ -29,6 +29,9 @@ Checks if environment is an alibaba miniprogram environment.
### `isWeChatMiniProgram: boolean`
Checks if environment is a wechat miniprogram environment.

### `isByteDance: boolean`
Checks if environment is a ByteDance miniprogram environment.

### `isQuickApp: boolean`
Checks if environment is a quickapp environment.

Expand All @@ -37,16 +40,20 @@ Checks if environment is a Node.js environment.

## Results in each container

| | isMiniApp | isWeChatMiniProgram | isQuickApp | isWeb | isWeex | isNode |
| ---------------------------- | --------- | ------------------- | ---------- | ----- | ------ | ------ |
| Alibaba MiniApp | ✔️ | ✘ | ✘ | ✘ | ✘ | ✘ |
| Alibaba MiniApp WebView | ✔️ | ✘ | ✘ | ✔️ | ✘ | ✘ |
| Wechat MiniProgram | ✘ | ✔️ | ✘ | ✘ | ✘ | ✘ |
| Wechat MiniProgram WebView | ✘ | ✔️ | ✘ | ✔️ | ✘ | ✘ |
| QuickApp | ✘ | ✘ | ✔️ | ✘ | ✘ | ✘ |
| QuickApp WebView | ✘ | ✘ | ✘ | ✔️ | ✘ | ✘ |
| Weex | ✘ | ✘ | ✘ | ✘ | ✔️ | ✘ |
| Node | ✘ | ✘ | ✘ | ✘ | ✘ | ✔️ |
| Web | ✘ | ✘ | ✘ | ✔️ | ✘ | ✘ |
Note:To judge MiniProgram env in WebView, please insert JS SDK accordingly.

| | isMiniApp | isWeChatMiniProgram | isByteDance | isQuickApp | isWeb | isWeex | isNode |
| ----------------------------- | --------- | ------------------- | ----------- | ---------- | ----- | ------ | ------ |
| Alibaba MiniApp | ✔️ | ✘ | ✘ | ✘ | ✘ | ✘ | ✘ |
| Alibaba MiniApp WebView | ✔️ | ✘ | ✘ | ✘ | ✔️ | ✘ | ✘ |
| Wechat MiniProgram | ✘ | ✔️ | ✘ | ✘ | ✘ | ✘ | ✘ |
| Wechat MiniProgram WebView | ✘ | ✔️ | ✘ | ✘ | ✔️ | ✘ | ✘ |
| ByteDance MiniProgram | ✘ | ✘ | ✔️ | ✘ | ✘ | ✘ | ✘ |
| ByteDance MiniProgram WebView | ✘ | ✘ | ✔️ | ✘ | ✔️ | ✘ | ✘ |
| QuickApp | ✘ | ✘ | ✘ | ✔️ | ✘ | ✘ | ✘ |
| QuickApp WebView | ✘ | ✘ | ✘ | ✘ | ✔️ | ✘ | ✘ |
| Weex | ✘ | ✘ | ✘ | ✘ | ✘ | ✔️ | ✘ |
| Node | ✘ | ✘ | ✘ | ✘ | ✘ | ✘ | ✔️ |
| Web | ✘ | ✘ | ✘ | ✘ | ✔️ | ✘ | ✘ |


2 changes: 1 addition & 1 deletion packages/env/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "universal-env",
"author": "rax",
"version": "3.1.0",
"version": "3.2.0-0",
"description": "",
"main": "lib/index.js",
"files": [
Expand Down
2 changes: 2 additions & 0 deletions packages/env/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ declare const WXEnvironment: any;
declare const __kraken__: any;
declare const my: any;
declare const wx: any;
declare const tt: any;
declare const global: any;

function isUndef(type): boolean {
Expand All @@ -17,3 +18,4 @@ export const isMiniApp = !isUndef(typeof my) && my !== null && !isUndef(typeof m
// In wechat mini propgram webview, there is no wx.login, but exist wx.miniProgram
export const isWeChatMiniProgram = !isUndef(typeof wx) && wx !== null && (!isUndef(typeof wx.login) || !isUndef(typeof wx.miniProgram));
export const isQuickApp = !isUndef(typeof global) && global !== null && !isUndef(typeof global.callNative) && !isWeex;
export const isByteDance = !isUndef(typeof tt) && tt !== null && !isUndef(typeof tt) && !isUndef(tt.showToast);
Loading