universal-env
Advanced tools
Comparing version 1.0.0 to 1.0.1-beta.1
@@ -95,2 +95,3 @@ // {"framework" : "Rax"} | ||
__webpack_require__.r(__webpack_exports__); | ||
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "isMiniApp", function() { return isMiniApp; }); | ||
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "isWeb", function() { return isWeb; }); | ||
@@ -100,11 +101,37 @@ /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "isNode", function() { return isNode; }); | ||
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "isReactNative", function() { return isReactNative; }); | ||
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "isMiniApp", function() { return isMiniApp; }); | ||
var isWeb = typeof navigator === 'object' && (navigator.appCodeName === 'Mozilla' || navigator.product === 'Gecko'); | ||
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "isAndroid", function() { return isAndroid; }); | ||
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "isIOS", function() { return isIOS; }); | ||
var isWebPure = typeof navigator === 'object' && (navigator.appCodeName === 'Mozilla' || navigator.product === 'Gecko'); | ||
var isMiniApp = typeof my === 'object' && typeof my.getSystemInfo !== 'undefined'; | ||
var isWeb = isWebPure && !isMiniApp; | ||
var isNode = typeof process !== 'undefined' && !!(process.versions && process.versions.node); | ||
var isWeex = typeof callNative === 'function' || typeof WXEnvironment === 'object' && WXEnvironment.platform !== 'Web'; | ||
var isReactNative = typeof __fbBatchedBridgeConfig !== 'undefined'; | ||
var isMiniApp = typeof my === 'object'; | ||
var miniAppSystemInfo = {}; | ||
if (isMiniApp) { | ||
miniAppSystemInfo = my.getSystemInfoSync(); | ||
} | ||
var isAndroid = function () { | ||
if (isMiniApp) { | ||
return ['Android', 'android'].includes(miniAppSystemInfo.platform); | ||
} else if (isWeex) { | ||
return navigator.platform.toLowerCase() === 'android'; | ||
} else { | ||
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'; | ||
} else { | ||
return Boolean(navigator.userAgent.match(/(iphone|ipod|ipad)/i)); | ||
} | ||
}(); | ||
/***/ }) | ||
/******/ ])}); require("env.factory");}};; | ||
//# sourceMappingURL=env.factory.map |
@@ -117,2 +117,3 @@ // {"framework" : "Rax"} | ||
__webpack_require__.r(__webpack_exports__); | ||
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "isMiniApp", function() { return isMiniApp; }); | ||
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "isWeb", function() { return isWeb; }); | ||
@@ -122,11 +123,37 @@ /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "isNode", function() { return isNode; }); | ||
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "isReactNative", function() { return isReactNative; }); | ||
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "isMiniApp", function() { return isMiniApp; }); | ||
var isWeb = typeof navigator === 'object' && (navigator.appCodeName === 'Mozilla' || navigator.product === 'Gecko'); | ||
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "isAndroid", function() { return isAndroid; }); | ||
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "isIOS", function() { return isIOS; }); | ||
var isWebPure = typeof navigator === 'object' && (navigator.appCodeName === 'Mozilla' || navigator.product === 'Gecko'); | ||
var isMiniApp = typeof my === 'object' && typeof my.getSystemInfo !== 'undefined'; | ||
var isWeb = isWebPure && !isMiniApp; | ||
var isNode = typeof process !== 'undefined' && !!(process.versions && process.versions.node); | ||
var isWeex = typeof callNative === 'function' || typeof WXEnvironment === 'object' && WXEnvironment.platform !== 'Web'; | ||
var isReactNative = typeof __fbBatchedBridgeConfig !== 'undefined'; | ||
var isMiniApp = typeof my === 'object'; | ||
var miniAppSystemInfo = {}; | ||
if (isMiniApp) { | ||
miniAppSystemInfo = my.getSystemInfoSync(); | ||
} | ||
var isAndroid = function () { | ||
if (isMiniApp) { | ||
return ['Android', 'android'].includes(miniAppSystemInfo.platform); | ||
} else if (isWeex) { | ||
return navigator.platform.toLowerCase() === 'android'; | ||
} else { | ||
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'; | ||
} else { | ||
return Boolean(navigator.userAgent.match(/(iphone|ipod|ipad)/i)); | ||
} | ||
}(); | ||
/***/ }) | ||
/******/ ])}); require("env");});; | ||
//# sourceMappingURL=env.map |
// {"framework" : "Rax"} | ||
!function(o){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=o();else if("function"==typeof define)define("universal-env",function(e,n,t){t.exports=o()});else{("undefined"!=typeof window?window:"undefined"!=typeof self?self:"undefined"!=typeof global?global:this).UniversalEnv=o()}}(function(){return define("env.min",function(e){function r(e){if(o[e])return o[e].exports;var n=o[e]={i:e,l:!1,exports:{}};return t[e].call(n.exports,n,n.exports,r),n.l=!0,n.exports}var t,o;o={},r.m=t=[function(e,n,t){"use strict";t.r(n),t.d(n,"isWeb",function(){return o}),t.d(n,"isNode",function(){return r}),t.d(n,"isWeex",function(){return i}),t.d(n,"isReactNative",function(){return f}),t.d(n,"isMiniApp",function(){return u});var o="object"==typeof navigator&&("Mozilla"===navigator.appCodeName||"Gecko"===navigator.product),r="undefined"!=typeof process&&!(!process.versions||!process.versions.node),i="function"==typeof callNative||"object"==typeof WXEnvironment&&"Web"!==WXEnvironment.platform,f="undefined"!=typeof __fbBatchedBridgeConfig,u="object"==typeof my}],r.c=o,r.d=function(e,n,t){r.o(e,n)||Object.defineProperty(e,n,{enumerable:!0,get:t})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(n,e){if(1&e&&(n=r(n)),8&e)return n;if(4&e&&"object"==typeof n&&n&&n.__esModule)return n;var t=Object.create(null);if(r.r(t),Object.defineProperty(t,"default",{enumerable:!0,value:n}),2&e&&"string"!=typeof n)for(var o in n)r.d(t,o,function(e){return n[e]}.bind(null,o));return t},r.n=function(e){var n=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(n,"a",n),n},r.o=function(e,n){return Object.prototype.hasOwnProperty.call(e,n)},r.p="/",r(r.s=0)})}); | ||
!function(o){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=o();else if("function"==typeof define)define("universal-env",function(e,n,t){t.exports=o()});else{("undefined"!=typeof window?window:"undefined"!=typeof self?self:"undefined"!=typeof global?global:this).UniversalEnv=o()}}(function(){return define("env.min",function(e){function r(e){if(o[e])return o[e].exports;var n=o[e]={i:e,l:!1,exports:{}};return t[e].call(n.exports,n,n.exports,r),n.l=!0,n.exports}var t,o;o={},r.m=t=[function(e,n,t){"use strict";t.r(n),t.d(n,"isMiniApp",function(){return r}),t.d(n,"isWeb",function(){return i}),t.d(n,"isNode",function(){return f}),t.d(n,"isWeex",function(){return u}),t.d(n,"isReactNative",function(){return d}),t.d(n,"isAndroid",function(){return c}),t.d(n,"isIOS",function(){return l});var o="object"==typeof navigator&&("Mozilla"===navigator.appCodeName||"Gecko"===navigator.product),r="object"==typeof my&&void 0!==my.getSystemInfo,i=o&&!r,f="undefined"!=typeof process&&!(!process.versions||!process.versions.node),u="function"==typeof callNative||"object"==typeof WXEnvironment&&"Web"!==WXEnvironment.platform,d="undefined"!=typeof __fbBatchedBridgeConfig,a={};r&&(a=my.getSystemInfoSync());var c=r?["Android","android"].includes(a.platform):u?"android"===navigator.platform.toLowerCase():Boolean(navigator.userAgent.match(/android/i)),l=r?["iPhone OS","iOS"].includes(a.platform):u?"ios"===navigator.platform.toLowerCase():Boolean(navigator.userAgent.match(/(iphone|ipod|ipad)/i))}],r.c=o,r.d=function(e,n,t){r.o(e,n)||Object.defineProperty(e,n,{enumerable:!0,get:t})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(n,e){if(1&e&&(n=r(n)),8&e)return n;if(4&e&&"object"==typeof n&&n&&n.__esModule)return n;var t=Object.create(null);if(r.r(t),Object.defineProperty(t,"default",{enumerable:!0,value:n}),2&e&&"string"!=typeof n)for(var o in n)r.d(t,o,function(e){return n[e]}.bind(null,o));return t},r.n=function(e){var n=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(n,"a",n),n},r.o=function(e,n){return Object.prototype.hasOwnProperty.call(e,n)},r.p="/",r(r.s=0)})}); | ||
//# sourceMappingURL=env.min.map |
@@ -0,1 +1,2 @@ | ||
export declare const isMiniApp: boolean; | ||
export declare const isWeb: boolean; | ||
@@ -5,2 +6,3 @@ export declare const isNode: boolean; | ||
export declare const isReactNative: boolean; | ||
export declare const isMiniApp: boolean; | ||
export declare const isAndroid: boolean; | ||
export declare const isIOS: boolean; |
"use strict"; | ||
exports.__esModule = true; | ||
exports.isMiniApp = exports.isReactNative = exports.isWeex = exports.isNode = exports.isWeb = void 0; | ||
var isWeb = typeof navigator === 'object' && (navigator.appCodeName === 'Mozilla' || navigator.product === 'Gecko'); | ||
exports.isIOS = exports.isAndroid = exports.isReactNative = exports.isWeex = exports.isNode = exports.isWeb = exports.isMiniApp = 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; | ||
@@ -13,3 +16,30 @@ var isNode = typeof process !== 'undefined' && !!(process.versions && process.versions.node); | ||
exports.isReactNative = isReactNative; | ||
var isMiniApp = typeof my === 'object'; | ||
exports.isMiniApp = isMiniApp; | ||
var miniAppSystemInfo = {}; | ||
if (isMiniApp) { | ||
miniAppSystemInfo = my.getSystemInfoSync(); | ||
} | ||
var isAndroid = function () { | ||
if (isMiniApp) { | ||
return ['Android', 'android'].includes(miniAppSystemInfo.platform); | ||
} else if (isWeex) { | ||
return navigator.platform.toLowerCase() === 'android'; | ||
} else { | ||
return Boolean(navigator.userAgent.match(/android/i)); | ||
} | ||
}(); | ||
exports.isAndroid = isAndroid; | ||
var isIOS = function () { | ||
if (isMiniApp) { | ||
return ['iPhone OS', 'iOS'].includes(miniAppSystemInfo.platform); | ||
} else if (isWeex) { | ||
return navigator.platform.toLowerCase() === 'ios'; | ||
} else { | ||
return Boolean(navigator.userAgent.match(/(iphone|ipod|ipad)/i)); | ||
} | ||
}(); | ||
exports.isIOS = isIOS; |
{ | ||
"name": "universal-env", | ||
"author": "rax", | ||
"version": "1.0.0", | ||
"version": "1.0.1-beta.1", | ||
"license": "BSD-3-Clause", | ||
"main": "lib/index.js", | ||
@@ -16,3 +17,3 @@ "types": "lib/index.d.ts", | ||
"lint": "eslint --ext .js --ext .jsx --ext .ts --ext .tsx ./src", | ||
"prebuild": "npm run lint && yarn run test", | ||
"prebuild": "npm run lint && npm run test", | ||
"prepublish": "npm run build" | ||
@@ -40,3 +41,11 @@ }, | ||
"typescript": "^3.4.5" | ||
} | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/raxjs/universal-env" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/raxjs/universal-env/issues" | ||
}, | ||
"homepage": "https://github.com/raxjs/universal-env" | ||
} |
@@ -1,5 +0,8 @@ | ||
# universal-env | ||
# 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" /> | ||
## 安装 | ||
@@ -18,6 +21,6 @@ ```bash | ||
### `isWeex: boolean` | ||
校验weex环境 | ||
校验 weex 环境 | ||
### `isWeb: boolean` | ||
校验web环境 | ||
校验 web 环境 | ||
@@ -28,5 +31,11 @@ ### `isMiniApp: boolean` | ||
### `isReactNative: boolean` | ||
校验React Native环境 | ||
校验 React Native 环境 | ||
### `isNode: boolean` | ||
校验Node.js环境 | ||
校验 Node.js 环境 | ||
### `isAndroid: boolean` | ||
校验 android 环境 | ||
### `isIOS: boolean` | ||
校验 iOS 环境 |
@@ -1,5 +0,8 @@ | ||
# universal-env | ||
# universal-env [![npm](https://img.shields.io/npm/v/universal-env.svg)](https://www.npmjs.com/package/universal-env) | ||
Judge runtime environment | ||
## Support | ||
<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" /> | ||
## Install | ||
@@ -31,1 +34,7 @@ ```bash | ||
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 = {}; | ||
(global as any).my = { | ||
getSystemInfo: () => {}, | ||
getSystemInfoSync: () => { | ||
return { | ||
platform: 'android' | ||
}; | ||
} | ||
}; | ||
@@ -10,2 +17,14 @@ describe('Mni app environment', (): void => { | ||
}); | ||
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); | ||
}); | ||
}); |
@@ -7,6 +7,32 @@ // https://www.w3.org/TR/html5/webappapis.html#dom-navigator-appcodename | ||
export const isWeb: boolean = typeof navigator === 'object' && (navigator.appCodeName === 'Mozilla' || navigator.product === 'Gecko'); | ||
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'; | ||
let miniAppSystemInfo: any = {}; | ||
if (isMiniApp) { | ||
miniAppSystemInfo = my.getSystemInfoSync(); | ||
} | ||
export const isAndroid = (() => { | ||
if (isMiniApp) { | ||
return ['Android', 'android'].includes(miniAppSystemInfo.platform); | ||
} else if (isWeex) { | ||
return navigator.platform.toLowerCase() === 'android'; | ||
} else { | ||
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'; | ||
} else { | ||
return Boolean(navigator.userAgent.match(/(iphone|ipod|ipad)/i)); | ||
} | ||
})(); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
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
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 bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
No License Found
License(Experimental) License information could not be found.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
No website
QualityPackage does not have a website.
Found 1 instance in 1 package
48459
30
0
512
40
0
0
2