mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-27 08:02:01 +00:00
parent
c865cef032
commit
6ae7718a42
@ -1,6 +1,3 @@
|
|||||||
import UAParser from 'ua-parser-js'
|
|
||||||
import semver from 'semver'
|
|
||||||
|
|
||||||
export const ModernBrowsers = {
|
export const ModernBrowsers = {
|
||||||
Edge: '16',
|
Edge: '16',
|
||||||
Firefox: '60',
|
Firefox: '60',
|
||||||
@ -15,22 +12,29 @@ export const ModernBrowsers = {
|
|||||||
'Mobile Safari': '10.3'
|
'Mobile Safari': '10.3'
|
||||||
}
|
}
|
||||||
|
|
||||||
const modernBrowsers = Object.keys(ModernBrowsers)
|
const modernBrowsers = new Proxy(ModernBrowsers, {
|
||||||
.reduce((allBrowsers, browser) => {
|
get (browsers, prop) {
|
||||||
allBrowsers[browser] = semver.coerce(ModernBrowsers[browser])
|
if (browsers[prop] && !browsers[prop].version) {
|
||||||
return allBrowsers
|
const coerce = require('semver/functions/coerce')
|
||||||
}, {})
|
browsers[prop] = coerce(browsers[prop])
|
||||||
|
}
|
||||||
|
return browsers[prop]
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
export const isModernBrowser = (ua) => {
|
export const isModernBrowser = (ua) => {
|
||||||
if (!ua) {
|
if (!ua) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
const coerce = require('semver/functions/coerce')
|
||||||
|
const gte = require('semver/functions/gte')
|
||||||
|
const UAParser = require('ua-parser-js')
|
||||||
const { browser } = UAParser(ua)
|
const { browser } = UAParser(ua)
|
||||||
const browserVersion = semver.coerce(browser.version)
|
const browserVersion = coerce(browser.version)
|
||||||
if (!browserVersion) {
|
if (!browserVersion) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
return Boolean(modernBrowsers[browser.name] && semver.gte(browserVersion, modernBrowsers[browser.name]))
|
return Boolean(modernBrowsers[browser.name] && gte(browserVersion, modernBrowsers[browser.name]))
|
||||||
}
|
}
|
||||||
|
|
||||||
export const isModernRequest = (req, modernMode = false) => {
|
export const isModernRequest = (req, modernMode = false) => {
|
||||||
|
Loading…
Reference in New Issue
Block a user