Skip to content

Commit

Permalink
Make cover query case-insensitive (browserslist#648)
Browse files Browse the repository at this point in the history
  • Loading branch information
g-plane authored and zhouyu9527 committed Jul 4, 2022
1 parent ffc6723 commit 2096f30
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
6 changes: 3 additions & 3 deletions index.js
Expand Up @@ -642,7 +642,7 @@ function coverQuery(context, coverage, statMode) {
coverage = parseFloat(coverage)
var usage = browserslist.usage.global
if (statMode) {
if (statMode.match(/^my\s+stats$/)) {
if (statMode.match(/^my\s+stats$/i)) {
if (!context.customUsage) {
throw new BrowserslistError('Custom usage statistics was not provided')
}
Expand Down Expand Up @@ -916,11 +916,11 @@ var QUERIES = [
}
},
{
regexp: /^cover\s+(\d+|\d+\.\d+|\.\d+)%$/,
regexp: /^cover\s+(\d+|\d+\.\d+|\.\d+)%$/i,
select: coverQuery
},
{
regexp: /^cover\s+(\d+|\d+\.\d+|\.\d+)%\s+in\s+(my\s+stats|(alt-)?\w\w)$/,
regexp: /^cover\s+(\d+|\d+\.\d+|\.\d+)%\s+in\s+(my\s+stats|(alt-)?\w\w)$/i,
select: coverQuery
},
{
Expand Down
13 changes: 13 additions & 0 deletions test/cover.test.js
Expand Up @@ -32,10 +32,18 @@ it('adds at least one browser', () => {
expect(browserslist('cover 1% in my stats')).toEqual(['ie 11'])
})

it('is case insensitive for custom stat', () => {
expect(browserslist('Cover 1% In My Stats')).toEqual(['ie 11'])
})

it('global coverage', () => {
expect(browserslist('cover 0.1%')).toEqual(['ie 5'])
})

it('is case insensitive for global coverage', () => {
expect(browserslist('Cover 0.1%')).toEqual(['ie 5'])
})

it('country coverage', () => {
expect(browserslist('cover 0.1% in US')).toEqual(['ie 9'])
})
Expand All @@ -44,6 +52,11 @@ it('country coverage alt', () => {
expect(browserslist('cover 0.1% in alt-us')).toEqual(['ie 8'])
})

it('is case insensitive for country coverage', () => {
expect(browserslist('Cover 0.1% in us')).toEqual(['ie 9'])
expect(browserslist('Cover 0.1% in Alt-US')).toEqual(['ie 8'])
})

it('adds browsers by popularity', () => {
expect(browserslist('cover 20% in my stats')).toEqual([
'chrome 37',
Expand Down

0 comments on commit 2096f30

Please sign in to comment.