Comparing version 1.0.0 to 1.0.1
@@ -1,775 +0,2 @@ | ||
const BROWSER_ALIASES_MAP = { | ||
"Amazon Silk": "amazon_silk", | ||
"Android Browser": "android", | ||
Bada: "bada", | ||
BlackBerry: "blackberry", | ||
Chrome: "chrome", | ||
Chromium: "chromium", | ||
Electron: "electron", | ||
Epiphany: "epiphany", | ||
Firefox: "firefox", | ||
Focus: "focus", | ||
Generic: "generic", | ||
"Google Search": "google_search", | ||
Googlebot: "googlebot", | ||
"Internet Explorer": "ie", | ||
"K-Meleon": "k_meleon", | ||
Maxthon: "maxthon", | ||
Miui: "miui", | ||
"Microsoft Edge": "edge", | ||
"MZ Browser": "mz", | ||
"NAVER Whale Browser": "naver", | ||
Opera: "opera", | ||
"Opera Coast": "opera_coast", | ||
"Opera Touch": "opera_touch", | ||
PhantomJS: "phantomjs", | ||
"PlayStation 4": "ps4", | ||
Puffin: "puffin", | ||
QupZilla: "qupzilla", | ||
QQ: "qq", | ||
QQLite: "qqlite", | ||
Safari: "safari", | ||
Sailfish: "sailfish", | ||
"Samsung Internet for Android": "samsung_internet", | ||
SeaMonkey: "seamonkey", | ||
Sleipnir: "sleipnir", | ||
SlimerJS: "slimerjs", | ||
Swing: "swing", | ||
Tizen: "tizen", | ||
"UC Browser": "uc", | ||
Vivaldi: "vivaldi", | ||
"WebOS Browser": "webos", | ||
WeChat: "wechat", | ||
"Yandex Browser": "yandex", | ||
Roku: "roku" | ||
}; | ||
const BROWSER_MAP = { | ||
amazon_silk: "Amazon Silk", | ||
android: "Android Browser", | ||
bada: "Bada", | ||
blackberry: "BlackBerry", | ||
chrome: "Chrome", | ||
chromium: "Chromium", | ||
electron: "Electron", | ||
epiphany: "Epiphany", | ||
firefox: "Firefox", | ||
focus: "Focus", | ||
generic: "Generic", | ||
googlebot: "Googlebot", | ||
google_search: "Google Search", | ||
ie: "Internet Explorer", | ||
k_meleon: "K-Meleon", | ||
maxthon: "Maxthon", | ||
miui: "Miui", | ||
edge: "Microsoft Edge", | ||
mz: "MZ Browser", | ||
naver: "NAVER Whale Browser", | ||
opera: "Opera", | ||
opera_coast: "Opera Coast", | ||
opera_touch: "Opera Touch", | ||
phantomjs: "PhantomJS", | ||
ps4: "PlayStation 4", | ||
puffin: "Puffin", | ||
qupzilla: "QupZilla", | ||
qq: "QQ Browser", | ||
qqlite: "QQ Browser Lite", | ||
safari: "Safari", | ||
sailfish: "Sailfish", | ||
samsung_internet: "Samsung Internet for Android", | ||
seamonkey: "SeaMonkey", | ||
sleipnir: "Sleipnir", | ||
slimerjs: "SlimerJS", | ||
swing: "Swing", | ||
tizen: "Tizen", | ||
uc: "UC Browser", | ||
vivaldi: "Vivaldi", | ||
webos: "WebOS Browser", | ||
wechat: "WeChat", | ||
yandex: "Yandex Browser" | ||
}; | ||
function getFirstMatch(regexp, ua) { | ||
const match = ua.match(regexp); | ||
return match && match.length > 0 && match[1] || ""; | ||
} | ||
function getSecondMatch(regexp, ua) { | ||
const match = ua.match(regexp); | ||
return match && match.length > 1 && match[2] || ""; | ||
} | ||
const commonVersionIdentifier = /version\/(\d+(\.?_?\d+)+)/i; | ||
const browsersList = [ | ||
{ | ||
test: [/googlebot/i], | ||
describe(ua) { | ||
const browser = { | ||
name: BROWSER_MAP.googlebot | ||
}; | ||
const version = getFirstMatch(/googlebot\/(\d+(\.\d+))/i, ua) || getFirstMatch(commonVersionIdentifier, ua); | ||
if (version) { | ||
browser.version = version; | ||
} | ||
return browser; | ||
} | ||
}, | ||
{ | ||
test: [/opera/i], | ||
describe(ua) { | ||
const browser = { | ||
name: BROWSER_MAP.opera | ||
}; | ||
const version = getFirstMatch(commonVersionIdentifier, ua) || getFirstMatch(/(?:opera)[\s/](\d+(\.?_?\d+)+)/i, ua); | ||
if (version) { | ||
browser.version = version; | ||
} | ||
return browser; | ||
} | ||
}, | ||
{ | ||
test: [/opr\/|opios/i], | ||
describe(ua) { | ||
const browser = { | ||
name: BROWSER_MAP.opera | ||
}; | ||
const version = getFirstMatch(/(?:opr|opios)[\s/](\S+)/i, ua) || getFirstMatch(commonVersionIdentifier, ua); | ||
if (version) { | ||
browser.version = version; | ||
} | ||
return browser; | ||
} | ||
}, | ||
{ | ||
test: [/SamsungBrowser/i], | ||
describe(ua) { | ||
const browser = { | ||
name: BROWSER_MAP.samsung_internet | ||
}; | ||
const version = getFirstMatch(commonVersionIdentifier, ua) || getFirstMatch(/(?:SamsungBrowser)[\s/](\d+(\.?_?\d+)+)/i, ua); | ||
if (version) { | ||
browser.version = version; | ||
} | ||
return browser; | ||
} | ||
}, | ||
{ | ||
test: [/Whale/i], | ||
describe(ua) { | ||
const browser = { | ||
name: BROWSER_MAP.naver | ||
}; | ||
const version = getFirstMatch(commonVersionIdentifier, ua) || getFirstMatch(/(?:whale)[\s/](\d+(?:\.\d+)+)/i, ua); | ||
if (version) { | ||
browser.version = version; | ||
} | ||
return browser; | ||
} | ||
}, | ||
{ | ||
test: [/MZBrowser/i], | ||
describe(ua) { | ||
const browser = { | ||
name: BROWSER_MAP.mz | ||
}; | ||
const version = getFirstMatch(/(?:MZBrowser)[\s/](\d+(?:\.\d+)+)/i, ua) || getFirstMatch(commonVersionIdentifier, ua); | ||
if (version) { | ||
browser.version = version; | ||
} | ||
return browser; | ||
} | ||
}, | ||
{ | ||
test: [/focus/i], | ||
describe(ua) { | ||
const browser = { | ||
name: BROWSER_MAP.focus | ||
}; | ||
const version = getFirstMatch(/(?:focus)[\s/](\d+(?:\.\d+)+)/i, ua) || getFirstMatch(commonVersionIdentifier, ua); | ||
if (version) { | ||
browser.version = version; | ||
} | ||
return browser; | ||
} | ||
}, | ||
{ | ||
test: [/swing/i], | ||
describe(ua) { | ||
const browser = { | ||
name: BROWSER_MAP.swing | ||
}; | ||
const version = getFirstMatch(/(?:swing)[\s/](\d+(?:\.\d+)+)/i, ua) || getFirstMatch(commonVersionIdentifier, ua); | ||
if (version) { | ||
browser.version = version; | ||
} | ||
return browser; | ||
} | ||
}, | ||
{ | ||
test: [/coast/i], | ||
describe(ua) { | ||
const browser = { | ||
name: BROWSER_MAP.opera_coast | ||
}; | ||
const version = getFirstMatch(commonVersionIdentifier, ua) || getFirstMatch(/(?:coast)[\s/](\d+(\.?_?\d+)+)/i, ua); | ||
if (version) { | ||
browser.version = version; | ||
} | ||
return browser; | ||
} | ||
}, | ||
{ | ||
test: [/opt\/\d+(?:.?_?\d+)+/i], | ||
describe(ua) { | ||
const browser = { | ||
name: BROWSER_MAP.opera_touch | ||
}; | ||
const version = getFirstMatch(/(?:opt)[\s/](\d+(\.?_?\d+)+)/i, ua) || getFirstMatch(commonVersionIdentifier, ua); | ||
if (version) { | ||
browser.version = version; | ||
} | ||
return browser; | ||
} | ||
}, | ||
{ | ||
test: [/yabrowser/i], | ||
describe(ua) { | ||
const browser = { | ||
name: BROWSER_MAP.yandex | ||
}; | ||
const version = getFirstMatch(/(?:yabrowser)[\s/](\d+(\.?_?\d+)+)/i, ua) || getFirstMatch(commonVersionIdentifier, ua); | ||
if (version) { | ||
browser.version = version; | ||
} | ||
return browser; | ||
} | ||
}, | ||
{ | ||
test: [/ucbrowser/i], | ||
describe(ua) { | ||
const browser = { | ||
name: BROWSER_MAP.uc | ||
}; | ||
const version = getFirstMatch(commonVersionIdentifier, ua) || getFirstMatch(/(?:ucbrowser)[\s/](\d+(\.?_?\d+)+)/i, ua); | ||
if (version) { | ||
browser.version = version; | ||
} | ||
return browser; | ||
} | ||
}, | ||
{ | ||
test: [/Maxthon|mxios/i], | ||
describe(ua) { | ||
const browser = { | ||
name: BROWSER_MAP.maxthon | ||
}; | ||
const version = getFirstMatch(commonVersionIdentifier, ua) || getFirstMatch(/(?:Maxthon|mxios)[\s/](\d+(\.?_?\d+)+)/i, ua); | ||
if (version) { | ||
browser.version = version; | ||
} | ||
return browser; | ||
} | ||
}, | ||
{ | ||
test: [/epiphany/i], | ||
describe(ua) { | ||
const browser = { | ||
name: BROWSER_MAP.epiphany | ||
}; | ||
const version = getFirstMatch(commonVersionIdentifier, ua) || getFirstMatch(/(?:epiphany)[\s/](\d+(\.?_?\d+)+)/i, ua); | ||
if (version) { | ||
browser.version = version; | ||
} | ||
return browser; | ||
} | ||
}, | ||
{ | ||
test: [/puffin/i], | ||
describe(ua) { | ||
const browser = { | ||
name: BROWSER_MAP.puffin | ||
}; | ||
const version = getFirstMatch(commonVersionIdentifier, ua) || getFirstMatch(/(?:puffin)[\s/](\d+(\.?_?\d+)+)/i, ua); | ||
if (version) { | ||
browser.version = version; | ||
} | ||
return browser; | ||
} | ||
}, | ||
{ | ||
test: [/sleipnir/i], | ||
describe(ua) { | ||
const browser = { | ||
name: BROWSER_MAP.sleipnir | ||
}; | ||
const version = getFirstMatch(commonVersionIdentifier, ua) || getFirstMatch(/(?:sleipnir)[\s/](\d+(\.?_?\d+)+)/i, ua); | ||
if (version) { | ||
browser.version = version; | ||
} | ||
return browser; | ||
} | ||
}, | ||
{ | ||
test: [/k-meleon/i], | ||
describe(ua) { | ||
const browser = { | ||
name: BROWSER_MAP.k_meleon | ||
}; | ||
const version = getFirstMatch(commonVersionIdentifier, ua) || getFirstMatch(/(?:k-meleon)[\s/](\d+(\.?_?\d+)+)/i, ua); | ||
if (version) { | ||
browser.version = version; | ||
} | ||
return browser; | ||
} | ||
}, | ||
{ | ||
test: [/micromessenger/i], | ||
describe(ua) { | ||
const browser = { | ||
name: BROWSER_MAP.wechat | ||
}; | ||
const version = getFirstMatch(/(?:micromessenger)[\s/](\d+(\.?_?\d+)+)/i, ua) || getFirstMatch(commonVersionIdentifier, ua); | ||
if (version) { | ||
browser.version = version; | ||
} | ||
return browser; | ||
} | ||
}, | ||
{ | ||
test: [/qqbrowser/i], | ||
describe(ua) { | ||
const browser = { | ||
name: /qqbrowserlite/i.test(ua) ? BROWSER_MAP.qqlite : BROWSER_MAP.qq | ||
}; | ||
const version = getFirstMatch(/(?:qqbrowserlite|qqbrowser)[/](\d+(\.?_?\d+)+)/i, ua) || getFirstMatch(commonVersionIdentifier, ua); | ||
if (version) { | ||
browser.version = version; | ||
} | ||
return browser; | ||
} | ||
}, | ||
{ | ||
test: [/msie|trident/i], | ||
describe(ua) { | ||
const browser = { | ||
name: BROWSER_MAP.ie | ||
}; | ||
const version = getFirstMatch(/(?:msie |rv:)(\d+(\.?_?\d+)+)/i, ua); | ||
if (version) { | ||
browser.version = version; | ||
} | ||
return browser; | ||
} | ||
}, | ||
{ | ||
test: [/\sedg\//i], | ||
describe(ua) { | ||
const browser = { | ||
name: BROWSER_MAP.edge | ||
}; | ||
const version = getFirstMatch(/\sedg\/(\d+(\.?_?\d+)+)/i, ua); | ||
if (version) { | ||
browser.version = version; | ||
} | ||
return browser; | ||
} | ||
}, | ||
{ | ||
test: [/edg([ea]|ios)/i], | ||
describe(ua) { | ||
const browser = { | ||
name: BROWSER_MAP.edge | ||
}; | ||
const version = getSecondMatch(/edg([ea]|ios)\/(\d+(\.?_?\d+)+)/i, ua); | ||
if (version) { | ||
browser.version = version; | ||
} | ||
return browser; | ||
} | ||
}, | ||
{ | ||
test: [/vivaldi/i], | ||
describe(ua) { | ||
const browser = { | ||
name: BROWSER_MAP.vivaldi | ||
}; | ||
const version = getFirstMatch(/vivaldi\/(\d+(\.?_?\d+)+)/i, ua); | ||
if (version) { | ||
browser.version = version; | ||
} | ||
return browser; | ||
} | ||
}, | ||
{ | ||
test: [/seamonkey/i], | ||
describe(ua) { | ||
const browser = { | ||
name: BROWSER_MAP.seamonkey | ||
}; | ||
const version = getFirstMatch(/seamonkey\/(\d+(\.?_?\d+)+)/i, ua); | ||
if (version) { | ||
browser.version = version; | ||
} | ||
return browser; | ||
} | ||
}, | ||
{ | ||
test: [/sailfish/i], | ||
describe(ua) { | ||
const browser = { | ||
name: BROWSER_MAP.sailfish | ||
}; | ||
const version = getFirstMatch(/sailfish\s?browser\/(\d+(\.\d+)?)/i, ua); | ||
if (version) { | ||
browser.version = version; | ||
} | ||
return browser; | ||
} | ||
}, | ||
{ | ||
test: [/silk/i], | ||
describe(ua) { | ||
const browser = { | ||
name: BROWSER_MAP.amazon_silk | ||
}; | ||
const version = getFirstMatch(/silk\/(\d+(\.?_?\d+)+)/i, ua); | ||
if (version) { | ||
browser.version = version; | ||
} | ||
return browser; | ||
} | ||
}, | ||
{ | ||
test: [/phantom/i], | ||
describe(ua) { | ||
const browser = { | ||
name: BROWSER_MAP.phantomjs | ||
}; | ||
const version = getFirstMatch(/phantomjs\/(\d+(\.?_?\d+)+)/i, ua); | ||
if (version) { | ||
browser.version = version; | ||
} | ||
return browser; | ||
} | ||
}, | ||
{ | ||
test: [/slimerjs/i], | ||
describe(ua) { | ||
const browser = { | ||
name: BROWSER_MAP.slimerjs | ||
}; | ||
const version = getFirstMatch(/slimerjs\/(\d+(\.?_?\d+)+)/i, ua); | ||
if (version) { | ||
browser.version = version; | ||
} | ||
return browser; | ||
} | ||
}, | ||
{ | ||
test: [/blackberry|\bbb\d+/i, /rim\stablet/i], | ||
describe(ua) { | ||
const browser = { | ||
name: BROWSER_MAP.blackberry | ||
}; | ||
const version = getFirstMatch(commonVersionIdentifier, ua) || getFirstMatch(/blackberry[\d]+\/(\d+(\.?_?\d+)+)/i, ua); | ||
if (version) { | ||
browser.version = version; | ||
} | ||
return browser; | ||
} | ||
}, | ||
{ | ||
test: [/(web|hpw)[o0]s/i], | ||
describe(ua) { | ||
const browser = { | ||
name: BROWSER_MAP.webos | ||
}; | ||
const version = getFirstMatch(commonVersionIdentifier, ua) || getFirstMatch(/w(?:eb)?[o0]sbrowser\/(\d+(\.?_?\d+)+)/i, ua); | ||
if (version) { | ||
browser.version = version; | ||
} | ||
return browser; | ||
} | ||
}, | ||
{ | ||
test: [/bada/i], | ||
describe(ua) { | ||
const browser = { | ||
name: BROWSER_MAP.bada | ||
}; | ||
const version = getFirstMatch(/dolfin\/(\d+(\.?_?\d+)+)/i, ua); | ||
if (version) { | ||
browser.version = version; | ||
} | ||
return browser; | ||
} | ||
}, | ||
{ | ||
test: [/tizen/i], | ||
describe(ua) { | ||
const browser = { | ||
name: BROWSER_MAP.tizen | ||
}; | ||
const version = getFirstMatch(/(?:tizen\s?)?browser\/(\d+(\.?_?\d+)+)/i, ua) || getFirstMatch(commonVersionIdentifier, ua); | ||
if (version) { | ||
browser.version = version; | ||
} | ||
return browser; | ||
} | ||
}, | ||
{ | ||
test: [/qupzilla/i], | ||
describe(ua) { | ||
const browser = { | ||
name: BROWSER_MAP.qupzilla | ||
}; | ||
const version = getFirstMatch(/(?:qupzilla)[\s/](\d+(\.?_?\d+)+)/i, ua) || getFirstMatch(commonVersionIdentifier, ua); | ||
if (version) { | ||
browser.version = version; | ||
} | ||
return browser; | ||
} | ||
}, | ||
{ | ||
test: [/firefox|iceweasel|fxios/i], | ||
describe(ua) { | ||
const browser = { | ||
name: BROWSER_MAP.firefox | ||
}; | ||
const version = getFirstMatch(/(?:firefox|iceweasel|fxios)[\s/](\d+(\.?_?\d+)+)/i, ua); | ||
if (version) { | ||
browser.version = version; | ||
} | ||
return browser; | ||
} | ||
}, | ||
{ | ||
test: [/electron/i], | ||
describe(ua) { | ||
const browser = { | ||
name: BROWSER_MAP.electron | ||
}; | ||
const version = getFirstMatch(/(?:electron)\/(\d+(\.?_?\d+)+)/i, ua); | ||
if (version) { | ||
browser.version = version; | ||
} | ||
return browser; | ||
} | ||
}, | ||
{ | ||
test: [/MiuiBrowser/i], | ||
describe(ua) { | ||
const browser = { | ||
name: BROWSER_MAP.miui | ||
}; | ||
const version = getFirstMatch(/(?:MiuiBrowser)[\s/](\d+(\.?_?\d+)+)/i, ua); | ||
if (version) { | ||
browser.version = version; | ||
} | ||
return browser; | ||
} | ||
}, | ||
{ | ||
test: [/chromium/i], | ||
describe(ua) { | ||
const browser = { | ||
name: BROWSER_MAP.chromium | ||
}; | ||
const version = getFirstMatch(/(?:chromium)[\s/](\d+(\.?_?\d+)+)/i, ua) || getFirstMatch(commonVersionIdentifier, ua); | ||
if (version) { | ||
browser.version = version; | ||
} | ||
return browser; | ||
} | ||
}, | ||
{ | ||
test: [/chrome|crios|crmo/i], | ||
describe(ua) { | ||
const browser = { | ||
name: BROWSER_MAP.chrome | ||
}; | ||
const version = getFirstMatch(/(?:chrome|crios|crmo)\/(\d+(\.?_?\d+)+)/i, ua); | ||
if (version) { | ||
browser.version = version; | ||
} | ||
return browser; | ||
} | ||
}, | ||
{ | ||
test: [/GSA/i], | ||
describe(ua) { | ||
const browser = { | ||
name: BROWSER_MAP.google_search | ||
}; | ||
const version = getFirstMatch(/(?:GSA)\/(\d+(\.?_?\d+)+)/i, ua); | ||
if (version) { | ||
browser.version = version; | ||
} | ||
return browser; | ||
} | ||
}, | ||
{ | ||
test(parser) { | ||
const notLikeAndroid = !parser.test(/like android/i); | ||
const butAndroid = parser.test(/android/i); | ||
return notLikeAndroid && butAndroid; | ||
}, | ||
describe(ua) { | ||
const browser = { | ||
name: BROWSER_MAP.android | ||
}; | ||
const version = getFirstMatch(commonVersionIdentifier, ua); | ||
if (version) { | ||
browser.version = version; | ||
} | ||
return browser; | ||
} | ||
}, | ||
{ | ||
test: [/playstation 4/i], | ||
describe(ua) { | ||
const browser = { | ||
name: BROWSER_MAP.ps4 | ||
}; | ||
const version = getFirstMatch(commonVersionIdentifier, ua); | ||
if (version) { | ||
browser.version = version; | ||
} | ||
return browser; | ||
} | ||
}, | ||
{ | ||
test: [/safari|applewebkit/i], | ||
describe(ua) { | ||
const browser = { | ||
name: BROWSER_MAP.safari | ||
}; | ||
const version = getFirstMatch(commonVersionIdentifier, ua); | ||
if (version) { | ||
browser.version = version; | ||
} | ||
return browser; | ||
} | ||
}, | ||
{ | ||
test: [/.*/i], | ||
describe(ua) { | ||
const regexpWithoutDeviceSpec = /^(.*)\/(.*) /; | ||
const regexpWithDeviceSpec = /^(.*)\/(.*)[ \t]\((.*)/; | ||
const hasDeviceSpec = ua.search("\\(") !== -1; | ||
const regexp = hasDeviceSpec ? regexpWithDeviceSpec : regexpWithoutDeviceSpec; | ||
return { | ||
name: getFirstMatch(regexp, ua), | ||
version: getSecondMatch(regexp, ua) | ||
}; | ||
} | ||
} | ||
]; | ||
function getVersionPrecision(version) { | ||
return version.split(".").length; | ||
} | ||
function compareVersions(versionA, versionB, isLoose = false) { | ||
const versionAPrecision = getVersionPrecision(versionA); | ||
const versionBPrecision = getVersionPrecision(versionB); | ||
let precision = Math.max(versionAPrecision, versionBPrecision); | ||
let lastPrecision = 0; | ||
const chunks = [versionA, versionB].map((version) => { | ||
const delta = precision - getVersionPrecision(version); | ||
const _version = version + new Array(delta + 1).join(".0"); | ||
return _version.split(".").map((chunk) => new Array(20 - chunk.length).join("0") + chunk).reverse(); | ||
}); | ||
if (isLoose) { | ||
lastPrecision = precision - Math.min(versionAPrecision, versionBPrecision); | ||
} | ||
precision -= 1; | ||
while (precision >= lastPrecision) { | ||
if (chunks[0][precision] > chunks[1][precision]) { | ||
return 1; | ||
} | ||
if (chunks[0][precision] === chunks[1][precision]) { | ||
if (precision === lastPrecision) { | ||
return 0; | ||
} | ||
precision -= 1; | ||
} else if (chunks[0][precision] < chunks[1][precision]) { | ||
return -1; | ||
} | ||
} | ||
return void 0; | ||
} | ||
function getBrowserTypeByAlias(browserAlias) { | ||
if (browserAlias in BROWSER_MAP) { | ||
return BROWSER_MAP[browserAlias]; | ||
} | ||
return ""; | ||
} | ||
function browserParser(parser) { | ||
let result = {}; | ||
const browserDescriptor = browsersList.find((candidate) => { | ||
if (typeof candidate.test === "function") { | ||
return candidate.test(parser); | ||
} | ||
if (candidate.test instanceof Array) { | ||
return candidate.test.some((condition) => parser.test(condition)); | ||
} | ||
throw new Error("Browser's test function is not valid"); | ||
}); | ||
if (browserDescriptor) { | ||
result = browserDescriptor.describe(parser.getUA()); | ||
} | ||
return { browser: result }; | ||
} | ||
function getBrowser(parser) { | ||
try { | ||
return parser.getResult().browser; | ||
} catch (e) { | ||
return browserParser(parser).browser; | ||
} | ||
} | ||
function getBrowserName(parser, toLowerCase = false) { | ||
var _a, _b; | ||
if (toLowerCase) { | ||
return ((_a = getBrowser(parser).name) != null ? _a : "").toLowerCase(); | ||
} | ||
return (_b = getBrowser(parser).name) != null ? _b : ""; | ||
} | ||
function getBrowserVersion(parser) { | ||
var _a; | ||
return (_a = getBrowser(parser).version) != null ? _a : ""; | ||
} | ||
function isBrowser(parser, browserName, includingAlias = false) { | ||
const defaultBrowserName = getBrowserName(parser, true); | ||
let browserNameLower = browserName.toLowerCase(); | ||
const alias = getBrowserTypeByAlias(browserNameLower); | ||
if (includingAlias && alias) { | ||
browserNameLower = alias.toLowerCase(); | ||
} | ||
return browserNameLower === defaultBrowserName; | ||
} | ||
function compareVersion(parser, version) { | ||
var _a; | ||
let expectedResults = [0]; | ||
let comparableVersion = version; | ||
let isLoose = false; | ||
const currentBrowserVersion = getBrowserVersion(parser); | ||
if (typeof currentBrowserVersion !== "string") { | ||
return false; | ||
} | ||
if (version[0] === ">" || version[0] === "<") { | ||
comparableVersion = version.substr(1); | ||
if (version[1] === "=") { | ||
isLoose = true; | ||
comparableVersion = version.substr(2); | ||
} else { | ||
expectedResults = []; | ||
} | ||
if (version[0] === ">") { | ||
expectedResults.push(1); | ||
} else { | ||
expectedResults.push(-1); | ||
} | ||
} else if (version[0] === "=") { | ||
comparableVersion = version.substr(1); | ||
} else if (version[0] === "~") { | ||
isLoose = true; | ||
comparableVersion = version.substr(1); | ||
} | ||
return expectedResults.indexOf((_a = compareVersions(currentBrowserVersion, comparableVersion, isLoose)) != null ? _a : Infinity) > -1; | ||
} | ||
export { BROWSER_ALIASES_MAP, BROWSER_MAP, browserParser, compareVersion, getBrowser, getBrowserName, getBrowserVersion, isBrowser }; | ||
export { e as BROWSER_ALIASES_MAP, B as BROWSER_MAP, b as browserParser, d as compareVersion, g as getBrowser, a as getBrowserName, c as getBrowserVersion, i as isBrowser } from "./browserParser.js"; | ||
import "./utils.js"; |
@@ -1,1 +0,1 @@ | ||
(function(d,m){typeof exports=="object"&&typeof module!="undefined"?m(exports):typeof define=="function"&&define.amd?define(["exports"],m):(d=typeof globalThis!="undefined"?globalThis:d||self,m(d["Bowser-Jr-Browser"]={}))})(this,function(d){"use strict";const m={"Amazon Silk":"amazon_silk","Android Browser":"android",Bada:"bada",BlackBerry:"blackberry",Chrome:"chrome",Chromium:"chromium",Electron:"electron",Epiphany:"epiphany",Firefox:"firefox",Focus:"focus",Generic:"generic","Google Search":"google_search",Googlebot:"googlebot","Internet Explorer":"ie","K-Meleon":"k_meleon",Maxthon:"maxthon",Miui:"miui","Microsoft Edge":"edge","MZ Browser":"mz","NAVER Whale Browser":"naver",Opera:"opera","Opera Coast":"opera_coast","Opera Touch":"opera_touch",PhantomJS:"phantomjs","PlayStation 4":"ps4",Puffin:"puffin",QupZilla:"qupzilla",QQ:"qq",QQLite:"qqlite",Safari:"safari",Sailfish:"sailfish","Samsung Internet for Android":"samsung_internet",SeaMonkey:"seamonkey",Sleipnir:"sleipnir",SlimerJS:"slimerjs",Swing:"swing",Tizen:"tizen","UC Browser":"uc",Vivaldi:"vivaldi","WebOS Browser":"webos",WeChat:"wechat","Yandex Browser":"yandex",Roku:"roku"},o={amazon_silk:"Amazon Silk",android:"Android Browser",bada:"Bada",blackberry:"BlackBerry",chrome:"Chrome",chromium:"Chromium",electron:"Electron",epiphany:"Epiphany",firefox:"Firefox",focus:"Focus",generic:"Generic",googlebot:"Googlebot",google_search:"Google Search",ie:"Internet Explorer",k_meleon:"K-Meleon",maxthon:"Maxthon",miui:"Miui",edge:"Microsoft Edge",mz:"MZ Browser",naver:"NAVER Whale Browser",opera:"Opera",opera_coast:"Opera Coast",opera_touch:"Opera Touch",phantomjs:"PhantomJS",ps4:"PlayStation 4",puffin:"Puffin",qupzilla:"QupZilla",qq:"QQ Browser",qqlite:"QQ Browser Lite",safari:"Safari",sailfish:"Sailfish",samsung_internet:"Samsung Internet for Android",seamonkey:"SeaMonkey",sleipnir:"Sleipnir",slimerjs:"SlimerJS",swing:"Swing",tizen:"Tizen",uc:"UC Browser",vivaldi:"Vivaldi",webos:"WebOS Browser",wechat:"WeChat",yandex:"Yandex Browser"};function i(s,e){const r=e.match(s);return r&&r.length>0&&r[1]||""}function w(s,e){const r=e.match(s);return r&&r.length>1&&r[2]||""}const n=/version\/(\d+(\.?_?\d+)+)/i,S=[{test:[/googlebot/i],describe(s){const e={name:o.googlebot},r=i(/googlebot\/(\d+(\.\d+))/i,s)||i(n,s);return r&&(e.version=r),e}},{test:[/opera/i],describe(s){const e={name:o.opera},r=i(n,s)||i(/(?:opera)[\s/](\d+(\.?_?\d+)+)/i,s);return r&&(e.version=r),e}},{test:[/opr\/|opios/i],describe(s){const e={name:o.opera},r=i(/(?:opr|opios)[\s/](\S+)/i,s)||i(n,s);return r&&(e.version=r),e}},{test:[/SamsungBrowser/i],describe(s){const e={name:o.samsung_internet},r=i(n,s)||i(/(?:SamsungBrowser)[\s/](\d+(\.?_?\d+)+)/i,s);return r&&(e.version=r),e}},{test:[/Whale/i],describe(s){const e={name:o.naver},r=i(n,s)||i(/(?:whale)[\s/](\d+(?:\.\d+)+)/i,s);return r&&(e.version=r),e}},{test:[/MZBrowser/i],describe(s){const e={name:o.mz},r=i(/(?:MZBrowser)[\s/](\d+(?:\.\d+)+)/i,s)||i(n,s);return r&&(e.version=r),e}},{test:[/focus/i],describe(s){const e={name:o.focus},r=i(/(?:focus)[\s/](\d+(?:\.\d+)+)/i,s)||i(n,s);return r&&(e.version=r),e}},{test:[/swing/i],describe(s){const e={name:o.swing},r=i(/(?:swing)[\s/](\d+(?:\.\d+)+)/i,s)||i(n,s);return r&&(e.version=r),e}},{test:[/coast/i],describe(s){const e={name:o.opera_coast},r=i(n,s)||i(/(?:coast)[\s/](\d+(\.?_?\d+)+)/i,s);return r&&(e.version=r),e}},{test:[/opt\/\d+(?:.?_?\d+)+/i],describe(s){const e={name:o.opera_touch},r=i(/(?:opt)[\s/](\d+(\.?_?\d+)+)/i,s)||i(n,s);return r&&(e.version=r),e}},{test:[/yabrowser/i],describe(s){const e={name:o.yandex},r=i(/(?:yabrowser)[\s/](\d+(\.?_?\d+)+)/i,s)||i(n,s);return r&&(e.version=r),e}},{test:[/ucbrowser/i],describe(s){const e={name:o.uc},r=i(n,s)||i(/(?:ucbrowser)[\s/](\d+(\.?_?\d+)+)/i,s);return r&&(e.version=r),e}},{test:[/Maxthon|mxios/i],describe(s){const e={name:o.maxthon},r=i(n,s)||i(/(?:Maxthon|mxios)[\s/](\d+(\.?_?\d+)+)/i,s);return r&&(e.version=r),e}},{test:[/epiphany/i],describe(s){const e={name:o.epiphany},r=i(n,s)||i(/(?:epiphany)[\s/](\d+(\.?_?\d+)+)/i,s);return r&&(e.version=r),e}},{test:[/puffin/i],describe(s){const e={name:o.puffin},r=i(n,s)||i(/(?:puffin)[\s/](\d+(\.?_?\d+)+)/i,s);return r&&(e.version=r),e}},{test:[/sleipnir/i],describe(s){const e={name:o.sleipnir},r=i(n,s)||i(/(?:sleipnir)[\s/](\d+(\.?_?\d+)+)/i,s);return r&&(e.version=r),e}},{test:[/k-meleon/i],describe(s){const e={name:o.k_meleon},r=i(n,s)||i(/(?:k-meleon)[\s/](\d+(\.?_?\d+)+)/i,s);return r&&(e.version=r),e}},{test:[/micromessenger/i],describe(s){const e={name:o.wechat},r=i(/(?:micromessenger)[\s/](\d+(\.?_?\d+)+)/i,s)||i(n,s);return r&&(e.version=r),e}},{test:[/qqbrowser/i],describe(s){const e={name:/qqbrowserlite/i.test(s)?o.qqlite:o.qq},r=i(/(?:qqbrowserlite|qqbrowser)[/](\d+(\.?_?\d+)+)/i,s)||i(n,s);return r&&(e.version=r),e}},{test:[/msie|trident/i],describe(s){const e={name:o.ie},r=i(/(?:msie |rv:)(\d+(\.?_?\d+)+)/i,s);return r&&(e.version=r),e}},{test:[/\sedg\//i],describe(s){const e={name:o.edge},r=i(/\sedg\/(\d+(\.?_?\d+)+)/i,s);return r&&(e.version=r),e}},{test:[/edg([ea]|ios)/i],describe(s){const e={name:o.edge},r=w(/edg([ea]|ios)\/(\d+(\.?_?\d+)+)/i,s);return r&&(e.version=r),e}},{test:[/vivaldi/i],describe(s){const e={name:o.vivaldi},r=i(/vivaldi\/(\d+(\.?_?\d+)+)/i,s);return r&&(e.version=r),e}},{test:[/seamonkey/i],describe(s){const e={name:o.seamonkey},r=i(/seamonkey\/(\d+(\.?_?\d+)+)/i,s);return r&&(e.version=r),e}},{test:[/sailfish/i],describe(s){const e={name:o.sailfish},r=i(/sailfish\s?browser\/(\d+(\.\d+)?)/i,s);return r&&(e.version=r),e}},{test:[/silk/i],describe(s){const e={name:o.amazon_silk},r=i(/silk\/(\d+(\.?_?\d+)+)/i,s);return r&&(e.version=r),e}},{test:[/phantom/i],describe(s){const e={name:o.phantomjs},r=i(/phantomjs\/(\d+(\.?_?\d+)+)/i,s);return r&&(e.version=r),e}},{test:[/slimerjs/i],describe(s){const e={name:o.slimerjs},r=i(/slimerjs\/(\d+(\.?_?\d+)+)/i,s);return r&&(e.version=r),e}},{test:[/blackberry|\bbb\d+/i,/rim\stablet/i],describe(s){const e={name:o.blackberry},r=i(n,s)||i(/blackberry[\d]+\/(\d+(\.?_?\d+)+)/i,s);return r&&(e.version=r),e}},{test:[/(web|hpw)[o0]s/i],describe(s){const e={name:o.webos},r=i(n,s)||i(/w(?:eb)?[o0]sbrowser\/(\d+(\.?_?\d+)+)/i,s);return r&&(e.version=r),e}},{test:[/bada/i],describe(s){const e={name:o.bada},r=i(/dolfin\/(\d+(\.?_?\d+)+)/i,s);return r&&(e.version=r),e}},{test:[/tizen/i],describe(s){const e={name:o.tizen},r=i(/(?:tizen\s?)?browser\/(\d+(\.?_?\d+)+)/i,s)||i(n,s);return r&&(e.version=r),e}},{test:[/qupzilla/i],describe(s){const e={name:o.qupzilla},r=i(/(?:qupzilla)[\s/](\d+(\.?_?\d+)+)/i,s)||i(n,s);return r&&(e.version=r),e}},{test:[/firefox|iceweasel|fxios/i],describe(s){const e={name:o.firefox},r=i(/(?:firefox|iceweasel|fxios)[\s/](\d+(\.?_?\d+)+)/i,s);return r&&(e.version=r),e}},{test:[/electron/i],describe(s){const e={name:o.electron},r=i(/(?:electron)\/(\d+(\.?_?\d+)+)/i,s);return r&&(e.version=r),e}},{test:[/MiuiBrowser/i],describe(s){const e={name:o.miui},r=i(/(?:MiuiBrowser)[\s/](\d+(\.?_?\d+)+)/i,s);return r&&(e.version=r),e}},{test:[/chromium/i],describe(s){const e={name:o.chromium},r=i(/(?:chromium)[\s/](\d+(\.?_?\d+)+)/i,s)||i(n,s);return r&&(e.version=r),e}},{test:[/chrome|crios|crmo/i],describe(s){const e={name:o.chrome},r=i(/(?:chrome|crios|crmo)\/(\d+(\.?_?\d+)+)/i,s);return r&&(e.version=r),e}},{test:[/GSA/i],describe(s){const e={name:o.google_search},r=i(/(?:GSA)\/(\d+(\.?_?\d+)+)/i,s);return r&&(e.version=r),e}},{test(s){const e=!s.test(/like android/i),r=s.test(/android/i);return e&&r},describe(s){const e={name:o.android},r=i(n,s);return r&&(e.version=r),e}},{test:[/playstation 4/i],describe(s){const e={name:o.ps4},r=i(n,s);return r&&(e.version=r),e}},{test:[/safari|applewebkit/i],describe(s){const e={name:o.safari},r=i(n,s);return r&&(e.version=r),e}},{test:[/.*/i],describe(s){const e=/^(.*)\/(.*) /,r=/^(.*)\/(.*)[ \t]\((.*)/,a=s.search("\\(")!==-1?r:e;return{name:i(a,s),version:w(a,s)}}}];function u(s){return s.split(".").length}function B(s,e,r=!1){const t=u(s),a=u(e);let c=Math.max(t,a),f=0;const b=[s,e].map(g=>{const x=c-u(g);return(g+new Array(x+1).join(".0")).split(".").map(_=>new Array(20-_.length).join("0")+_).reverse()});for(r&&(f=c-Math.min(t,a)),c-=1;c>=f;){if(b[0][c]>b[1][c])return 1;if(b[0][c]===b[1][c]){if(c===f)return 0;c-=1}else if(b[0][c]<b[1][c])return-1}}function y(s){return s in o?o[s]:""}function v(s){let e={};const r=S.find(t=>{if(typeof t.test=="function")return t.test(s);if(t.test instanceof Array)return t.test.some(a=>s.test(a));throw new Error("Browser's test function is not valid")});return r&&(e=r.describe(s.getUA())),{browser:e}}function l(s){try{return s.getResult().browser}catch(e){return v(s).browser}}function p(s,e=!1){var r,t;return e?((r=l(s).name)!=null?r:"").toLowerCase():(t=l(s).name)!=null?t:""}function h(s){var e;return(e=l(s).version)!=null?e:""}function k(s,e,r=!1){const t=p(s,!0);let a=e.toLowerCase();const c=y(a);return r&&c&&(a=c.toLowerCase()),a===t}function M(s,e){var f;let r=[0],t=e,a=!1;const c=h(s);return typeof c!="string"?!1:(e[0]===">"||e[0]==="<"?(t=e.substr(1),e[1]==="="?(a=!0,t=e.substr(2)):r=[],e[0]===">"?r.push(1):r.push(-1)):e[0]==="="?t=e.substr(1):e[0]==="~"&&(a=!0,t=e.substr(1)),r.indexOf((f=B(c,t,a))!=null?f:1/0)>-1)}d.BROWSER_ALIASES_MAP=m,d.BROWSER_MAP=o,d.browserParser=v,d.compareVersion=M,d.getBrowser=l,d.getBrowserName=p,d.getBrowserVersion=h,d.isBrowser=k,Object.defineProperties(d,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}); | ||
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});var r=require("./browserParser.js");require("./utils.js");exports.BROWSER_ALIASES_MAP=r.BROWSER_ALIASES_MAP;exports.BROWSER_MAP=r.BROWSER_MAP;exports.browserParser=r.browserParser;exports.compareVersion=r.compareVersion;exports.getBrowser=r.getBrowser;exports.getBrowserName=r.getBrowserName;exports.getBrowserVersion=r.getBrowserVersion;exports.isBrowser=r.isBrowser; |
@@ -1,1 +0,159 @@ | ||
import { B as BROWSER_MAP, b as browserParser, g as getBrowser, a as getBrowserName, c as getBrowserVersion, i as isBrowser, d as compareVersion } from "./browserParser.js"; | ||
import { E as ENGINE_MAP, e as engineParser, g as getEngine, a as getEngineName, i as isEngine } from "./engineParser.js"; | ||
import { O as OS_MAP, o as osParser, g as getOS, a as getOSName, b as getOSVersion, i as isOS } from "./osParser.js"; | ||
import { g as getParser, i as isAnything, a as isSome } from "./parser.js"; | ||
import { P as PLATFORMS_MAP, p as platformParser, g as getPlatform, a as getPlatformType, i as isPlatform } from "./platformParser.js"; | ||
import "./utils.js"; | ||
class CompatParser { | ||
constructor(UA, skipParsing = false) { | ||
this.parser = getParser(UA, { | ||
use: [browserParser, engineParser, osParser, platformParser], | ||
skipParsing | ||
}); | ||
} | ||
getUA() { | ||
return this.parser.getUA(); | ||
} | ||
test(regex) { | ||
return this.parser.test(regex); | ||
} | ||
parseBrowser() { | ||
return getBrowser(this.parser); | ||
} | ||
getBrowser() { | ||
return getBrowser(this.parser); | ||
} | ||
getBrowserName(toLowerCase = false) { | ||
return getBrowserName(this.parser, toLowerCase); | ||
} | ||
getBrowserVersion() { | ||
return getBrowserVersion(this.parser); | ||
} | ||
getOS() { | ||
return getOS(this.parser); | ||
} | ||
parseOS() { | ||
return getOS(this.parser); | ||
} | ||
getOSName(toLowerCase = false) { | ||
return getOSName(this.parser, toLowerCase); | ||
} | ||
getOSVersion() { | ||
return getOSVersion(this.parser); | ||
} | ||
getPlatform() { | ||
getPlatform(this.parser); | ||
} | ||
getPlatformType(_toLowerCase = false) { | ||
return getPlatformType(this.parser); | ||
} | ||
parsePlatform() { | ||
return getPlatform(this.parser); | ||
} | ||
getEngine() { | ||
return getEngine(this.parser); | ||
} | ||
getEngineName(toLowerCase = false) { | ||
return getEngineName(this.parser, toLowerCase); | ||
} | ||
parseEngine() { | ||
return getEngine(this.parser); | ||
} | ||
parse() { | ||
this.parseBrowser(); | ||
this.parseOS(); | ||
this.parsePlatform(); | ||
this.parseEngine(); | ||
return this; | ||
} | ||
getResult() { | ||
return this.parser.getResult(); | ||
} | ||
satisfies(checkTree) { | ||
const platformsAndOSes = {}; | ||
let platformsAndOSCounter = 0; | ||
const browsers = {}; | ||
let browsersCounter = 0; | ||
const allDefinitions = Object.keys(checkTree); | ||
allDefinitions.forEach((key) => { | ||
const currentDefinition = checkTree[key]; | ||
if (typeof currentDefinition === "string") { | ||
browsers[key] = currentDefinition; | ||
browsersCounter += 1; | ||
} else if (typeof currentDefinition === "object") { | ||
platformsAndOSes[key] = currentDefinition; | ||
platformsAndOSCounter += 1; | ||
} | ||
}); | ||
if (platformsAndOSCounter > 0) { | ||
const platformsAndOSNames = Object.keys(platformsAndOSes); | ||
const OSMatchingDefinition = platformsAndOSNames.find((name) => this.isOS(name)); | ||
if (OSMatchingDefinition) { | ||
const osResult = this.satisfies(platformsAndOSes[OSMatchingDefinition]); | ||
if (osResult !== void 0) { | ||
return osResult; | ||
} | ||
} | ||
const platformMatchingDefinition = platformsAndOSNames.find((name) => this.isPlatform(name)); | ||
if (platformMatchingDefinition) { | ||
const platformResult = this.satisfies(platformsAndOSes[platformMatchingDefinition]); | ||
if (platformResult !== void 0) { | ||
return platformResult; | ||
} | ||
} | ||
} | ||
if (browsersCounter > 0) { | ||
const browserNames = Object.keys(browsers); | ||
const matchingDefinition = browserNames.find((name) => this.isBrowser(name, true)); | ||
if (matchingDefinition !== void 0) { | ||
return this.compareVersion(browsers[matchingDefinition]); | ||
} | ||
} | ||
return void 0; | ||
} | ||
isBrowser(browserName, includingAlias = false) { | ||
return isBrowser(this.parser, browserName, includingAlias); | ||
} | ||
compareVersion(version) { | ||
return compareVersion(this.parser, version); | ||
} | ||
isOS(osName) { | ||
return isOS(this.parser, osName); | ||
} | ||
isPlatform(platformType) { | ||
return isPlatform(this.parser, platformType); | ||
} | ||
isEngine(engineName) { | ||
return isEngine(this.parser, engineName); | ||
} | ||
is(anything, includingAlias = false) { | ||
return isAnything(this.parser, anything, (parser, name) => isBrowser(parser, name, includingAlias), isPlatform, isOS); | ||
} | ||
some(anythings = []) { | ||
return isSome(this.parser, anythings, isBrowser, isPlatform, isOS); | ||
} | ||
} | ||
class BowserCompat { | ||
static getParser(UA, skipParsing = false) { | ||
if (typeof UA !== "string") { | ||
throw new Error("UserAgent should be a string"); | ||
} | ||
return new CompatParser(UA, skipParsing); | ||
} | ||
static parse(UA) { | ||
return new CompatParser(UA).getResult(); | ||
} | ||
static get BROWSER_MAP() { | ||
return BROWSER_MAP; | ||
} | ||
static get ENGINE_MAP() { | ||
return ENGINE_MAP; | ||
} | ||
static get OS_MAP() { | ||
return OS_MAP; | ||
} | ||
static get PLATFORMS_MAP() { | ||
return PLATFORMS_MAP; | ||
} | ||
} | ||
export { BowserCompat as default }; |
@@ -1,1 +0,1 @@ | ||
(function(n){typeof define=="function"&&define.amd?define(n):n()})(function(){"use strict"}); | ||
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});var t=require("./browserParser.js"),u=require("./engineParser.js"),a=require("./osParser.js"),l=require("./parser.js"),n=require("./platformParser.js");require("./utils.js");class m{constructor(r,e=!1){this.parser=l.getParser(r,{use:[t.browserParser,u.engineParser,a.osParser,n.platformParser],skipParsing:e})}getUA(){return this.parser.getUA()}test(r){return this.parser.test(r)}parseBrowser(){return t.getBrowser(this.parser)}getBrowser(){return t.getBrowser(this.parser)}getBrowserName(r=!1){return t.getBrowserName(this.parser,r)}getBrowserVersion(){return t.getBrowserVersion(this.parser)}getOS(){return a.getOS(this.parser)}parseOS(){return a.getOS(this.parser)}getOSName(r=!1){return a.getOSName(this.parser,r)}getOSVersion(){return a.getOSVersion(this.parser)}getPlatform(){n.getPlatform(this.parser)}getPlatformType(r=!1){return n.getPlatformType(this.parser)}parsePlatform(){return n.getPlatform(this.parser)}getEngine(){return u.getEngine(this.parser)}getEngineName(r=!1){return u.getEngineName(this.parser,r)}parseEngine(){return u.getEngine(this.parser)}parse(){return this.parseBrowser(),this.parseOS(),this.parsePlatform(),this.parseEngine(),this}getResult(){return this.parser.getResult()}satisfies(r){const e={};let f=0;const g={};let h=0;if(Object.keys(r).forEach(o=>{const s=r[o];typeof s=="string"?(g[o]=s,h+=1):typeof s=="object"&&(e[o]=s,f+=1)}),f>0){const o=Object.keys(e),s=o.find(i=>this.isOS(i));if(s){const i=this.satisfies(e[s]);if(i!==void 0)return i}const p=o.find(i=>this.isPlatform(i));if(p){const i=this.satisfies(e[p]);if(i!==void 0)return i}}if(h>0){const s=Object.keys(g).find(p=>this.isBrowser(p,!0));if(s!==void 0)return this.compareVersion(g[s])}}isBrowser(r,e=!1){return t.isBrowser(this.parser,r,e)}compareVersion(r){return t.compareVersion(this.parser,r)}isOS(r){return a.isOS(this.parser,r)}isPlatform(r){return n.isPlatform(this.parser,r)}isEngine(r){return u.isEngine(this.parser,r)}is(r,e=!1){return l.isAnything(this.parser,r,(f,g)=>t.isBrowser(f,g,e),n.isPlatform,a.isOS)}some(r=[]){return l.isSome(this.parser,r,t.isBrowser,n.isPlatform,a.isOS)}}class c{static getParser(r,e=!1){if(typeof r!="string")throw new Error("UserAgent should be a string");return new m(r,e)}static parse(r){return new m(r).getResult()}static get BROWSER_MAP(){return t.BROWSER_MAP}static get ENGINE_MAP(){return u.ENGINE_MAP}static get OS_MAP(){return a.OS_MAP}static get PLATFORMS_MAP(){return n.PLATFORMS_MAP}}exports.default=c; |
@@ -1,130 +0,2 @@ | ||
const ENGINE_MAP = { | ||
EdgeHTML: "EdgeHTML", | ||
Blink: "Blink", | ||
Trident: "Trident", | ||
Presto: "Presto", | ||
Gecko: "Gecko", | ||
WebKit: "WebKit" | ||
}; | ||
function getFirstMatch(regexp, ua) { | ||
const match = ua.match(regexp); | ||
return match && match.length > 0 && match[1] || ""; | ||
} | ||
const enginesList = [ | ||
{ | ||
test: [/edg([ea]|ios)/i, /\sedg\//i], | ||
describe(ua) { | ||
const isBlinkBased = /\sedg\//i.test(ua); | ||
if (isBlinkBased) { | ||
return { | ||
name: ENGINE_MAP.Blink | ||
}; | ||
} | ||
const version = getFirstMatch(/edge\/(\d+(\.?_?\d+)+)/i, ua); | ||
return { | ||
name: ENGINE_MAP.EdgeHTML, | ||
version | ||
}; | ||
} | ||
}, | ||
{ | ||
test: [/trident/i], | ||
describe(ua) { | ||
const engine = { | ||
name: ENGINE_MAP.Trident | ||
}; | ||
const version = getFirstMatch(/trident\/(\d+(\.?_?\d+)+)/i, ua); | ||
if (version) { | ||
engine.version = version; | ||
} | ||
return engine; | ||
} | ||
}, | ||
{ | ||
test(parser) { | ||
return parser.test(/presto/i); | ||
}, | ||
describe(ua) { | ||
const engine = { | ||
name: ENGINE_MAP.Presto | ||
}; | ||
const version = getFirstMatch(/presto\/(\d+(\.?_?\d+)+)/i, ua); | ||
if (version) { | ||
engine.version = version; | ||
} | ||
return engine; | ||
} | ||
}, | ||
{ | ||
test(parser) { | ||
const isGecko = parser.test(/gecko/i); | ||
const likeGecko = parser.test(/like gecko/i); | ||
return isGecko && !likeGecko; | ||
}, | ||
describe(ua) { | ||
const engine = { | ||
name: ENGINE_MAP.Gecko | ||
}; | ||
const version = getFirstMatch(/gecko\/(\d+(\.?_?\d+)+)/i, ua); | ||
if (version) { | ||
engine.version = version; | ||
} | ||
return engine; | ||
} | ||
}, | ||
{ | ||
test: [/(apple)?webkit\/537\.36/i], | ||
describe() { | ||
return { | ||
name: ENGINE_MAP.Blink | ||
}; | ||
} | ||
}, | ||
{ | ||
test: [/(apple)?webkit/i], | ||
describe(ua) { | ||
const engine = { | ||
name: ENGINE_MAP.WebKit | ||
}; | ||
const version = getFirstMatch(/webkit\/(\d+(\.?_?\d+)+)/i, ua); | ||
if (version) { | ||
engine.version = version; | ||
} | ||
return engine; | ||
} | ||
} | ||
]; | ||
function engineParser(parser) { | ||
let result = {}; | ||
const engineDescriptor = enginesList.find((candidate) => { | ||
if (typeof candidate.test === "function") { | ||
return candidate.test(parser); | ||
} | ||
if (candidate.test instanceof Array) { | ||
return candidate.test.some((condition) => parser.test(condition)); | ||
} | ||
throw new Error("Browser's test function is not valid"); | ||
}); | ||
if (engineDescriptor) { | ||
result = engineDescriptor.describe(parser.getUA()); | ||
} | ||
return { engine: result }; | ||
} | ||
function getEngine(parser) { | ||
try { | ||
return parser.getResult().engine; | ||
} catch (e) { | ||
return engineParser(parser).engine; | ||
} | ||
} | ||
function getEngineName(parser, toLowerCase = false) { | ||
var _a, _b; | ||
if (toLowerCase) { | ||
return ((_a = getEngine(parser).name) != null ? _a : "").toLowerCase(); | ||
} | ||
return (_b = getEngine(parser).name) != null ? _b : ""; | ||
} | ||
function isEngine(parser, engineName) { | ||
return getEngineName(parser, true) === engineName.toLowerCase(); | ||
} | ||
export { ENGINE_MAP, engineParser, getEngine, getEngineName, isEngine }; | ||
export { E as ENGINE_MAP, e as engineParser, g as getEngine, a as getEngineName, i as isEngine } from "./engineParser.js"; | ||
import "./utils.js"; |
@@ -1,1 +0,1 @@ | ||
(function(s,i){typeof exports=="object"&&typeof module!="undefined"?i(exports):typeof define=="function"&&define.amd?define(["exports"],i):(s=typeof globalThis!="undefined"?globalThis:s||self,i(s["Bowser-Jr-Engine"]={}))})(this,function(s){"use strict";const i={EdgeHTML:"EdgeHTML",Blink:"Blink",Trident:"Trident",Presto:"Presto",Gecko:"Gecko",WebKit:"WebKit"};function o(e,t){const n=t.match(e);return n&&n.length>0&&n[1]||""}const g=[{test:[/edg([ea]|ios)/i,/\sedg\//i],describe(e){if(/\sedg\//i.test(e))return{name:i.Blink};const n=o(/edge\/(\d+(\.?_?\d+)+)/i,e);return{name:i.EdgeHTML,version:n}}},{test:[/trident/i],describe(e){const t={name:i.Trident},n=o(/trident\/(\d+(\.?_?\d+)+)/i,e);return n&&(t.version=n),t}},{test(e){return e.test(/presto/i)},describe(e){const t={name:i.Presto},n=o(/presto\/(\d+(\.?_?\d+)+)/i,e);return n&&(t.version=n),t}},{test(e){const t=e.test(/gecko/i),n=e.test(/like gecko/i);return t&&!n},describe(e){const t={name:i.Gecko},n=o(/gecko\/(\d+(\.?_?\d+)+)/i,e);return n&&(t.version=n),t}},{test:[/(apple)?webkit\/537\.36/i],describe(){return{name:i.Blink}}},{test:[/(apple)?webkit/i],describe(e){const t={name:i.WebKit},n=o(/webkit\/(\d+(\.?_?\d+)+)/i,e);return n&&(t.version=n),t}}];function d(e){let t={};const n=g.find(r=>{if(typeof r.test=="function")return r.test(e);if(r.test instanceof Array)return r.test.some(l=>e.test(l));throw new Error("Browser's test function is not valid")});return n&&(t=n.describe(e.getUA())),{engine:t}}function c(e){try{return e.getResult().engine}catch(t){return d(e).engine}}function u(e,t=!1){var n,r;return t?((n=c(e).name)!=null?n:"").toLowerCase():(r=c(e).name)!=null?r:""}function f(e,t){return u(e,!0)===t.toLowerCase()}s.ENGINE_MAP=i,s.engineParser=d,s.getEngine=c,s.getEngineName=u,s.isEngine=f,Object.defineProperties(s,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}); | ||
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});var e=require("./engineParser.js");require("./utils.js");exports.ENGINE_MAP=e.ENGINE_MAP;exports.engineParser=e.engineParser;exports.getEngine=e.getEngine;exports.getEngineName=e.getEngineName;exports.isEngine=e.isEngine; |
@@ -1,321 +0,2 @@ | ||
const OS_MAP = { | ||
WindowsPhone: "Windows Phone", | ||
Windows: "Windows", | ||
MacOS: "macOS", | ||
iOS: "iOS", | ||
Android: "Android", | ||
WebOS: "WebOS", | ||
BlackBerry: "BlackBerry", | ||
Bada: "Bada", | ||
Tizen: "Tizen", | ||
Linux: "Linux", | ||
ChromeOS: "Chrome OS", | ||
PlayStation4: "PlayStation 4", | ||
Roku: "Roku" | ||
}; | ||
function getFirstMatch(regexp, ua) { | ||
const match = ua.match(regexp); | ||
return match && match.length > 0 && match[1] || ""; | ||
} | ||
function getSecondMatch(regexp, ua) { | ||
const match = ua.match(regexp); | ||
return match && match.length > 1 && match[2] || ""; | ||
} | ||
function getWindowsVersionName(version) { | ||
switch (version) { | ||
case "NT": | ||
return "NT"; | ||
case "XP": | ||
return "XP"; | ||
case "NT 5.0": | ||
return "2000"; | ||
case "NT 5.1": | ||
return "XP"; | ||
case "NT 5.2": | ||
return "2003"; | ||
case "NT 6.0": | ||
return "Vista"; | ||
case "NT 6.1": | ||
return "7"; | ||
case "NT 6.2": | ||
return "8"; | ||
case "NT 6.3": | ||
return "8.1"; | ||
case "NT 10.0": | ||
return "10"; | ||
default: | ||
return void 0; | ||
} | ||
} | ||
function getMacOSVersionName(version) { | ||
const v = version.split(".").splice(0, 2).map((s) => parseInt(s, 10) || 0); | ||
v.push(0); | ||
if (v[0] !== 10) | ||
return void 0; | ||
switch (v[1]) { | ||
case 5: | ||
return "Leopard"; | ||
case 6: | ||
return "Snow Leopard"; | ||
case 7: | ||
return "Lion"; | ||
case 8: | ||
return "Mountain Lion"; | ||
case 9: | ||
return "Mavericks"; | ||
case 10: | ||
return "Yosemite"; | ||
case 11: | ||
return "El Capitan"; | ||
case 12: | ||
return "Sierra"; | ||
case 13: | ||
return "High Sierra"; | ||
case 14: | ||
return "Mojave"; | ||
case 15: | ||
return "Catalina"; | ||
default: | ||
return void 0; | ||
} | ||
} | ||
function getAndroidVersionName(version) { | ||
const v = version.split(".").splice(0, 2).map((s) => parseInt(s, 10) || 0); | ||
v.push(0); | ||
if (v[0] === 1 && v[1] < 5) | ||
return void 0; | ||
if (v[0] === 1 && v[1] < 6) | ||
return "Cupcake"; | ||
if (v[0] === 1 && v[1] >= 6) | ||
return "Donut"; | ||
if (v[0] === 2 && v[1] < 2) | ||
return "Eclair"; | ||
if (v[0] === 2 && v[1] === 2) | ||
return "Froyo"; | ||
if (v[0] === 2 && v[1] > 2) | ||
return "Gingerbread"; | ||
if (v[0] === 3) | ||
return "Honeycomb"; | ||
if (v[0] === 4 && v[1] < 1) | ||
return "Ice Cream Sandwich"; | ||
if (v[0] === 4 && v[1] < 4) | ||
return "Jelly Bean"; | ||
if (v[0] === 4 && v[1] >= 4) | ||
return "KitKat"; | ||
if (v[0] === 5) | ||
return "Lollipop"; | ||
if (v[0] === 6) | ||
return "Marshmallow"; | ||
if (v[0] === 7) | ||
return "Nougat"; | ||
if (v[0] === 8) | ||
return "Oreo"; | ||
if (v[0] === 9) | ||
return "Pie"; | ||
return void 0; | ||
} | ||
const osList = [ | ||
{ | ||
test: [/Roku\/DVP/], | ||
describe(ua) { | ||
const version = getFirstMatch(/Roku\/DVP-(\d+\.\d+)/i, ua); | ||
return { | ||
name: OS_MAP.Roku, | ||
version | ||
}; | ||
} | ||
}, | ||
{ | ||
test: [/windows phone/i], | ||
describe(ua) { | ||
const version = getFirstMatch(/windows phone (?:os)?\s?(\d+(\.\d+)*)/i, ua); | ||
return { | ||
name: OS_MAP.WindowsPhone, | ||
version | ||
}; | ||
} | ||
}, | ||
{ | ||
test: [/windows /i], | ||
describe(ua) { | ||
const version = getFirstMatch(/Windows ((NT|XP)( \d\d?.\d)?)/i, ua); | ||
const versionName = getWindowsVersionName(version); | ||
return { | ||
name: OS_MAP.Windows, | ||
version, | ||
versionName | ||
}; | ||
} | ||
}, | ||
{ | ||
test: [/Macintosh(.*?) FxiOS(.*?)\//], | ||
describe(ua) { | ||
const result = { | ||
name: OS_MAP.iOS | ||
}; | ||
const version = getSecondMatch(/(Version\/)(\d[\d.]+)/, ua); | ||
if (version) { | ||
result.version = version; | ||
} | ||
return result; | ||
} | ||
}, | ||
{ | ||
test: [/macintosh/i], | ||
describe(ua) { | ||
const version = getFirstMatch(/mac os x (\d+(\.?_?\d+)+)/i, ua).replace(/[_\s]/g, "."); | ||
const versionName = getMacOSVersionName(version); | ||
const os = { | ||
name: OS_MAP.MacOS, | ||
version | ||
}; | ||
if (versionName) { | ||
os.versionName = versionName; | ||
} | ||
return os; | ||
} | ||
}, | ||
{ | ||
test: [/(ipod|iphone|ipad)/i], | ||
describe(ua) { | ||
const version = getFirstMatch(/os (\d+([_\s]\d+)*) like mac os x/i, ua).replace(/[_\s]/g, "."); | ||
return { | ||
name: OS_MAP.iOS, | ||
version | ||
}; | ||
} | ||
}, | ||
{ | ||
test(parser) { | ||
const notLikeAndroid = !parser.test(/like android/i); | ||
const butAndroid = parser.test(/android/i); | ||
return notLikeAndroid && butAndroid; | ||
}, | ||
describe(ua) { | ||
const version = getFirstMatch(/android[\s/-](\d+(\.\d+)*)/i, ua); | ||
const versionName = getAndroidVersionName(version); | ||
const os = { | ||
name: OS_MAP.Android, | ||
version | ||
}; | ||
if (versionName) { | ||
os.versionName = versionName; | ||
} | ||
return os; | ||
} | ||
}, | ||
{ | ||
test: [/(web|hpw)[o0]s/i], | ||
describe(ua) { | ||
const version = getFirstMatch(/(?:web|hpw)[o0]s\/(\d+(\.\d+)*)/i, ua); | ||
const os = { | ||
name: OS_MAP.WebOS | ||
}; | ||
if (version && version.length) { | ||
os.version = version; | ||
} | ||
return os; | ||
} | ||
}, | ||
{ | ||
test: [/blackberry|\bbb\d+/i, /rim\stablet/i], | ||
describe(ua) { | ||
const version = getFirstMatch(/rim\stablet\sos\s(\d+(\.\d+)*)/i, ua) || getFirstMatch(/blackberry\d+\/(\d+([_\s]\d+)*)/i, ua) || getFirstMatch(/\bbb(\d+)/i, ua); | ||
return { | ||
name: OS_MAP.BlackBerry, | ||
version | ||
}; | ||
} | ||
}, | ||
{ | ||
test: [/bada/i], | ||
describe(ua) { | ||
const version = getFirstMatch(/bada\/(\d+(\.\d+)*)/i, ua); | ||
return { | ||
name: OS_MAP.Bada, | ||
version | ||
}; | ||
} | ||
}, | ||
{ | ||
test: [/tizen/i], | ||
describe(ua) { | ||
const version = getFirstMatch(/tizen[/\s](\d+(\.\d+)*)/i, ua); | ||
return { | ||
name: OS_MAP.Tizen, | ||
version | ||
}; | ||
} | ||
}, | ||
{ | ||
test: [/linux/i], | ||
describe() { | ||
return { | ||
name: OS_MAP.Linux | ||
}; | ||
} | ||
}, | ||
{ | ||
test: [/CrOS/], | ||
describe() { | ||
return { | ||
name: OS_MAP.ChromeOS | ||
}; | ||
} | ||
}, | ||
{ | ||
test: [/PlayStation 4/], | ||
describe(ua) { | ||
const version = getFirstMatch(/PlayStation 4[/\s](\d+(\.\d+)*)/i, ua); | ||
return { | ||
name: OS_MAP.PlayStation4, | ||
version | ||
}; | ||
} | ||
} | ||
]; | ||
function osParser(parser) { | ||
let result = {}; | ||
const osDescriptor = osList.find((candidate) => { | ||
if (typeof candidate.test === "function") { | ||
return candidate.test(parser); | ||
} | ||
if (candidate.test instanceof Array) { | ||
return candidate.test.some((condition) => parser.test(condition)); | ||
} | ||
throw new Error("Browser's test function is not valid"); | ||
}); | ||
if (osDescriptor) { | ||
result = osDescriptor.describe(parser.getUA()); | ||
} | ||
return { os: result }; | ||
} | ||
function getOS(parser) { | ||
try { | ||
return parser.getResult().os; | ||
} catch (e) { | ||
return osParser(parser).os; | ||
} | ||
} | ||
function getOSName(parser, toLowerCase = false) { | ||
var _a, _b; | ||
if (toLowerCase) { | ||
return ((_a = getOS(parser).name) != null ? _a : "").toLowerCase(); | ||
} | ||
return (_b = getOS(parser).name) != null ? _b : ""; | ||
} | ||
function getOSVersion(parser) { | ||
var _a; | ||
return (_a = getOS(parser).version) != null ? _a : ""; | ||
} | ||
function getOSVersionName(parser, toLowerCase = false) { | ||
var _a, _b; | ||
if (toLowerCase) { | ||
return ((_a = getOS(parser).versionName) != null ? _a : "").toLowerCase(); | ||
} | ||
return (_b = getOS(parser).versionName) != null ? _b : ""; | ||
} | ||
function isOS(parser, osName) { | ||
return getOSName(parser, true) === osName.toLowerCase(); | ||
} | ||
export { OS_MAP, getOS, getOSName, getOSVersion, getOSVersionName, isOS, osParser }; | ||
export { O as OS_MAP, g as getOS, a as getOSName, b as getOSVersion, c as getOSVersionName, i as isOS, o as osParser } from "./osParser.js"; | ||
import "./utils.js"; |
@@ -1,1 +0,1 @@ | ||
(function(o,r){typeof exports=="object"&&typeof module!="undefined"?r(exports):typeof define=="function"&&define.amd?define(["exports"],r):(o=typeof globalThis!="undefined"?globalThis:o||self,r(o["Bowser-Jr-OS"]={}))})(this,function(o){"use strict";const r={WindowsPhone:"Windows Phone",Windows:"Windows",MacOS:"macOS",iOS:"iOS",Android:"Android",WebOS:"WebOS",BlackBerry:"BlackBerry",Bada:"Bada",Tizen:"Tizen",Linux:"Linux",ChromeOS:"Chrome OS",PlayStation4:"PlayStation 4",Roku:"Roku"};function s(n,e){const t=e.match(n);return t&&t.length>0&&t[1]||""}function d(n,e){const t=e.match(n);return t&&t.length>1&&t[2]||""}function f(n){switch(n){case"NT":return"NT";case"XP":return"XP";case"NT 5.0":return"2000";case"NT 5.1":return"XP";case"NT 5.2":return"2003";case"NT 6.0":return"Vista";case"NT 6.1":return"7";case"NT 6.2":return"8";case"NT 6.3":return"8.1";case"NT 10.0":return"10";default:return}}function m(n){const e=n.split(".").splice(0,2).map(t=>parseInt(t,10)||0);if(e.push(0),e[0]===10)switch(e[1]){case 5:return"Leopard";case 6:return"Snow Leopard";case 7:return"Lion";case 8:return"Mountain Lion";case 9:return"Mavericks";case 10:return"Yosemite";case 11:return"El Capitan";case 12:return"Sierra";case 13:return"High Sierra";case 14:return"Mojave";case 15:return"Catalina";default:return}}function l(n){const e=n.split(".").splice(0,2).map(t=>parseInt(t,10)||0);if(e.push(0),!(e[0]===1&&e[1]<5)){if(e[0]===1&&e[1]<6)return"Cupcake";if(e[0]===1&&e[1]>=6)return"Donut";if(e[0]===2&&e[1]<2)return"Eclair";if(e[0]===2&&e[1]===2)return"Froyo";if(e[0]===2&&e[1]>2)return"Gingerbread";if(e[0]===3)return"Honeycomb";if(e[0]===4&&e[1]<1)return"Ice Cream Sandwich";if(e[0]===4&&e[1]<4)return"Jelly Bean";if(e[0]===4&&e[1]>=4)return"KitKat";if(e[0]===5)return"Lollipop";if(e[0]===6)return"Marshmallow";if(e[0]===7)return"Nougat";if(e[0]===8)return"Oreo";if(e[0]===9)return"Pie"}}const S=[{test:[/Roku\/DVP/],describe(n){const e=s(/Roku\/DVP-(\d+\.\d+)/i,n);return{name:r.Roku,version:e}}},{test:[/windows phone/i],describe(n){const e=s(/windows phone (?:os)?\s?(\d+(\.\d+)*)/i,n);return{name:r.WindowsPhone,version:e}}},{test:[/windows /i],describe(n){const e=s(/Windows ((NT|XP)( \d\d?.\d)?)/i,n),t=f(e);return{name:r.Windows,version:e,versionName:t}}},{test:[/Macintosh(.*?) FxiOS(.*?)\//],describe(n){const e={name:r.iOS},t=d(/(Version\/)(\d[\d.]+)/,n);return t&&(e.version=t),e}},{test:[/macintosh/i],describe(n){const e=s(/mac os x (\d+(\.?_?\d+)+)/i,n).replace(/[_\s]/g,"."),t=m(e),i={name:r.MacOS,version:e};return t&&(i.versionName=t),i}},{test:[/(ipod|iphone|ipad)/i],describe(n){const e=s(/os (\d+([_\s]\d+)*) like mac os x/i,n).replace(/[_\s]/g,".");return{name:r.iOS,version:e}}},{test(n){const e=!n.test(/like android/i),t=n.test(/android/i);return e&&t},describe(n){const e=s(/android[\s/-](\d+(\.\d+)*)/i,n),t=l(e),i={name:r.Android,version:e};return t&&(i.versionName=t),i}},{test:[/(web|hpw)[o0]s/i],describe(n){const e=s(/(?:web|hpw)[o0]s\/(\d+(\.\d+)*)/i,n),t={name:r.WebOS};return e&&e.length&&(t.version=e),t}},{test:[/blackberry|\bbb\d+/i,/rim\stablet/i],describe(n){const e=s(/rim\stablet\sos\s(\d+(\.\d+)*)/i,n)||s(/blackberry\d+\/(\d+([_\s]\d+)*)/i,n)||s(/\bbb(\d+)/i,n);return{name:r.BlackBerry,version:e}}},{test:[/bada/i],describe(n){const e=s(/bada\/(\d+(\.\d+)*)/i,n);return{name:r.Bada,version:e}}},{test:[/tizen/i],describe(n){const e=s(/tizen[/\s](\d+(\.\d+)*)/i,n);return{name:r.Tizen,version:e}}},{test:[/linux/i],describe(){return{name:r.Linux}}},{test:[/CrOS/],describe(){return{name:r.ChromeOS}}},{test:[/PlayStation 4/],describe(n){const e=s(/PlayStation 4[/\s](\d+(\.\d+)*)/i,n);return{name:r.PlayStation4,version:e}}}];function c(n){let e={};const t=S.find(i=>{if(typeof i.test=="function")return i.test(n);if(i.test instanceof Array)return i.test.some(O=>n.test(O));throw new Error("Browser's test function is not valid")});return t&&(e=t.describe(n.getUA())),{os:e}}function a(n){try{return n.getResult().os}catch(e){return c(n).os}}function u(n,e=!1){var t,i;return e?((t=a(n).name)!=null?t:"").toLowerCase():(i=a(n).name)!=null?i:""}function b(n){var e;return(e=a(n).version)!=null?e:""}function h(n,e=!1){var t,i;return e?((t=a(n).versionName)!=null?t:"").toLowerCase():(i=a(n).versionName)!=null?i:""}function v(n,e){return u(n,!0)===e.toLowerCase()}o.OS_MAP=r,o.getOS=a,o.getOSName=u,o.getOSVersion=b,o.getOSVersionName=h,o.isOS=v,o.osParser=c,Object.defineProperties(o,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}); | ||
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});var e=require("./osParser.js");require("./utils.js");exports.OS_MAP=e.OS_MAP;exports.getOS=e.getOS;exports.getOSName=e.getOSName;exports.getOSVersion=e.getOSVersion;exports.getOSVersionName=e.getOSVersionName;exports.isOS=e.isOS;exports.osParser=e.osParser; |
@@ -1,272 +0,2 @@ | ||
const PLATFORMS_MAP = { | ||
tablet: "tablet", | ||
mobile: "mobile", | ||
desktop: "desktop", | ||
tv: "tv" | ||
}; | ||
function getFirstMatch(regexp, ua) { | ||
const match = ua.match(regexp); | ||
return match && match.length > 0 && match[1] || ""; | ||
} | ||
const platformsList = [ | ||
{ | ||
test: [/googlebot/i], | ||
describe() { | ||
return { | ||
type: "bot", | ||
vendor: "Google" | ||
}; | ||
} | ||
}, | ||
{ | ||
test: [/huawei/i], | ||
describe(ua) { | ||
const model = getFirstMatch(/(can-l01)/i, ua) && "Nova"; | ||
const platform = { | ||
type: PLATFORMS_MAP.mobile, | ||
vendor: "Huawei" | ||
}; | ||
if (model) { | ||
platform.model = model; | ||
} | ||
return platform; | ||
} | ||
}, | ||
{ | ||
test: [/nexus\s*(?:7|8|9|10).*/i], | ||
describe() { | ||
return { | ||
type: PLATFORMS_MAP.tablet, | ||
vendor: "Nexus" | ||
}; | ||
} | ||
}, | ||
{ | ||
test: [/ipad/i], | ||
describe() { | ||
return { | ||
type: PLATFORMS_MAP.tablet, | ||
vendor: "Apple", | ||
model: "iPad" | ||
}; | ||
} | ||
}, | ||
{ | ||
test: [/Macintosh(.*?) FxiOS(.*?)\//], | ||
describe() { | ||
return { | ||
type: PLATFORMS_MAP.tablet, | ||
vendor: "Apple", | ||
model: "iPad" | ||
}; | ||
} | ||
}, | ||
{ | ||
test: [/kftt build/i], | ||
describe() { | ||
return { | ||
type: PLATFORMS_MAP.tablet, | ||
vendor: "Amazon", | ||
model: "Kindle Fire HD 7" | ||
}; | ||
} | ||
}, | ||
{ | ||
test: [/silk/i], | ||
describe() { | ||
return { | ||
type: PLATFORMS_MAP.tablet, | ||
vendor: "Amazon" | ||
}; | ||
} | ||
}, | ||
{ | ||
test: [/tablet(?! pc)/i], | ||
describe() { | ||
return { | ||
type: PLATFORMS_MAP.tablet | ||
}; | ||
} | ||
}, | ||
{ | ||
test(parser) { | ||
const iDevice = parser.test(/ipod|iphone/i); | ||
const likeIDevice = parser.test(/like (ipod|iphone)/i); | ||
return iDevice && !likeIDevice; | ||
}, | ||
describe(ua) { | ||
const model = getFirstMatch(/(ipod|iphone)/i, ua); | ||
return { | ||
type: PLATFORMS_MAP.mobile, | ||
vendor: "Apple", | ||
model | ||
}; | ||
} | ||
}, | ||
{ | ||
test: [/nexus\s*[0-6].*/i, /galaxy nexus/i], | ||
describe() { | ||
return { | ||
type: PLATFORMS_MAP.mobile, | ||
vendor: "Nexus" | ||
}; | ||
} | ||
}, | ||
{ | ||
test: [/[^-]mobi/i], | ||
describe() { | ||
return { | ||
type: PLATFORMS_MAP.mobile | ||
}; | ||
} | ||
}, | ||
{ | ||
test: [/blackberry|\bbb\d+/i, /rim\stablet/i], | ||
describe() { | ||
return { | ||
type: PLATFORMS_MAP.mobile, | ||
vendor: "BlackBerry" | ||
}; | ||
} | ||
}, | ||
{ | ||
test: [/bada/i], | ||
describe() { | ||
return { | ||
type: PLATFORMS_MAP.mobile | ||
}; | ||
} | ||
}, | ||
{ | ||
test: [/windows phone/i], | ||
describe() { | ||
return { | ||
type: PLATFORMS_MAP.mobile, | ||
vendor: "Microsoft" | ||
}; | ||
} | ||
}, | ||
{ | ||
test(parser) { | ||
const notLikeAndroid = !parser.test(/like android/i); | ||
const butAndroid = parser.test(/android/i); | ||
const isAndroid = notLikeAndroid && butAndroid; | ||
const version = getFirstMatch(/android[\s/-](\d+(\.\d+)*)/i, parser.getUA()); | ||
const osMajorVersion = Number(String(version).split(".")[0]); | ||
return isAndroid && osMajorVersion >= 3; | ||
}, | ||
describe() { | ||
return { | ||
type: PLATFORMS_MAP.tablet | ||
}; | ||
} | ||
}, | ||
{ | ||
test(parser) { | ||
const notLikeAndroid = !parser.test(/like android/i); | ||
const butAndroid = parser.test(/android/i); | ||
return notLikeAndroid && butAndroid; | ||
}, | ||
describe() { | ||
return { | ||
type: PLATFORMS_MAP.mobile | ||
}; | ||
} | ||
}, | ||
{ | ||
test: [/macintosh/i], | ||
describe() { | ||
return { | ||
type: PLATFORMS_MAP.desktop, | ||
vendor: "Apple" | ||
}; | ||
} | ||
}, | ||
{ | ||
test(parser) { | ||
const maybeLinux = parser.test(/windows/i); | ||
const isRoku = parser.test(/Roku\/DVP/); | ||
const isWebOS = parser.test(/(web|hpw)[o0]s/i); | ||
return maybeLinux && !isRoku && !isWebOS; | ||
}, | ||
describe() { | ||
return { | ||
type: PLATFORMS_MAP.desktop | ||
}; | ||
} | ||
}, | ||
{ | ||
test(parser) { | ||
const maybeLinux = parser.test(/linux/i); | ||
const isRoku = parser.test(/Roku\/DVP/); | ||
const isWebOS = parser.test(/(web|hpw)[o0]s/i); | ||
return maybeLinux && !isRoku && !isWebOS; | ||
}, | ||
describe() { | ||
return { | ||
type: PLATFORMS_MAP.desktop | ||
}; | ||
} | ||
}, | ||
{ | ||
test: [/PlayStation 4/], | ||
describe() { | ||
return { | ||
type: PLATFORMS_MAP.tv | ||
}; | ||
} | ||
}, | ||
{ | ||
test: [/Roku\/DVP/], | ||
describe() { | ||
return { | ||
type: PLATFORMS_MAP.tv | ||
}; | ||
} | ||
} | ||
]; | ||
function platformParser(parser) { | ||
let result = {}; | ||
const platformDescriptor = platformsList.find((candidate) => { | ||
if (typeof candidate.test === "function") { | ||
return candidate.test(parser); | ||
} | ||
if (candidate.test instanceof Array) { | ||
return candidate.test.some((condition) => parser.test(condition)); | ||
} | ||
throw new Error("Browser's test function is not valid"); | ||
}); | ||
if (platformDescriptor) { | ||
result = platformDescriptor.describe(parser.getUA()); | ||
} | ||
return { platform: result }; | ||
} | ||
function getPlatform(parser) { | ||
try { | ||
return parser.getResult().platform; | ||
} catch (e) { | ||
return platformParser(parser).platform; | ||
} | ||
} | ||
function getPlatformType(parser) { | ||
var _a; | ||
return (_a = getPlatform(parser).type) != null ? _a : ""; | ||
} | ||
function getPlatformVendor(parser, toLowerCase = false) { | ||
var _a, _b; | ||
if (toLowerCase) { | ||
return ((_a = getPlatform(parser).vendor) != null ? _a : "").toLowerCase(); | ||
} | ||
return (_b = getPlatform(parser).vendor) != null ? _b : ""; | ||
} | ||
function getPlatformModel(parser, toLowerCase = false) { | ||
var _a, _b; | ||
if (toLowerCase) { | ||
return ((_a = getPlatform(parser).model) != null ? _a : "").toLowerCase(); | ||
} | ||
return (_b = getPlatform(parser).model) != null ? _b : ""; | ||
} | ||
function isPlatform(parser, platformType) { | ||
return getPlatformType(parser) === platformType.toLowerCase(); | ||
} | ||
export { PLATFORMS_MAP, getPlatform, getPlatformModel, getPlatformType, getPlatformVendor, isPlatform, platformParser }; | ||
export { P as PLATFORMS_MAP, g as getPlatform, c as getPlatformModel, a as getPlatformType, b as getPlatformVendor, i as isPlatform, p as platformParser } from "./platformParser.js"; | ||
import "./utils.js"; |
@@ -1,1 +0,1 @@ | ||
(function(n,o){typeof exports=="object"&&typeof module!="undefined"?o(exports):typeof define=="function"&&define.amd?define(["exports"],o):(n=typeof globalThis!="undefined"?globalThis:n||self,o(n["Bowser-Jr-Platform"]={}))})(this,function(n){"use strict";const o={tablet:"tablet",mobile:"mobile",desktop:"desktop",tv:"tv"};function d(e,t){const i=t.match(e);return i&&i.length>0&&i[1]||""}const b=[{test:[/googlebot/i],describe(){return{type:"bot",vendor:"Google"}}},{test:[/huawei/i],describe(e){const t=d(/(can-l01)/i,e)&&"Nova",i={type:o.mobile,vendor:"Huawei"};return t&&(i.model=t),i}},{test:[/nexus\s*(?:7|8|9|10).*/i],describe(){return{type:o.tablet,vendor:"Nexus"}}},{test:[/ipad/i],describe(){return{type:o.tablet,vendor:"Apple",model:"iPad"}}},{test:[/Macintosh(.*?) FxiOS(.*?)\//],describe(){return{type:o.tablet,vendor:"Apple",model:"iPad"}}},{test:[/kftt build/i],describe(){return{type:o.tablet,vendor:"Amazon",model:"Kindle Fire HD 7"}}},{test:[/silk/i],describe(){return{type:o.tablet,vendor:"Amazon"}}},{test:[/tablet(?! pc)/i],describe(){return{type:o.tablet}}},{test(e){const t=e.test(/ipod|iphone/i),i=e.test(/like (ipod|iphone)/i);return t&&!i},describe(e){const t=d(/(ipod|iphone)/i,e);return{type:o.mobile,vendor:"Apple",model:t}}},{test:[/nexus\s*[0-6].*/i,/galaxy nexus/i],describe(){return{type:o.mobile,vendor:"Nexus"}}},{test:[/[^-]mobi/i],describe(){return{type:o.mobile}}},{test:[/blackberry|\bbb\d+/i,/rim\stablet/i],describe(){return{type:o.mobile,vendor:"BlackBerry"}}},{test:[/bada/i],describe(){return{type:o.mobile}}},{test:[/windows phone/i],describe(){return{type:o.mobile,vendor:"Microsoft"}}},{test(e){const t=!e.test(/like android/i),i=e.test(/android/i),r=t&&i,l=d(/android[\s/-](\d+(\.\d+)*)/i,e.getUA()),p=Number(String(l).split(".")[0]);return r&&p>=3},describe(){return{type:o.tablet}}},{test(e){const t=!e.test(/like android/i),i=e.test(/android/i);return t&&i},describe(){return{type:o.mobile}}},{test:[/macintosh/i],describe(){return{type:o.desktop,vendor:"Apple"}}},{test(e){const t=e.test(/windows/i),i=e.test(/Roku\/DVP/),r=e.test(/(web|hpw)[o0]s/i);return t&&!i&&!r},describe(){return{type:o.desktop}}},{test(e){const t=e.test(/linux/i),i=e.test(/Roku\/DVP/),r=e.test(/(web|hpw)[o0]s/i);return t&&!i&&!r},describe(){return{type:o.desktop}}},{test:[/PlayStation 4/],describe(){return{type:o.tv}}},{test:[/Roku\/DVP/],describe(){return{type:o.tv}}}];function u(e){let t={};const i=b.find(r=>{if(typeof r.test=="function")return r.test(e);if(r.test instanceof Array)return r.test.some(l=>e.test(l));throw new Error("Browser's test function is not valid")});return i&&(t=i.describe(e.getUA())),{platform:t}}function s(e){try{return e.getResult().platform}catch(t){return u(e).platform}}function c(e){var t;return(t=s(e).type)!=null?t:""}function a(e,t=!1){var i,r;return t?((i=s(e).vendor)!=null?i:"").toLowerCase():(r=s(e).vendor)!=null?r:""}function f(e,t=!1){var i,r;return t?((i=s(e).model)!=null?i:"").toLowerCase():(r=s(e).model)!=null?r:""}function m(e,t){return c(e)===t.toLowerCase()}n.PLATFORMS_MAP=o,n.getPlatform=s,n.getPlatformModel=f,n.getPlatformType=c,n.getPlatformVendor=a,n.isPlatform=m,n.platformParser=u,Object.defineProperties(n,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}); | ||
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});var e=require("./platformParser.js");require("./utils.js");exports.PLATFORMS_MAP=e.PLATFORMS_MAP;exports.getPlatform=e.getPlatform;exports.getPlatformModel=e.getPlatformModel;exports.getPlatformType=e.getPlatformType;exports.getPlatformVendor=e.getPlatformVendor;exports.isPlatform=e.isPlatform;exports.platformParser=e.platformParser; |
@@ -1,72 +0,1 @@ | ||
var __defProp = Object.defineProperty; | ||
var __getOwnPropSymbols = Object.getOwnPropertySymbols; | ||
var __hasOwnProp = Object.prototype.hasOwnProperty; | ||
var __propIsEnum = Object.prototype.propertyIsEnumerable; | ||
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value; | ||
var __spreadValues = (a, b) => { | ||
for (var prop in b || (b = {})) | ||
if (__hasOwnProp.call(b, prop)) | ||
__defNormalProp(a, prop, b[prop]); | ||
if (__getOwnPropSymbols) | ||
for (var prop of __getOwnPropSymbols(b)) { | ||
if (__propIsEnum.call(b, prop)) | ||
__defNormalProp(a, prop, b[prop]); | ||
} | ||
return a; | ||
}; | ||
class Parser { | ||
constructor(ua, options) { | ||
this.ua = ua; | ||
this.features = options.use; | ||
if (options.skipParsing !== true) { | ||
this.parse(); | ||
} | ||
} | ||
getUA() { | ||
return this.ua; | ||
} | ||
test(regexp) { | ||
return regexp.test(this.ua); | ||
} | ||
parse() { | ||
if (this.result) { | ||
return this.result; | ||
} | ||
let result = {}; | ||
this.features.forEach((feature) => { | ||
result = __spreadValues(__spreadValues({}, result), feature(this)); | ||
}); | ||
this.result = result; | ||
return this.result; | ||
} | ||
getResult() { | ||
if (!this.result) { | ||
throw new Error("You need to parse before calling `getResult`"); | ||
} | ||
return this.result; | ||
} | ||
get(key) { | ||
if (!this.result || !(key in this.result)) { | ||
throw new Error(`\`${key}\` not found in result`); | ||
} | ||
return this.result[key]; | ||
} | ||
} | ||
function getParser(UA, options) { | ||
return new Parser(UA, options); | ||
} | ||
function parse(UA, options) { | ||
return getParser(UA, options).getResult(); | ||
} | ||
function isAnything(parser, anything, ...args) { | ||
for (const comparator of args) { | ||
if (comparator(parser, anything)) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
function isSome(parser, anythings, ...args) { | ||
return anythings.some((anything) => isAnything(parser, anything, ...args)); | ||
} | ||
export { getParser, isAnything, isSome, parse }; | ||
export { g as getParser, i as isAnything, a as isSome, p as parse } from "./parser.js"; |
@@ -1,1 +0,1 @@ | ||
(function(t,r){typeof exports=="object"&&typeof module!="undefined"?r(exports):typeof define=="function"&&define.amd?define(["exports"],r):(t=typeof globalThis!="undefined"?globalThis:t||self,r(t["Bowser-Jr"]={}))})(this,function(t){"use strict";var d=Object.defineProperty;var l=Object.getOwnPropertySymbols;var g=Object.prototype.hasOwnProperty,p=Object.prototype.propertyIsEnumerable;var h=(t,r,s)=>r in t?d(t,r,{enumerable:!0,configurable:!0,writable:!0,value:s}):t[r]=s,o=(t,r)=>{for(var s in r||(r={}))g.call(r,s)&&h(t,s,r[s]);if(l)for(var s of l(r))p.call(r,s)&&h(t,s,r[s]);return t};class r{constructor(e,i){this.ua=e,this.features=i.use,i.skipParsing!==!0&&this.parse()}getUA(){return this.ua}test(e){return e.test(this.ua)}parse(){if(this.result)return this.result;let e={};return this.features.forEach(i=>{e=o(o({},e),i(this))}),this.result=e,this.result}getResult(){if(!this.result)throw new Error("You need to parse before calling `getResult`");return this.result}get(e){if(!this.result||!(e in this.result))throw new Error(`\`${e}\` not found in result`);return this.result[e]}}function s(u,e){return new r(u,e)}function a(u,e){return s(u,e).getResult()}function f(u,e,...i){for(const n of i)if(n(u,e))return!0;return!1}function c(u,e,...i){return e.some(n=>f(u,n,...i))}t.getParser=s,t.isAnything=f,t.isSome=c,t.parse=a,Object.defineProperties(t,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}); | ||
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});var e=require("./parser.js");exports.getParser=e.getParser;exports.isAnything=e.isAnything;exports.isSome=e.isSome;exports.parse=e.parse; |
@@ -6,8 +6,41 @@ import type { IParser } from "../types"; | ||
}; | ||
export default browserParser; | ||
/** | ||
* Get parsed browser object | ||
* | ||
* @param {IParser} parser The parser instance | ||
* @returns {Browser} | ||
* | ||
* @public | ||
* @example | ||
* const parser = getParser(userAgent, { use: [browserParser] }); | ||
* getBrowser(parser); | ||
* { | ||
* name: 'Firefox', | ||
* version: '26.0' | ||
* } | ||
*/ | ||
export declare function getBrowser<T extends IParser<{ | ||
browser: Browser; | ||
}>>(parser: T): Browser; | ||
/** | ||
* Get browser's name | ||
* | ||
* @param {IParser} parser The parser instance | ||
* @param {boolean} toLowerCase Flag to transform name to lower case | ||
* @returns {String} Browser's name or an empty string | ||
* | ||
* @public | ||
*/ | ||
export declare function getBrowserName<T extends IParser<{ | ||
browser: Browser; | ||
}>>(parser: T, toLowerCase?: boolean): string; | ||
/** | ||
* Get browser's version | ||
* | ||
* @param {IParser} parser Parser instance | ||
* @returns {String} Browser's version or an empty string | ||
* | ||
* @public | ||
*/ | ||
export declare function getBrowserVersion<T extends IParser<{ | ||
@@ -23,2 +56,4 @@ browser: Browser; | ||
* @returns {boolean} | ||
* | ||
* @public | ||
*/ | ||
@@ -34,2 +69,4 @@ export declare function isBrowser<T extends IParser<{ | ||
* @returns {boolean} | ||
* | ||
* @public | ||
*/ | ||
@@ -36,0 +73,0 @@ export declare function compareVersion<T extends IParser<{ |
/** | ||
* The main class that arranges the whole parsing process. | ||
*/ | ||
declare class Parser { | ||
declare class CompatParser { | ||
private parser; | ||
@@ -109,3 +109,3 @@ constructor(UA: string, skipParsing?: boolean); | ||
* Parse full information about the browser | ||
* @returns {Parser} | ||
* @returns {CompatParser} | ||
*/ | ||
@@ -163,10 +163,10 @@ parse(): this; | ||
} | ||
declare class Bowser { | ||
declare class BowserCompat { | ||
/** | ||
* Creates a {@link Parser} instance | ||
* Creates a {@link CompatParser} instance | ||
* | ||
* @param {String} UA UserAgent string | ||
* @param {Boolean} [skipParsing=false] Will make the Parser postpone parsing until you ask it | ||
* explicitly. Same as `skipParsing` for {@link Parser}. | ||
* @returns {Parser} | ||
* explicitly. Same as `skipParsing` for {@link CompatParser}. | ||
* @returns {CompatParser} | ||
* @throws {Error} when UA is not a String | ||
@@ -178,5 +178,5 @@ * | ||
*/ | ||
static getParser(UA: string, skipParsing?: boolean): Parser; | ||
static getParser(UA: string, skipParsing?: boolean): CompatParser; | ||
/** | ||
* Creates a {@link Parser} instance and runs {@link Parser.getResult} immediately | ||
* Creates a {@link CompatParser} instance and runs {@link CompatParser.getResult} immediately | ||
* | ||
@@ -193,3 +193,6 @@ * @param UA | ||
android: string; | ||
bada: string; | ||
bada: string; /** | ||
* Get parsed browser object | ||
* @return {Object} | ||
*/ | ||
blackberry: string; | ||
@@ -199,8 +202,3 @@ chrome: string; | ||
electron: string; | ||
epiphany: string; /** | ||
* Get parsed browser object | ||
* @return {Object} | ||
* | ||
* @public | ||
*/ | ||
epiphany: string; | ||
firefox: string; | ||
@@ -235,2 +233,6 @@ focus: string; | ||
tizen: string; | ||
/** | ||
* Parse OS and save it to this.parsedResult.os | ||
* @return {*|{}} | ||
*/ | ||
uc: string; | ||
@@ -272,2 +274,2 @@ vivaldi: string; | ||
} | ||
export default Bowser; | ||
export default BowserCompat; |
@@ -1,1 +0,2 @@ | ||
export * from "./compatParser"; | ||
import BowserCompat from "./compatParser"; | ||
export default BowserCompat; |
{ | ||
"name": "bowser-jr", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "Light-weight, composable browser detector", | ||
@@ -30,17 +30,17 @@ "author": { | ||
"@types/js-yaml": "4.0.5", | ||
"@types/node": "^17.0.35", | ||
"c8": "^7.11.3", | ||
"js-yaml": "4.1.0", | ||
"jsdom": "^19.0.0", | ||
"typescript": "^4.6.3", | ||
"vite": "^2.8.6", | ||
"vitest": "^0.10.0", | ||
"js-yaml": "4.1.0" | ||
"vitest": "^0.10.0" | ||
}, | ||
"dependencies": {}, | ||
"scripts": { | ||
"generate-types": "tsc --project tsconfig.lib.json", | ||
"build": "node ./scripts/build.js", | ||
"build": "vite build && pnpm run generate-types", | ||
"lint": "tsc", | ||
"test": "vitest run", | ||
"test:watch": "vitest" | ||
}, | ||
"readme": "# Bowser Jr.\n\nA small, lightweight and *composable* browser detection utility heavily inspired by [`bowser`](https://github.com/lancedikson/bowser).\n\n[![Unit Tests](https://github.com/thillmann/bowser-jr/actions/workflows/test.yaml/badge.svg)](https://github.com/thillmann/bowser-jr/actions/workflows/test.yaml)\n\n## Installation\n\nInstall it using your favourite package manager:\n\n```bash\n$ npm install bowser-jr\n# or\n$ yarn add bowser-jr\n# or\n$ pnpm add bowser-jr\n```\n\n## Usage\n\nNow just import `getParser` and the `parsers` you need:\n\n```ts\nimport { getParser } from 'bowser-jr';\nimport { getBrowserName, browserParser } from 'bowser-jr/browser';\n\nconst parser = getParser(window.navigator.userAgent, { use: [browserParser] });\n\nconsole.log(getBrowserName(parser)); // outputs `Firefox`\n```\n\n### Using multiple parsers\n\nYou can use multiple parsers to extract more information from the user agent:\n\n```ts\nimport { getParser } from 'bowser-jr';\nimport { browserParser } from 'bowser-jr/browser';\nimport { engineParser } from 'bowser-jr/engine';\nimport { osParser } from 'bowser-jr/os';\nimport { platformParser } from 'bowser-jr/platform';\n\nconst parser = getParser(window.navigator.userAgent, {\n use: [browserParser, engineParser, osParser, platformParser],\n});\n\nconsole.log(parser.getResult());\n```\n\n### Bowser compat utilities\n\n`bowser-jr` also comes with a compatibility utility for [`bowser`](https://github.com/lancedikson/bowser) to make adoption a little easier:\n\n```ts\nimport Bowser from 'bowser-jr/compat';\n\nconst browser = Bowser.getParser(window.navigator.userAgent);\nconsole.log(browser.getBrowser());\n\n// outputs\n{\n name: \"Internet Explorer\"\n version: \"11.0\"\n}\n```\n\n" | ||
} | ||
} |
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
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 3 instances 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
56
57014
8
974
9
1