universal-env
Advanced tools
Comparing version 1.0.1 to 1.0.2-beta.1
@@ -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
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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
No website
QualityPackage does not have a website.
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
43
11856
14
16
184
2
2