Socket
Socket
Sign inDemoInstall

universal-env

Package Overview
Dependencies
Maintainers
5
Versions
117
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

universal-env - npm Package Compare versions

Comparing version 1.0.7 to 2.0.0-beta.1

build.json

5

.eslintrc.js
module.exports = {
extends: ['eslint-config-rax/react', 'eslint-config-rax/typescript'],
globals: {},
rules: {}
rules: {
"@typescript-eslint/no-use-before-define": ["error", { "variables": false }],
"@typescript-eslint/no-explicit-any": "off"
}
};

7

lib/index.d.ts

@@ -0,8 +1,5 @@

export declare const isWeb: boolean;
export declare const isNode: boolean;
export declare const isWeex: boolean;
export declare const isReactNative: boolean;
export declare const isMiniApp: boolean;
export declare const isWechatApp: boolean;
export declare const isWeb: boolean;
export declare const isAndroid: boolean;
export declare const isIOS: boolean;
export declare const isWechatMiniprogram: boolean;

@@ -1,58 +0,19 @@

"use strict";
'use strict';
exports.__esModule = true;
exports.isIOS = exports.isAndroid = exports.isWeb = exports.isWechatApp = exports.isMiniApp = exports.isReactNative = exports.isWeex = exports.isNode = void 0;
// compatibility taobao mp
var isTaoWebview = typeof __sfc__ !== 'undefined';
var isWebPure = typeof navigator === 'object' && (navigator.appCodeName === 'Mozilla' || navigator.product === 'Gecko');
var isNode = typeof process !== 'undefined' && !!(process.versions && process.versions.node);
exports.isNode = isNode;
var isWeex = typeof callNative === 'function' || typeof WXEnvironment === 'object' && WXEnvironment.platform !== 'Web';
exports.isWeex = isWeex;
var isReactNative = typeof __fbBatchedBridgeConfig !== 'undefined';
exports.isReactNative = isReactNative;
var isMiniApp = typeof my === 'object' && typeof my.getSystemInfo !== 'undefined' && !isTaoWebview;
exports.isMiniApp = isMiniApp;
var isWechatApp = typeof wx === 'object' && typeof wx.getSystemInfo !== 'undefined'; // In taobao mp'webview __sfc__ is an object
Object.defineProperty(exports, '__esModule', { value: true });
exports.isWechatApp = isWechatApp;
var isWeb = isWebPure && !isMiniApp && !isWechatApp || isTaoWebview;
exports.isWeb = isWeb;
var systemInfo = {};
if (isMiniApp) {
systemInfo = my.getSystemInfoSync();
function isUndef(type) {
return type === 'undefined';
}
var isWeb = !isUndef(typeof window) && 'onload' in window;
var isNode = !isUndef(typeof process) && !!(process.versions && process.versions.node);
var isWeex = !isUndef(typeof callNative) ||
!isUndef(typeof WXEnvironment) && WXEnvironment.platform !== 'Web';
var isMiniApp = !isUndef(typeof my) && !isUndef(my.navigateTo);
var isWechatMiniprogram = !isUndef(typeof wx) && !isUndef(wx.navigateTo);
if (isWechatApp) {
systemInfo = wx.getSystemInfoSync();
}
if (isWeex) {
systemInfo = navigator;
}
var isAndroid = function () {
if (isMiniApp || isWechatApp || isWeex) {
var platform = systemInfo.platform || '';
return platform.toLowerCase() === 'android';
} else if (isWeb) {
return Boolean(navigator.userAgent.match(/android/i));
}
return false;
}();
exports.isAndroid = isAndroid;
var isIOS = function () {
if (isMiniApp || isWechatApp || isWeex) {
return ['ios', 'iOS', 'iPhone OS'].indexOf(systemInfo.platform) > -1;
} else if (isWeb) {
return Boolean(navigator.userAgent.match(/(iphone|ipod|ipad)/i));
}
return false;
}();
exports.isIOS = isIOS;
exports.isMiniApp = isMiniApp;
exports.isNode = isNode;
exports.isWeb = isWeb;
exports.isWechatMiniprogram = isWechatMiniprogram;
exports.isWeex = isWeex;
{
"name": "universal-env",
"author": "rax",
"version": "1.0.7",
"version": "2.0.0-beta.1",
"license": "BSD-3-Clause",
"main": "lib/index.js",
"main": "index.js",
"types": "lib/index.d.ts",
"scripts": {
"start": "rax-scripts start --type 'component' -p 8000",
"start:miniapp": "rax-scripts start --type 'component-miniapp'",
"build": "rax-scripts build --type 'component'",
"start": "rax-scripts start",
"build": "rax-scripts build",
"test": "rax-scripts test",
"lint": "eslint --ext .js --ext .jsx --ext .ts --ext .tsx ./src",
"prebuild": "npm run lint && npm run test",
"prepublish": "npm run build"
"lint": "eslint --ext .js --ext .jsx --ext .ts --ext .tsx ./src"
},

@@ -35,6 +32,7 @@ "keywords": [

"rax": "^1.0.4",
"rax-plugin-api-builder": "^0.0.1",
"rax-plugin-component": "^0.1.5",
"rax-scripts": "^2.0.0",
"rax-text": "^1.0.1",
"rax-view": "^1.0.2",
"rax-scripts": "1.2.1-beta.2",
"typescript": "^3.4.5"
"rax-view": "^1.0.2"
},

@@ -41,0 +39,0 @@ "repository": {

@@ -6,3 +6,3 @@ # universal-env [![npm](https://img.shields.io/npm/v/universal-env.svg)](https://www.npmjs.com/package/universal-env)

## 支持
<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="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">

@@ -16,3 +16,3 @@ ## 安装

```javascript
import { isWeex, isWeb, isMiniApp, isReactNative, isNode } from 'universal-env';
import { isWeex, isWeb, isMiniApp, isNode, isWeChatMiniprogram } from 'universal-env';

@@ -31,15 +31,21 @@ ```

### `isWechatApp: boolean`
### `isWeChatMiniprogram: boolean`
校验微信小程序环境
### `isReactNative: boolean`
校验 React Native 环境
### `isNode: boolean`
校验 Node.js 环境
### `isAndroid: boolean`
校验 Android 环境
## 各容器内返回结果
### `isIOS: boolean`
校验 iOS 环境
| | isMiniApp | isWeChatMiniprogram | isWeb | isWeex | isNode |
| ------------------ | --------- | ------------------- | ----- | ------ | ------ |
| 阿里小程序 | ✔️ | ✘ | ✘ | ✘ | ✘ |
| 阿里小程序 WebView | ✔️ | ✘ | ✔️ | ✘ | ✘ |
| 微信小程序 | ✘ | ✔️ | ✘ | ✘ | ✘ |
| 微信小程序 WebView | ✘ | ✔️ | ✔️ | ✘ | ✘ |
| Weex | ✘ | ✘ | ✘ | ✔️ | ✘ |
| Node | ✘ | ✘ | ✘ | ✘ | ✔️ |
| Web | ✘ | ✘ | ✔️ | ✘ | ✘ |

@@ -15,3 +15,3 @@ # universal-env [![npm](https://img.shields.io/npm/v/universal-env.svg)](https://www.npmjs.com/package/universal-env)

```javascript
import { isWeex, isWeb, isMiniApp, isReactNative, isNode } from 'universal-env';
import { isWeex, isWeb, isMiniApp, isNode, isWeChatMiniprogram } from 'universal-env';

@@ -30,15 +30,20 @@ ```

### `isWechatApp: boolean`
### `isWeChatMiniprogram: boolean`
Checks if environment is a wechat miniprogram environment.
### `isReactNative: boolean`
Checks if environment is a React Native environment.
### `isNode: boolean`
Checks if environment is a Node.js environment.
### `isAndroid: boolean`
Checks if environment is a android environment.
## Results in each container
### `isIOS: boolean`
Checks if environment is a iOS environment.
| | isMiniApp | isWeChatMiniprogram | isWeb | isWeex | isNode |
| ------------------ | --------- | ------------------- | ----- | ------ | ------ |
| Alibaba MiniApp | ✔️ | ✘ | ✘ | ✘ | ✘ |
| Alibaba MiniApp WebView | ✔️ | ✘ | ✔️ | ✘ | ✘ |
| Wechat Miniprogram | ✘ | ✔️ | ✘ | ✘ | ✘ |
| Wechat Miniprogram WebView | ✘ | ✔️ | ✔️ | ✘ | ✘ |
| Weex | ✘ | ✘ | ✘ | ✔️ | ✘ |
| Node | ✘ | ✘ | ✘ | ✘ | ✔️ |
| Web | ✘ | ✘ | ✔️ | ✘ | ✘ |
// eslint-disable-next-line
(global as any).my = {
getSystemInfo: () => {},
navigateTo: () => {},
getSystemInfoSync: () => {

@@ -17,14 +17,2 @@ return {

});
it('Is android mini app environment', (): void => {
// eslint-disable-next-line
const { isAndroid } = require('../index');
expect(isAndroid).toBeTruthy();
});
it('Is not iOS mini app environment', (): void => {
// eslint-disable-next-line
const { isIOS } = require('../index');
expect(isIOS).toBe(false);
});
});

@@ -1,2 +0,2 @@

import { isWeb, isNode, isMiniApp, isReactNative } from '..';
import { isWeb, isNode, isMiniApp } from '..';

@@ -12,6 +12,2 @@ describe('environment value', (): void => {

it('react native environment value is boolean', (): void => {
expect(typeof isReactNative).toEqual('boolean');
});
it('mini app environment value is boolean', (): void => {

@@ -18,0 +14,0 @@ expect(typeof isMiniApp).toEqual('boolean');

@@ -1,47 +0,18 @@

// https://www.w3.org/TR/html5/webappapis.html#dom-navigator-appcodename
declare const callNative: any;
declare const WXEnvironment: any;
declare const __fbBatchedBridgeConfig: any;
declare const my: any;
declare const wx: any;
// compatibility taobao mp
const isTaoWebview = typeof __sfc__ !== 'undefined';
const isWebPure: boolean = typeof navigator === 'object' && (navigator.appCodeName === 'Mozilla' || navigator.product === 'Gecko');
export const isNode: boolean = typeof process !== 'undefined' && !!(process.versions && process.versions.node);
export const isWeex: boolean = typeof callNative === 'function' || typeof WXEnvironment === 'object' && WXEnvironment.platform !== 'Web';
export const isReactNative: boolean = typeof __fbBatchedBridgeConfig !== 'undefined';
export const isMiniApp: boolean = typeof my === 'object' && typeof my.getSystemInfo !== 'undefined' && !isTaoWebview;
export const isWechatApp: boolean = typeof wx === 'object' && typeof wx.getSystemInfo !== 'undefined';
// In taobao mp'webview __sfc__ is an object
export const isWeb: boolean = isWebPure && !isMiniApp && !isWechatApp || isTaoWebview;
let systemInfo: any = {};
if (isMiniApp) {
systemInfo = my.getSystemInfoSync();
function isUndef(type): boolean {
return type === 'undefined';
}
if (isWechatApp) {
systemInfo = wx.getSystemInfoSync();
}
if (isWeex) {
systemInfo = navigator;
}
export const isAndroid = (() => {
if (isMiniApp || isWechatApp || isWeex) {
const platform = systemInfo.platform || '';
return platform.toLowerCase() === 'android';
} else if (isWeb) {
return Boolean(navigator.userAgent.match(/android/i));
}
return false;
})();
export const isIOS = (() => {
if (isMiniApp || isWechatApp || isWeex) {
return ['ios', 'iOS', 'iPhone OS'].indexOf(systemInfo.platform) > -1;
} else if (isWeb) {
return Boolean(navigator.userAgent.match(/(iphone|ipod|ipad)/i));
}
return false;
})();
export const isWeb = !isUndef(typeof window) && 'onload' in window;
export const isNode =
!isUndef(typeof process) && !!(process.versions && process.versions.node);
export const isWeex =
!isUndef(typeof callNative) ||
!isUndef(typeof WXEnvironment) && WXEnvironment.platform !== 'Web';
export const isMiniApp = !isUndef(typeof my) && !isUndef(my.navigateTo);
export const isWeChatMiniprogram =
!isUndef(typeof wx) && !isUndef(wx.navigateTo);
{
"compilerOptions": {
"module": "esNext",
"target": "es2015",
"target": "es5",
"jsx": "preserve",

@@ -6,0 +6,0 @@ "jsxFactory": "createElement",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc