Skip to content

Test for caniuse features that contain a key of browserNameMap in their name #79

@tndev

Description

@tndev

browserslist has the ability to use supports [feature] to query against caniuse features.

So something like this also works with browserslist-useragent:

matchesUA(
  'Mozilla/5.0 (Windows NT 10.0; rv:54.0) Gecko/20100101 Firefox/54.0',
  { browsers: ['supports es6-module'] }
)

It however fails if the feature to test for contains a key listed in:

const browserNameMap: Record<string, string> = {
bb: 'BlackBerry',
and_chr: 'Chrome',
ChromeAndroid: 'Chrome',
FirefoxAndroid: 'Firefox',
ff: 'Firefox',
ie_mob: 'ExplorerMobile',
ie: 'Explorer',
and_ff: 'Firefox',
ios_saf: 'iOS',
op_mini: 'OperaMini',
op_mob: 'OperaMobile',
and_qq: 'QQAndroid',
and_uc: 'UCAndroid',
}

Like for example woff or woff2, this is due to

function normalizeQuery(query: string) {
let normalizedQuery = query
const regex = `(${Object.keys(browserNameMap).join('|')})`
const match = query.match(new RegExp(regex))
if (match) {
normalizedQuery = query.replace(match[0], browserNameMap[match[0]])
}
return normalizedQuery
}

Is there some way to make { browsers: ['supports woff2'] } and working?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions