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.2 to 1.0.3

5

lib/index.d.ts

@@ -1,7 +0,8 @@

export declare const isMiniApp: boolean;
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;

36

lib/index.js
"use strict";
exports.__esModule = true;
exports.isIOS = exports.isAndroid = exports.isReactNative = exports.isWeex = exports.isNode = exports.isWeb = exports.isMiniApp = void 0;
exports.isIOS = exports.isAndroid = exports.isWeb = exports.isWechatApp = exports.isMiniApp = exports.isReactNative = exports.isWeex = exports.isNode = void 0;
var isWebPure = typeof navigator === 'object' && (navigator.appCodeName === 'Mozilla' || navigator.product === 'Gecko');
var isMiniApp = typeof my === 'object' && typeof my.getSystemInfo !== 'undefined';
exports.isMiniApp = isMiniApp;
var isWeb = isWebPure && !isMiniApp;
exports.isWeb = isWeb;
var isNode = typeof process !== 'undefined' && !!(process.versions && process.versions.node);

@@ -16,13 +12,25 @@ exports.isNode = isNode;

exports.isReactNative = isReactNative;
var miniAppSystemInfo = {};
var isMiniApp = typeof my === 'object' && typeof my.getSystemInfo !== 'undefined';
exports.isMiniApp = isMiniApp;
var isWechatApp = typeof wx === 'object' && typeof wx.getSystemInfo !== 'undefined';
exports.isWechatApp = isWechatApp;
var isWeb = isWebPure && !isMiniApp && !isWechatApp;
exports.isWeb = isWeb;
var systemInfo = {};
if (isMiniApp) {
miniAppSystemInfo = my.getSystemInfoSync();
systemInfo = my.getSystemInfoSync();
}
if (isWechatApp) {
systemInfo = wx.getSystemInfoSync();
}
if (isWeex) {
systemInfo = navigator;
}
var isAndroid = function () {
if (isMiniApp) {
return ['Android', 'android'].includes(miniAppSystemInfo.platform);
} else if (isWeex) {
return navigator.platform.toLowerCase() === 'android';
if (isMiniApp || isWechatApp || isWeex) {
return systemInfo.platform.toLowerCase() === 'android';
} else if (isWeb) {

@@ -38,6 +46,4 @@ return Boolean(navigator.userAgent.match(/android/i));

var isIOS = function () {
if (isMiniApp) {
return ['iPhone OS', 'iOS'].includes(miniAppSystemInfo.platform);
} else if (isWeex) {
return navigator.platform.toLowerCase() === 'ios';
if (isMiniApp || isWechatApp || isWeex) {
return ['ios', 'iOS', 'iPhone OS'].includes(systemInfo.platform);
} else if (isWeb) {

@@ -44,0 +50,0 @@ return Boolean(navigator.userAgent.match(/(iphone|ipod|ipad)/i));

{
"name": "universal-env",
"author": "rax",
"version": "1.0.2",
"version": "1.0.3",
"license": "BSD-3-Clause",

@@ -35,2 +35,4 @@ "main": "lib/index.js",

"rax": "^1.0.4",
"rax-text": "^1.0.1",
"rax-view": "^1.0.2",
"rax-scripts": "1.2.1-beta.2",

@@ -37,0 +39,0 @@ "typescript": "^3.4.5"

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

### `isMiniApp: boolean`
校验小程序环境
校验阿里小程序环境
### `isWechatApp: boolean`
校验微信小程序环境
### `isReactNative: boolean`

@@ -31,0 +34,0 @@ 校验 React Native 环境

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

### `isMiniApp: boolean`
Checks if environment is a mini app environment.
Checks if environment is an alibaba miniprogram environment.
### `isWechatApp: boolean`
Checks if environment is a wechat miniprogram environment.
### `isReactNative: boolean`

@@ -31,0 +34,0 @@ Checks if environment is a React Native environment.

@@ -6,20 +6,26 @@ // https://www.w3.org/TR/html5/webappapis.html#dom-navigator-appcodename

declare const my: any;
declare const wx: any;
const isWebPure: boolean = typeof navigator === 'object' && (navigator.appCodeName === 'Mozilla' || navigator.product === 'Gecko');
export const isMiniApp: boolean = typeof my === 'object' && typeof my.getSystemInfo !== 'undefined';
export const isWeb: boolean = isWebPure && !isMiniApp;
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';
export const isWechatApp: boolean = typeof wx === 'object' && typeof wx.getSystemInfo !== 'undefined';
export const isWeb: boolean = isWebPure && !isMiniApp && !isWechatApp;
let miniAppSystemInfo: any = {};
let systemInfo: any = {};
if (isMiniApp) {
miniAppSystemInfo = my.getSystemInfoSync();
systemInfo = my.getSystemInfoSync();
}
if (isWechatApp) {
systemInfo = wx.getSystemInfoSync();
}
if (isWeex) {
systemInfo = navigator;
}
export const isAndroid = (() => {
if (isMiniApp) {
return ['Android', 'android'].includes(miniAppSystemInfo.platform);
} else if (isWeex) {
return navigator.platform.toLowerCase() === 'android';
if (isMiniApp || isWechatApp || isWeex) {
return systemInfo.platform.toLowerCase() === 'android';
} else if (isWeb) {

@@ -32,6 +38,4 @@ return Boolean(navigator.userAgent.match(/android/i));

export const isIOS = (() => {
if (isMiniApp) {
return ['iPhone OS', 'iOS'].includes(miniAppSystemInfo.platform);
} else if (isWeex) {
return navigator.platform.toLowerCase() === 'ios';
if (isMiniApp || isWechatApp || isWeex) {
return ['ios', 'iOS', 'iPhone OS'].includes(systemInfo.platform);
} else if (isWeb) {

@@ -42,1 +46,2 @@ return Boolean(navigator.userAgent.match(/(iphone|ipod|ipad)/i));

})();

Sorry, the diff of this file is not supported yet

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