Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

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.1 to 1.0.2-beta.1

7

lib/index.d.ts

@@ -1,5 +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;
"use strict";
exports.__esModule = true;
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);

@@ -15,2 +11,45 @@ exports.isNode = isNode;

var isReactNative = typeof __fbBatchedBridgeConfig !== 'undefined';
exports.isReactNative = isReactNative;
exports.isReactNative = isReactNative;
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) {
systemInfo = my.getSystemInfoSync();
}
if (isWechatApp) {
systemInfo = wx.getSystemInfoSync();
}
if (isWeex) {
systemInfo = navigator;
}
var isAndroid = function () {
if (isMiniApp || isWechatApp || isWeex) {
return systemInfo.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'].includes(systemInfo.platform);
} else if (isWeb) {
return Boolean(navigator.userAgent.match(/(iphone|ipod|ipad)/i));
}
return false;
}();
exports.isIOS = isIOS;
{
"name": "universal-env",
"author": "rax",
"version": "1.0.1",
"version": "1.0.2-beta.1",
"license": "BSD-3-Clause",
"main": "lib/index.js",
"types": "lib/index.d.ts",
"miniappConfig": {
"main": "lib/index.js"
},
"scripts": {

@@ -38,2 +35,4 @@ "start": "rax-scripts start --type 'component' -p 8000",

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

@@ -49,3 +48,3 @@ "typescript": "^3.4.5"

},
"homepage": "https://github.com/alibaba/rax#readme"
"homepage": "https://github.com/raxjs/universal-env"
}

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

### `isWeex: boolean`
校验weex环境
校验 Weex 环境
### `isWeb: boolean`
校验web环境
校验 Web 环境
### `isMiniApp: boolean`
校验小程序环境
校验阿里小程序环境
### `isWechatApp: boolean`
校验微信小程序环境
### `isReactNative: boolean`
校验React Native环境
校验 React Native 环境
### `isNode: boolean`
校验Node.js环境
校验 Node.js 环境
### `isAndroid: boolean`
校验 Android 环境
### `isIOS: boolean`
校验 iOS 环境

@@ -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`

@@ -35,1 +38,7 @@ Checks if environment is a React Native environment.

Checks if environment is a Node.js environment.
### `isAndroid: boolean`
Checks if environment is a android environment.
### `isIOS: boolean`
Checks if environment is a iOS environment.
// eslint-disable-next-line
(global as any).my = {
getSystemInfo: () => {}
getSystemInfo: () => {},
getSystemInfoSync: () => {
return {
platform: 'android'
};
}
};

@@ -12,2 +17,14 @@

});
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);
});
});

@@ -6,8 +6,40 @@ // 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 systemInfo: any = {};
if (isMiniApp) {
systemInfo = my.getSystemInfoSync();
}
if (isWechatApp) {
systemInfo = wx.getSystemInfoSync();
}
if (isWeex) {
systemInfo = navigator;
}
export const isAndroid = (() => {
if (isMiniApp || isWechatApp || isWeex) {
return systemInfo.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'].includes(systemInfo.platform);
} else if (isWeb) {
return Boolean(navigator.userAgent.match(/(iphone|ipod|ipad)/i));
}
return false;
})();

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