UNPKG

jshow-device-detect

Version:
70 lines 2.03 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const tslib_1 = require("tslib"); /* eslint-disable @typescript-eslint/no-non-null-assertion */ const regexp_1 = tslib_1.__importDefault(require("../constants/regexp")); const utils_1 = require("../utils"); /** * UA 解析类。 */ class UAParser { constructor(ua) { this._userAgent = ''; this.reset(ua); } get userAgent() { return this._userAgent; } set userAgent(value) { this.reset(value); } get browser() { return this._cacheObject.browser; } get engine() { return this._cacheObject.engine; } get os() { return this._cacheObject.os; } get device() { return this._cacheObject.device; } get cpu() { return this._cacheObject.cpu; } reset(ua) { this._userAgent = ua || (typeof window !== 'undefined' && window.navigator && window.navigator.userAgent) || ''; this._cacheObject = { ua: this._userAgent, browser: this.getBrowser(), engine: this.getEngine(), os: this.getOS(), device: this.getDevice(), cpu: this.getCPU(), }; return this; } getBrowser(ua = this._userAgent) { const browser = (0, utils_1.execRxp)(ua, regexp_1.default.browser); browser.major = (0, utils_1.getMajor)(browser.version); return browser; } getCPU(ua = this._userAgent) { return (0, utils_1.execRxp)(ua, regexp_1.default.cpu); } getDevice(ua = this._userAgent) { return (0, utils_1.execRxp)(ua, regexp_1.default.device); } getEngine(ua = this._userAgent) { return (0, utils_1.execRxp)(ua, regexp_1.default.engine); } getOS(ua = this._userAgent) { return (0, utils_1.execRxp)(ua, regexp_1.default.os); } toString() { return this._cacheObject.toString(); } } exports.default = UAParser; //# sourceMappingURL=parser.js.map