universal-env
Advanced tools
Comparing version 1.0.2 to 1.0.3
@@ -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; |
"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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
11849
184
43
0
14