# @uni/env

> [![npm](https://img.shields.io/npm/v/@uni/env.svg)](https://www.npmjs.com/package/@uni/env)

Latest version **1.1.1** (published 2023-04-26) · BSD-3-Clause license · 0 weekly downloads

## Install

```sh
npm install @uni/env
pnpm add @uni/env
yarn add @uni/env
bun add @uni/env
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.1 |
| Published | 2023-04-26 |
| First published | 2021-02-26 |
| Weekly downloads | 0 |
| License | BSD-3-Clause |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 20 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 270 |
| Author | rax |
| Maintainers | bunko, rax-publisher |

## Links

- npm: https://www.npmjs.com/package/@uni/env
- Repository: https://github.com/raxjs/universal-api
- Homepage: https://github.com/raxjs/universal-api#readme
- Issues: https://github.com/raxjs/universal-api/issues
- npm.io page: https://npm.io/package/@uni/env

## Recent versions

- 1.1.1 (latest) — 2023-04-26
- 1.1.0-beta.1 (beta) — 2022-02-17
- 1.1.0 — 2022-04-11
- 1.1.0-beta.0 — 2022-02-16
- 1.0.7 — 2021-07-15
- 1.0.6 — 2021-05-25
- 1.0.6-beta — 2021-05-19
- 1.0.5 — 2021-05-07
- 1.0.4 — 2021-05-07
- 1.0.3 — 2021-04-28
- 1.0.2 — 2021-04-22
- 1.0.1 — 2021-04-14
- 1.0.1-beta — 2021-03-10
- 1.0.0 — 2021-03-04
- 1.0.0-beta1 — 2021-02-26
- … 1 more at https://npm.io/package/@uni/env/versions

## README

# env
[![npm](https://img.shields.io/npm/v/@uni/env.svg)](https://www.npmjs.com/package/@uni/env)

判断和获取运行时环境

## 支持
<img alt="browser" src="https://gw.alicdn.com/tfs/TB1uYFobGSs3KVjSZPiXXcsiVXa-200-200.svg" width="25px" height="25px" title="h5" /> <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" title="阿里小程序" /> <img alt="wechatMiniprogram" src="https://img.alicdn.com/tfs/TB1slcYdxv1gK0jSZFFXXb0sXXa-200-200.svg" width="25px" height="25px" title="微信小程序" /> <img alt="bytedanceMicroApp" src="https://gw.alicdn.com/tfs/TB1jFtVzO_1gK0jSZFqXXcpaXXa-200-200.svg" width="25px" height="25px" title="字节跳动小程序" /> <img alt="baiduSmartProgram" src="https://img.alicdn.com/imgextra/i4/O1CN01jngdBb24yGv2Fu34G_!!6000000007459-2-tps-200-200.png" width="25px" height="25px" title="百度小程序"> <img alt="kuaiShouMiniProgram" src="https://gw.alicdn.com/imgextra/i4/O1CN01kzmJMM24jcFEzp5Wv_!!6000000007427-2-tps-200-200.png" width="25px" height="25px" title="快手小程序">

## 安装
```bash
$ npm install @uni/env --save
```

## 示例
```javascript
import { isWeex, isWeb, isMiniApp, isNode, isWeChatMiniProgram, isByteDanceMicroApp, isBaiduSmartProgram, isKuaiShouMiniProgram } from '@uni/env';

```
你也可以从大包引入：

```js
import { env } from '@uni/apis';
```

## APIS
### `isWeex: boolean`
校验 Weex 环境

### `isWeb: boolean`
校验 Web 环境

### `isMiniApp: boolean`
校验阿里小程序环境

### `isWeChatMiniProgram: boolean`
校验微信小程序环境

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

### `isBaiduSmartProgram: boolean`
校验百度小程序环境

### `isKuaiShouMiniProgram: boolean`
校验快手小程序环境

### `isNode: boolean`
校验 Node.js 环境

## 各容器内返回结果

注：以下各小程序 WebView 内容器判断依赖 WebView 中注入容器的JS SDK。

|                     | isMiniApp | isWeChatMiniProgram | isByteDanceMicroApp | isBaiduSmartProgram | isKuaiShouMiniProgram | isWeb | isWeex | isNode |
| ------------------- | --------- | ------------------- | ------------------  | ------------------- | --------------------- | ------ | ----- | ------ |
| 阿里小程序            | ✔️         | ✘                   | ✘                   | ✘                   | ✘                     | ✘      | ✘     | ✘    |
| 阿里小程序 WebView    | ✔️         | ✘                   | ✘                   | ✘                   | ✘                     | ✔️      | ✘     | ✘   |
| 微信小程序            | ✘         | ✔️                   | ✘                   | ✘                   | ✘                     | ✘      | ✘     | ✘   |
| 微信小程序 WebView    | ✘         | ✔️                   | ✘                   | ✘                   | ✘                     | ✔️      | ✘     | ✘   |
| 字节跳动小程序         | ✘         | ✘                   | ✔️                   | ✘                   | ✘                     | ✘      | ✘     | ✘   |
| 字节跳动小程序 WebView | ✘         | ✘                   | ✔️                   | ✘                   | ✘                     | ✔️      | ✘     | ✘   |
| 百度小程序            | ✘         | ✘                    | ✘                   | ✔️                  | ✘                     | ✘      | ✘     | ✘   |
| 百度小程序 WebView    | ✘         | ✘                   | ✘                   | ✔️                   | ✘                     | ✔️      | ✘     | ✘   |
| 快手小程序            | ✘         | ✘                    | ✘                   | ✘                  | ✔️                     | ✘      | ✘     | ✘   |
| 快手小程序 WebView    | ✘         | ✘                   | ✘                   | ✘                   | ✔️                     | ✔️      | ✘     | ✘   |
| Node                 | ✘         | ✘                   | ✘                   | ✘                  | ✘                      | ✘      | ✘     | ✔️   |
| Web                  | ✘         | ✘                   | ✘                   | ✘                  | ✘                      | ✔️      | ✘     | ✘   |

---
_Source: https://npm.io/package/@uni/env · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
