@shopify/browser
Advanced tools
Comparing version 1.1.3 to 1.1.4
@@ -1,145 +0,71 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.asPlainObject = exports.Browser = void 0; | ||
var ua_parser_js_1 = require("ua-parser-js"); | ||
var MOBILE_DEVICE_TYPES = ['mobile', 'tablet']; | ||
var Browser = /** @class */ (function () { | ||
function Browser(_a) { | ||
var userAgent = _a.userAgent, _b = _a.supported, supported = _b === void 0 ? true : _b; | ||
import { UAParser } from 'ua-parser-js'; | ||
const MOBILE_DEVICE_TYPES = ['mobile', 'tablet']; | ||
export class Browser { | ||
constructor({ userAgent, supported = true }) { | ||
this.userAgent = userAgent; | ||
this.supported = supported; | ||
this.ua = new ua_parser_js_1.UAParser(userAgent); | ||
this.ua = new UAParser(userAgent); | ||
} | ||
Object.defineProperty(Browser.prototype, "name", { | ||
get: function () { | ||
return this.ua.getBrowser().name || ''; | ||
}, | ||
enumerable: false, | ||
configurable: true | ||
}); | ||
Object.defineProperty(Browser.prototype, "version", { | ||
get: function () { | ||
return this.ua.getBrowser().version || ''; | ||
}, | ||
enumerable: false, | ||
configurable: true | ||
}); | ||
Object.defineProperty(Browser.prototype, "majorVersion", { | ||
get: function () { | ||
var version = this.version; | ||
if (version === '') { | ||
return undefined; | ||
} | ||
var majorVersion = parseInt(version.split('.')[0], 10); | ||
return Number.isNaN(majorVersion) ? undefined : majorVersion; | ||
}, | ||
enumerable: false, | ||
configurable: true | ||
}); | ||
Object.defineProperty(Browser.prototype, "unknown", { | ||
get: function () { | ||
return this.name === ''; | ||
}, | ||
enumerable: false, | ||
configurable: true | ||
}); | ||
Object.defineProperty(Browser.prototype, "isMobile", { | ||
get: function () { | ||
return MOBILE_DEVICE_TYPES.includes(this.ua.getDevice().type); | ||
}, | ||
enumerable: false, | ||
configurable: true | ||
}); | ||
Object.defineProperty(Browser.prototype, "isDesktop", { | ||
get: function () { | ||
return !this.isMobile; | ||
}, | ||
enumerable: false, | ||
configurable: true | ||
}); | ||
Object.defineProperty(Browser.prototype, "isNativeApp", { | ||
get: function () { | ||
return this.ua.getUA().includes('Shopify Mobile/', 0); | ||
}, | ||
enumerable: false, | ||
configurable: true | ||
}); | ||
Object.defineProperty(Browser.prototype, "os", { | ||
get: function () { | ||
return this.ua.getOS().name || ''; | ||
}, | ||
enumerable: false, | ||
configurable: true | ||
}); | ||
Object.defineProperty(Browser.prototype, "isWindows", { | ||
get: function () { | ||
return this.os.includes('Windows'); | ||
}, | ||
enumerable: false, | ||
configurable: true | ||
}); | ||
Object.defineProperty(Browser.prototype, "isMac", { | ||
get: function () { | ||
return this.os.includes('Mac OS'); | ||
}, | ||
enumerable: false, | ||
configurable: true | ||
}); | ||
Object.defineProperty(Browser.prototype, "isSafari", { | ||
get: function () { | ||
return this.name.includes('Safari'); | ||
}, | ||
enumerable: false, | ||
configurable: true | ||
}); | ||
Object.defineProperty(Browser.prototype, "isChrome", { | ||
get: function () { | ||
return this.name.includes('Chrome'); | ||
}, | ||
enumerable: false, | ||
configurable: true | ||
}); | ||
Object.defineProperty(Browser.prototype, "isAndroidChrome", { | ||
get: function () { | ||
return this.ua.getUA().includes('Android') && this.name.includes('Chrome'); | ||
}, | ||
enumerable: false, | ||
configurable: true | ||
}); | ||
Object.defineProperty(Browser.prototype, "isFirefox", { | ||
get: function () { | ||
return this.name === 'Firefox'; | ||
}, | ||
enumerable: false, | ||
configurable: true | ||
}); | ||
Object.defineProperty(Browser.prototype, "isIE", { | ||
get: function () { | ||
return this.name.includes('IE'); | ||
}, | ||
enumerable: false, | ||
configurable: true | ||
}); | ||
Object.defineProperty(Browser.prototype, "isEdge", { | ||
get: function () { | ||
return this.name === 'Edge'; | ||
}, | ||
enumerable: false, | ||
configurable: true | ||
}); | ||
Object.defineProperty(Browser.prototype, "isIOS", { | ||
get: function () { | ||
var os = this.ua.getOS(); | ||
var isStandardiOS = os.name && os.name.includes('iOS'); | ||
var isShopifyiOS = /Shopify Mobile|Shopify POS|Shopify Ping/.test(this.userAgent) && | ||
this.userAgent.includes('iOS'); | ||
return isStandardiOS || isShopifyiOS; | ||
}, | ||
enumerable: false, | ||
configurable: true | ||
}); | ||
return Browser; | ||
}()); | ||
exports.Browser = Browser; | ||
function asPlainObject(browser) { | ||
get name() { | ||
return this.ua.getBrowser().name || ''; | ||
} | ||
get version() { | ||
return this.ua.getBrowser().version || ''; | ||
} | ||
get majorVersion() { | ||
const { version } = this; | ||
if (version === '') { | ||
return undefined; | ||
} | ||
const majorVersion = parseInt(version.split('.')[0], 10); | ||
return Number.isNaN(majorVersion) ? undefined : majorVersion; | ||
} | ||
get unknown() { | ||
return this.name === ''; | ||
} | ||
get isMobile() { | ||
return MOBILE_DEVICE_TYPES.includes(this.ua.getDevice().type); | ||
} | ||
get isDesktop() { | ||
return !this.isMobile; | ||
} | ||
get isNativeApp() { | ||
return this.ua.getUA().includes('Shopify Mobile/', 0); | ||
} | ||
get os() { | ||
return this.ua.getOS().name || ''; | ||
} | ||
get isWindows() { | ||
return this.os.includes('Windows'); | ||
} | ||
get isMac() { | ||
return this.os.includes('Mac OS'); | ||
} | ||
get isSafari() { | ||
return this.name.includes('Safari'); | ||
} | ||
get isChrome() { | ||
return this.name.includes('Chrome'); | ||
} | ||
get isAndroidChrome() { | ||
return this.ua.getUA().includes('Android') && this.name.includes('Chrome'); | ||
} | ||
get isFirefox() { | ||
return this.name === 'Firefox'; | ||
} | ||
get isIE() { | ||
return this.name.includes('IE'); | ||
} | ||
get isEdge() { | ||
return this.name === 'Edge'; | ||
} | ||
get isIOS() { | ||
const os = this.ua.getOS(); | ||
const isStandardiOS = os.name && os.name.includes('iOS'); | ||
const isShopifyiOS = /Shopify Mobile|Shopify POS|Shopify Ping/.test(this.userAgent) && | ||
this.userAgent.includes('iOS'); | ||
return isStandardiOS || isShopifyiOS; | ||
} | ||
} | ||
export function asPlainObject(browser) { | ||
if (browser == null) { | ||
@@ -156,2 +82,1 @@ return {}; | ||
} | ||
exports.asPlainObject = asPlainObject; |
@@ -1,5 +0,1 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var browser_1 = require("./browser"); | ||
Object.defineProperty(exports, "Browser", { enumerable: true, get: function () { return browser_1.Browser; } }); | ||
Object.defineProperty(exports, "asPlainObject", { enumerable: true, get: function () { return browser_1.asPlainObject; } }); | ||
export { Browser, asPlainObject } from './browser'; |
@@ -8,4 +8,12 @@ # Changelog | ||
## [1.1.2] - 2021-03-03 | ||
<!-- ## Unreleased --> | ||
## 1.1.4 - 2021-04-13 | ||
### Changed | ||
- Removed dependency on tslib, as we no-longer compile with `tsc`. [#1829](https://github.com/Shopify/quilt/pull/1829) | ||
## 1.1.2 - 2021-03-03 | ||
### Fixed | ||
@@ -15,3 +23,3 @@ | ||
## [1.1.0] - 2020-12-18 | ||
## 1.1.0 - 2020-12-18 | ||
@@ -22,7 +30,7 @@ ### Added | ||
## [1.0.1] - 2020-10-20 | ||
## 1.0.1 - 2020-10-20 | ||
- Added `tslib@^1.14.1` in the list of dependencies. [#1657](https://github.com/Shopify/quilt/pull/1657) | ||
## [1.0.0] - 2020-05-20 | ||
## 1.0.0 - 2020-05-20 | ||
@@ -29,0 +37,0 @@ ### Added |
{ | ||
"name": "@shopify/browser", | ||
"version": "1.1.3", | ||
"version": "1.1.4", | ||
"license": "MIT", | ||
@@ -8,5 +8,2 @@ "description": "Utilities for extracting browser information from user-agents", | ||
"types": "index.d.ts", | ||
"scripts": { | ||
"build": "tsc --p tsconfig.json" | ||
}, | ||
"sideEffects": false, | ||
@@ -36,3 +33,2 @@ "publishConfig": { | ||
"dependencies": { | ||
"tslib": "^1.14.1", | ||
"ua-parser-js": "^0.7.17" | ||
@@ -39,0 +35,0 @@ }, |
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
1
29027
514
- Removedtslib@^1.14.1
- Removedtslib@1.14.1(transitive)