@probe.gl/env
Advanced tools
Comparing version 4.0.7 to 4.0.8
@@ -1,7 +0,7 @@ | ||
export { VERSION } from "./utils/globals.js"; | ||
export declare const VERSION: any; | ||
export { self, window, global, document, process, console } from "./lib/globals.js"; | ||
export { default as isBrowser, isBrowserMainThread } from "./lib/is-browser.js"; | ||
export { default as getBrowser, isMobile } from "./lib/get-browser.js"; | ||
export { default as isElectron } from "./lib/is-electron.js"; | ||
export { default as assert } from "./utils/assert.js"; | ||
export { isBrowser } from "./lib/is-browser.js"; | ||
export { getBrowser, isMobile } from "./lib/get-browser.js"; | ||
export { isElectron } from "./lib/is-electron.js"; | ||
export { assert } from "./utils/assert.js"; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -1,8 +0,12 @@ | ||
export { VERSION } from "./utils/globals.js"; | ||
// Extract injected version from package.json (injected by babel plugin) | ||
// @ts-expect-error | ||
export const VERSION = typeof "4.0.7" !== 'undefined' ? "4.0.7" : 'untranspiled source'; | ||
// ENVIRONMENT | ||
export { self, window, global, document, process, console } from "./lib/globals.js"; | ||
export { default as isBrowser, isBrowserMainThread } from "./lib/is-browser.js"; | ||
export { default as getBrowser, isMobile } from "./lib/get-browser.js"; | ||
export { default as isElectron } from "./lib/is-electron.js"; | ||
export { isBrowser } from "./lib/is-browser.js"; | ||
export { getBrowser, isMobile } from "./lib/get-browser.js"; | ||
export { isElectron } from "./lib/is-electron.js"; | ||
// ENVIRONMENT'S ASSERT IS 5-15KB, SO WE PROVIDE OUR OWN | ||
export { default as assert } from "./utils/assert.js"; | ||
export { assert } from "./utils/assert.js"; | ||
// TODO - wish we could just export a constant | ||
// export const isBrowser = checkIfBrowser(); |
@@ -7,3 +7,3 @@ declare global { | ||
export declare function isMobile(): boolean; | ||
export default function getBrowser(mockUserAgent?: string): 'Node' | 'Electron' | 'Chrome' | 'Firefox' | 'Safari' | 'Edge' | 'IE' | 'Unknown'; | ||
export declare function getBrowser(mockUserAgent?: string): 'Node' | 'Electron' | 'Chrome' | 'Firefox' | 'Safari' | 'Edge' | 'Unknown'; | ||
//# sourceMappingURL=get-browser.d.ts.map |
@@ -22,8 +22,7 @@ // Copyright (c) 2017 Uber Technologies, Inc. | ||
// make sure it can be imported in isolation | ||
import isBrowser from "./is-browser.js"; | ||
import isElectron from "./is-electron.js"; | ||
import { isBrowser } from "./is-browser.js"; | ||
import { isElectron } from "./is-electron.js"; | ||
import { navigator } from "./globals.js"; | ||
const window = globalThis; | ||
export function isMobile() { | ||
return typeof window.orientation !== 'undefined'; | ||
return typeof globalThis.orientation !== 'undefined'; | ||
} | ||
@@ -33,3 +32,3 @@ // Simple browser detection | ||
/* eslint-disable complexity */ | ||
export default function getBrowser(mockUserAgent) { | ||
export function getBrowser(mockUserAgent) { | ||
if (!mockUserAgent && !isBrowser()) { | ||
@@ -42,3 +41,2 @@ return 'Node'; | ||
const userAgent = mockUserAgent || navigator.userAgent || ''; | ||
// const appVersion = navigator_.appVersion || ''; | ||
// NOTE: Order of tests matter, as many agents list Chrome etc. | ||
@@ -48,14 +46,9 @@ if (userAgent.indexOf('Edge') > -1) { | ||
} | ||
const isMSIE = userAgent.indexOf('MSIE ') !== -1; | ||
const isTrident = userAgent.indexOf('Trident/') !== -1; | ||
if (isMSIE || isTrident) { | ||
return 'IE'; | ||
} | ||
if (window.chrome) { | ||
if (globalThis.chrome) { | ||
return 'Chrome'; | ||
} | ||
if (window.safari) { | ||
if (globalThis.safari) { | ||
return 'Safari'; | ||
} | ||
if (window.mozInnerScreenX) { | ||
if (globalThis.mozInnerScreenX) { | ||
return 'Firefox'; | ||
@@ -62,0 +55,0 @@ } |
declare const global_: typeof globalThis; | ||
declare const self_: typeof globalThis; | ||
declare const window_: Window; | ||
@@ -8,3 +7,3 @@ declare const document_: Document; | ||
declare const navigator_: Navigator; | ||
export { global_ as global, self_ as self, window_ as window, document_ as document, process_ as process, console_ as console, navigator_ as navigator }; | ||
export { global_ as global, global_ as self, window_ as window, document_ as document, process_ as process, console_ as console, navigator_ as navigator }; | ||
//# sourceMappingURL=globals.d.ts.map |
// Do not name these variables the same as the global objects - will break bundling | ||
const global_ = globalThis; | ||
// eslint-disable-next-line consistent-this | ||
const self_ = globalThis.self || globalThis.window || globalThis.global; | ||
const window_ = (globalThis.window || globalThis.self || globalThis.global); | ||
const window_ = globalThis; | ||
const document_ = globalThis.document || {}; | ||
@@ -10,2 +8,2 @@ const process_ = globalThis.process || {}; | ||
const navigator_ = globalThis.navigator || {}; | ||
export { global_ as global, self_ as self, window_ as window, document_ as document, process_ as process, console_ as console, navigator_ as navigator }; | ||
export { global_ as global, global_ as self, window_ as window, document_ as document, process_ as process, console_ as console, navigator_ as navigator }; |
@@ -1,3 +0,3 @@ | ||
export default function isBrowser(): boolean; | ||
export declare function isBrowserMainThread(): boolean; | ||
/** Check if in browser by duck-typing Node context */ | ||
export declare function isBrowser(): boolean; | ||
//# sourceMappingURL=is-browser.d.ts.map |
// This function is needed in initialization stages, | ||
// make sure it can be imported in isolation | ||
import isElectron from "./is-electron.js"; | ||
export default function isBrowser() { | ||
// Check if in browser by duck-typing Node context | ||
const isNode = | ||
import { isElectron } from "./is-electron.js"; | ||
/** Check if in browser by duck-typing Node context */ | ||
export function isBrowser() { | ||
// @ts-expect-error | ||
typeof process === 'object' && String(process) === '[object process]' && !process.browser; | ||
const isNode = typeof process === 'object' && !process?.browser; | ||
return !isNode || isElectron(); | ||
} | ||
// document does not exist on worker thread | ||
export function isBrowserMainThread() { | ||
return isBrowser() && typeof document !== 'undefined'; | ||
} |
@@ -1,2 +0,2 @@ | ||
export default function isElectron(mockUserAgent?: string): boolean; | ||
export declare function isElectron(mockUserAgent?: string): boolean; | ||
//# sourceMappingURL=is-electron.d.ts.map |
// based on https://github.com/cheton/is-electron | ||
// https://github.com/electron/electron/issues/2288 | ||
/* eslint-disable complexity */ | ||
export default function isElectron(mockUserAgent) { | ||
export function isElectron(mockUserAgent) { | ||
// Renderer process | ||
if (typeof window !== 'undefined' && | ||
typeof window.process === 'object' && | ||
// @ts-expect-error | ||
window.process.type === 'renderer') { | ||
// @ts-expect-error | ||
if (typeof window !== 'undefined' && window.process?.type === 'renderer') { | ||
return true; | ||
} | ||
// Main process | ||
if (typeof process !== 'undefined' && | ||
typeof process.versions === 'object' && | ||
// eslint-disable-next-line | ||
Boolean(process.versions['electron'])) { | ||
// eslint-disable-next-line | ||
if (typeof process !== 'undefined' && Boolean(process.versions?.['electron'])) { | ||
return true; | ||
} | ||
// Detect the user agent when the `nodeIntegration` option is set to true | ||
const realUserAgent = typeof navigator === 'object' && typeof navigator.userAgent === 'string' && navigator.userAgent; | ||
const realUserAgent = typeof navigator !== 'undefined' && navigator.userAgent; | ||
const userAgent = mockUserAgent || realUserAgent; | ||
if (userAgent && userAgent.indexOf('Electron') >= 0) { | ||
return true; | ||
} | ||
return false; | ||
return Boolean(userAgent && userAgent.indexOf('Electron') >= 0); | ||
} |
@@ -1,2 +0,2 @@ | ||
export default function assert(condition: unknown, message?: string): void; | ||
export declare function assert(condition: unknown, message?: string): void; | ||
//# sourceMappingURL=assert.d.ts.map |
@@ -1,2 +0,2 @@ | ||
export default function assert(condition, message) { | ||
export function assert(condition, message) { | ||
if (!condition) { | ||
@@ -3,0 +3,0 @@ throw new Error(message || 'Assertion failed'); |
@@ -6,3 +6,3 @@ { | ||
"type": "module", | ||
"version": "4.0.7", | ||
"version": "4.0.8", | ||
"keywords": [ | ||
@@ -36,3 +36,3 @@ "javascript", | ||
], | ||
"gitHead": "e1192bb8b78fb8f713519ab693638408da08de16" | ||
"gitHead": "ae2ed194abe48fa4912ec1d6d3b39196a9b59280" | ||
} |
@@ -1,10 +0,15 @@ | ||
export {VERSION} from './utils/globals'; | ||
// Extract injected version from package.json (injected by babel plugin) | ||
// @ts-expect-error | ||
export const VERSION = typeof __VERSION__ !== 'undefined' ? __VERSION__ : 'untranspiled source'; | ||
// ENVIRONMENT | ||
export {self, window, global, document, process, console} from './lib/globals'; | ||
export {default as isBrowser, isBrowserMainThread} from './lib/is-browser'; | ||
export {default as getBrowser, isMobile} from './lib/get-browser'; | ||
export {default as isElectron} from './lib/is-electron'; | ||
export {isBrowser} from './lib/is-browser'; | ||
export {getBrowser, isMobile} from './lib/get-browser'; | ||
export {isElectron} from './lib/is-electron'; | ||
// ENVIRONMENT'S ASSERT IS 5-15KB, SO WE PROVIDE OUR OWN | ||
export {default as assert} from './utils/assert'; | ||
export {assert} from './utils/assert'; | ||
// TODO - wish we could just export a constant | ||
// export const isBrowser = checkIfBrowser(); |
@@ -24,4 +24,4 @@ // Copyright (c) 2017 Uber Technologies, Inc. | ||
import isBrowser from './is-browser'; | ||
import isElectron from './is-electron'; | ||
import {isBrowser} from './is-browser'; | ||
import {isElectron} from './is-electron'; | ||
import {navigator} from './globals'; | ||
@@ -35,6 +35,4 @@ | ||
const window = globalThis; | ||
export function isMobile(): boolean { | ||
return typeof window.orientation !== 'undefined'; | ||
return typeof globalThis.orientation !== 'undefined'; | ||
} | ||
@@ -45,9 +43,8 @@ | ||
/* eslint-disable complexity */ | ||
export default function getBrowser( | ||
export function getBrowser( | ||
mockUserAgent?: string | ||
): 'Node' | 'Electron' | 'Chrome' | 'Firefox' | 'Safari' | 'Edge' | 'IE' | 'Unknown' { | ||
): 'Node' | 'Electron' | 'Chrome' | 'Firefox' | 'Safari' | 'Edge' | 'Unknown' { | ||
if (!mockUserAgent && !isBrowser()) { | ||
return 'Node'; | ||
} | ||
if (isElectron(mockUserAgent)) { | ||
@@ -58,3 +55,2 @@ return 'Electron'; | ||
const userAgent = mockUserAgent || navigator.userAgent || ''; | ||
// const appVersion = navigator_.appVersion || ''; | ||
@@ -65,14 +61,9 @@ // NOTE: Order of tests matter, as many agents list Chrome etc. | ||
} | ||
const isMSIE = userAgent.indexOf('MSIE ') !== -1; | ||
const isTrident = userAgent.indexOf('Trident/') !== -1; | ||
if (isMSIE || isTrident) { | ||
return 'IE'; | ||
} | ||
if (window.chrome) { | ||
if (globalThis.chrome) { | ||
return 'Chrome'; | ||
} | ||
if (window.safari) { | ||
if (globalThis.safari) { | ||
return 'Safari'; | ||
} | ||
if (window.mozInnerScreenX) { | ||
if (globalThis.mozInnerScreenX) { | ||
return 'Firefox'; | ||
@@ -79,0 +70,0 @@ } |
// Do not name these variables the same as the global objects - will break bundling | ||
const global_ = globalThis; | ||
// eslint-disable-next-line consistent-this | ||
const self_ = globalThis.self || globalThis.window || globalThis.global; | ||
const window_ = (globalThis.window || globalThis.self || globalThis.global) as unknown as Window; | ||
const window_ = globalThis as unknown as Window; | ||
const document_ = globalThis.document || ({} as Document); | ||
@@ -13,3 +11,3 @@ const process_ = globalThis.process || {}; | ||
global_ as global, | ||
self_ as self, | ||
global_ as self, | ||
window_ as window, | ||
@@ -16,0 +14,0 @@ document_ as document, |
// This function is needed in initialization stages, | ||
// make sure it can be imported in isolation | ||
import isElectron from './is-electron'; | ||
import {isElectron} from './is-electron'; | ||
export default function isBrowser(): boolean { | ||
// Check if in browser by duck-typing Node context | ||
const isNode = | ||
// @ts-expect-error | ||
typeof process === 'object' && String(process) === '[object process]' && !process.browser; | ||
/** Check if in browser by duck-typing Node context */ | ||
export function isBrowser(): boolean { | ||
// @ts-expect-error | ||
const isNode = typeof process === 'object' && !process?.browser; | ||
return !isNode || isElectron(); | ||
} | ||
// document does not exist on worker thread | ||
export function isBrowserMainThread(): boolean { | ||
return isBrowser() && typeof document !== 'undefined'; | ||
} |
// based on https://github.com/cheton/is-electron | ||
// https://github.com/electron/electron/issues/2288 | ||
/* eslint-disable complexity */ | ||
export default function isElectron(mockUserAgent?: string): boolean { | ||
export function isElectron(mockUserAgent?: string): boolean { | ||
// Renderer process | ||
if ( | ||
typeof window !== 'undefined' && | ||
typeof window.process === 'object' && | ||
// @ts-expect-error | ||
window.process.type === 'renderer' | ||
) { | ||
// @ts-expect-error | ||
if (typeof window !== 'undefined' && window.process?.type === 'renderer') { | ||
return true; | ||
} | ||
// Main process | ||
if ( | ||
typeof process !== 'undefined' && | ||
typeof process.versions === 'object' && | ||
// eslint-disable-next-line | ||
Boolean(process.versions['electron']) | ||
) { | ||
// eslint-disable-next-line | ||
if (typeof process !== 'undefined' && Boolean(process.versions?.['electron'])) { | ||
return true; | ||
} | ||
// Detect the user agent when the `nodeIntegration` option is set to true | ||
const realUserAgent = | ||
typeof navigator === 'object' && typeof navigator.userAgent === 'string' && navigator.userAgent; | ||
const realUserAgent = typeof navigator !== 'undefined' && navigator.userAgent; | ||
const userAgent = mockUserAgent || realUserAgent; | ||
if (userAgent && userAgent.indexOf('Electron') >= 0) { | ||
return true; | ||
} | ||
return false; | ||
return Boolean(userAgent && userAgent.indexOf('Electron') >= 0); | ||
} |
@@ -1,2 +0,2 @@ | ||
export default function assert(condition: unknown, message?: string) { | ||
export function assert(condition: unknown, message?: string) { | ||
if (!condition) { | ||
@@ -3,0 +3,0 @@ throw new Error(message || 'Assertion failed'); |
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
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
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
35258
39
354