question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Question: caniuse-lite Features Query

See original GitHub issue

I did a fair amount of searching in the repo and the webs for an answer before choosing to post, and I came up short. I’m in need of retrieving browsers that support native WebSocket. caniuse-lite does have a data file for that, but I only see the regions data from that module being used by this one. Since babel-env leverages this module, and I’m looking to target a build to browsers which support WebSocket as the baseline minimum supported, the ability to get a list of browsers based on feature is really attractive.

Is that possible at present?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:2
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

4reactions
shellscapecommented, Dec 31, 2017

I’m not sure if this is proper for the documentation here, but here’s what I came up with. Tested with a .browserslistrc and it appears to work correctly:

const caniuse = require('caniuse-api');
const results = caniuse.getSupport('websocket');

/*
{
  and_chr: { y: 62 },
  and_ff: { y: 57 },
  and_qq: { y: 1.2 },
  and_uc: { y: 11.4 },
  android: { n: 4.2, y: 4.4 },
  baidu: { y: 7.12 },
  bb: { y: 7, '#1': 7 },
  chrome: { a: 15, '#1': 14, '#2': 15, y: 16 },
  edge: { y: 12 },
  firefox: { n: 3.6, a: 10, '#1': 5, x: 10, '#2': 10, y: 11 },
  ie: { n: 9, y: 10 },
  ie_mob: { y: 10 },
  ios_saf: { y: 6, n: 4, a: 5, '#1': 5 },
  op_mini: {},
  op_mob: { n: 10, a: 12, '#1': 12, y: 12.1 },
  opera: { n: 10.6, a: 12, '#1': 12, y: 12.1 },
  safari: { n: 4, a: 6.1, '#1': 5.1, '#2': 6.1, y: 7 },
  samsung: { y: 4 }
};
*/

const keys = Object.keys(results);
const browsers = [];

for (const name of keys) {
  const browser = results[name];

  if (browser.y) {
    browsers.push(`${name} >= ${browser.y}`);
  }
}

console.log(browsers.join('\n'));
/*
and_chr >= 62
and_ff >= 57
and_qq >= 1.2
and_uc >= 11.4
android >= 4.4
baidu >= 7.12
bb >= 7
chrome >= 16
edge >= 12
firefox >= 11
ie >= 10
ie_mob >= 10
ios_saf >= 6
op_mob >= 12.1
opera >= 12.1
safari >= 7
samsung >= 4
*/
1reaction
aicommented, Dec 31, 2017

I added caniuse-api to docs 030a438

Read more comments on GitHub >

github_iconTop Results From Across the Web

browserslist/caniuse-lite - GitHub
The features index is provided as a way to query all of the features that are listed in the caniuse-db dataset. Note that...
Read more >
caniuse-lite - NPM Package Overview - Socket.dev
The features index is provided as a way to query all of the features that are listed in the caniuse-db dataset. Note that...
Read more >
caniuse-lite is outdated. Please run next command `npm ...
First, as the message says, I ran npm update caniuse-lite browserslist but it didn't fix the issue. I deleted the whole node_modules directory ......
Read more >
"feature queries" | Can I use... Support tables for HTML5 ...
CSS Feature Queries allow authors to condition rules based on whether particular property declarations are supported in CSS using the @supports at rule....
Read more >
caniuse-lite is outdated. Please run next command `npm ...
First, as the message says, I ran npm update caniuse-lite browserslist but it didn't fix ... This question is tagged with npm sass...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found