Skip to content

Commit 19a15f3

Browse files
committed
Simplify browser ranges
Fixes #184
1 parent e06e7c6 commit 19a15f3

File tree

3 files changed

+52
-14
lines changed

3 files changed

+52
-14
lines changed

README.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,15 @@ cat main.css | doiuse --browsers "ie >= 9, > 1%, last 2 versions"
2323

2424
**Sample output:**
2525
```
26-
/projects/website/main.css:5:3: CSS3 Box-sizing not supported by: IE (8,9,10,11), Chrome (36,37,38), Safari (8,7.1), Opera (24,25), iOS Safari (8,7.1,8.1), Android Browser (4.1,4.4,4.4.4), IE Mobile (10,11)
27-
/projects/website/main.css:6:3: CSS3 Box-sizing not supported by: IE (8,9,10,11), Chrome (36,37,38), Safari (8,7.1), Opera (24,25), iOS Safari (8,7.1,8.1), Android Browser (4.1,4.4,4.4.4), IE Mobile (10,11)
28-
/projects/website/main.css:8:3: CSS user-select: none not supported by: IE (8,9)
29-
/projects/website/main.css:9:3: CSS user-select: none not supported by: IE (8,9)
30-
/projects/website/main.css:10:3: CSS user-select: none not supported by: IE (8,9)
31-
/projects/website/main.css:11:3: CSS user-select: none not supported by: IE (8,9)
32-
/projects/website/main.css:12:3: CSS user-select: none not supported by: IE (8,9)
33-
/projects/website/main.css:13:3: Pointer events not supported by: IE (8,9,10), Firefox (32,33), Chrome (36,37,38), Safari (8,7.1), Opera (24,25), iOS Safari (8,7.1,8.1), Android Browser (4.1,4.4,4.4.4), IE Mobile (10)
34-
/projects/website/main.css:14:3: Pointer events not supported by: IE (8,9,10), Firefox (32,33), Chrome (36,37,38), Safari (8,7.1), Opera (24,25), iOS Safari (8,7.1,8.1), Android Browser (4.1,4.4,4.4.4), IE Mobile (10)
26+
/projects/website/main.css:5:3: CSS3 Box-sizing not supported by: IE (8-11), Chrome (36-38), Safari (8,7.1), Opera (24-25), iOS Safari (8,7.1,8.1), Android Browser (4.1,4.4,4.4.4), IE Mobile (10-11)
27+
/projects/website/main.css:6:3: CSS3 Box-sizing not supported by: IE (8-11), Chrome (36-38), Safari (8,7.1), Opera (24-25), iOS Safari (8,7.1,8.1), Android Browser (4.1,4.4,4.4.4), IE Mobile (10-11)
28+
/projects/website/main.css:8:3: CSS user-select: none not supported by: IE (8-9)
29+
/projects/website/main.css:9:3: CSS user-select: none not supported by: IE (8-9)
30+
/projects/website/main.css:10:3: CSS user-select: none not supported by: IE (8-9)
31+
/projects/website/main.css:11:3: CSS user-select: none not supported by: IE (8-9)
32+
/projects/website/main.css:12:3: CSS user-select: none not supported by: IE (8-9)
33+
/projects/website/main.css:13:3: Pointer events not supported by: IE (8-10), Firefox (32-33), Chrome (36-38), Safari (8,7.1), Opera (24-25), iOS Safari (8,7.1,8.1), Android Browser (4.1,4.4,4.4.4), IE Mobile (10)
34+
/projects/website/main.css:14:3: Pointer events not supported by: IE (8-10), Firefox (32-33), Chrome (36-38), Safari (8,7.1), Opera (24-25), iOS Safari (8,7.1,8.1), Android Browser (4.1,4.4,4.4.4), IE Mobile (10)
3535
/projects/website/main.css:32:3: CSS3 Transforms not supported by: IE (8)
3636
```
3737

test/cli.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ const pathToCli = ` node ${joinPath(selfPath, '../bin/cli.js')}`;
1111
const catCss = ` cat ${cssFile} `;
1212

1313
const expectedCssGradients = [
14-
'<streaming css input>:8:1: CSS Gradients not supported by: IE (8,9) (css-gradients)\n',
15-
'<streaming css input>:12:1: CSS Gradients not supported by: IE (8,9) (css-gradients)\n',
14+
'<streaming css input>:8:1: CSS Gradients not supported by: IE (8-9) (css-gradients)\n',
15+
'<streaming css input>:12:1: CSS Gradients not supported by: IE (8-9) (css-gradients)\n',
1616
];
1717

1818
const expectedCssRepeatingGradients = [
19-
'<streaming css input>:16:1: CSS Repeating Gradients not supported by: IE (8,9) (css-repeating-gradients)\n',
20-
'<streaming css input>:20:1: CSS Repeating Gradients not supported by: IE (8,9) (css-repeating-gradients)\n',
19+
'<streaming css input>:16:1: CSS Repeating Gradients not supported by: IE (8-9) (css-repeating-gradients)\n',
20+
'<streaming css input>:20:1: CSS Repeating Gradients not supported by: IE (8-9) (css-repeating-gradients)\n',
2121
];
2222
const expected = [
2323
...expectedCssGradients,

utils/util.js

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,45 @@ export function formatBrowserName(browserKey, versions) {
2323
if (!versions) {
2424
return browserName || '';
2525
}
26-
return (`${browserName} (${versions.join(',')})`);
26+
27+
const ranges = [];
28+
let rangeStart = -1;
29+
let rangeEnd = -1;
30+
31+
for (const [index, versionString] of versions.entries()) {
32+
const current = +versionString;
33+
const next = +versions[index + 1];
34+
35+
if (Number.isInteger(current)) {
36+
if (rangeStart === -1) {
37+
rangeStart = current;
38+
rangeEnd = current;
39+
} else if (current === rangeEnd + 1) {
40+
rangeEnd = current;
41+
} else {
42+
ranges.push(rangeStart === rangeEnd ? [rangeStart] : [rangeStart, rangeEnd]);
43+
rangeStart = current;
44+
rangeEnd = current;
45+
}
46+
47+
if (!Number.isInteger(next) || current + 1 !== next) {
48+
ranges.push(rangeStart === rangeEnd ? [rangeStart] : [rangeStart, rangeEnd]);
49+
rangeStart = -1;
50+
rangeEnd = -1;
51+
}
52+
} else {
53+
if (rangeStart !== -1) {
54+
ranges.push(rangeStart === rangeEnd ? [rangeStart] : [rangeStart, rangeEnd]);
55+
rangeStart = -1;
56+
rangeEnd = -1;
57+
}
58+
ranges.push([versionString]);
59+
}
60+
}
61+
62+
const versionString = ranges.map((range) => range.join('-')).join(',');
63+
64+
return `${browserName} (${versionString})`;
2765
}
2866

2967
/**

0 commit comments

Comments
 (0)