browsers.js 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. (function() {
  2. var Browsers, browserslist, utils;
  3. browserslist = require('browserslist');
  4. utils = require('./utils');
  5. Browsers = (function() {
  6. Browsers.prefixes = function() {
  7. var data, i, name;
  8. if (this.prefixesCache) {
  9. return this.prefixesCache;
  10. }
  11. data = require('caniuse-db/data').agents;
  12. return this.prefixesCache = utils.uniq((function() {
  13. var _results;
  14. _results = [];
  15. for (name in data) {
  16. i = data[name];
  17. _results.push("-" + i.prefix + "-");
  18. }
  19. return _results;
  20. })()).sort(function(a, b) {
  21. return b.length - a.length;
  22. });
  23. };
  24. Browsers.withPrefix = function(value) {
  25. if (!this.prefixesRegexp) {
  26. this.prefixesRegexp = RegExp("" + (this.prefixes().join('|')));
  27. }
  28. return this.prefixesRegexp.test(value);
  29. };
  30. function Browsers(_at_data, requirements, _at_options) {
  31. this.data = _at_data;
  32. this.options = _at_options;
  33. this.selected = this.parse(requirements);
  34. }
  35. Browsers.prototype.parse = function(requirements) {
  36. var _ref;
  37. return browserslist(requirements, {
  38. path: (_ref = this.options) != null ? _ref.from : void 0
  39. });
  40. };
  41. Browsers.prototype.browsers = function(criteria) {
  42. var browser, data, selected, versions, _ref;
  43. selected = [];
  44. _ref = this.data;
  45. for (browser in _ref) {
  46. data = _ref[browser];
  47. versions = criteria(data).map(function(version) {
  48. return browser + " " + version;
  49. });
  50. selected = selected.concat(versions);
  51. }
  52. return selected;
  53. };
  54. Browsers.prototype.prefix = function(browser) {
  55. var data, name, prefix, version, _ref;
  56. _ref = browser.split(' '), name = _ref[0], version = _ref[1];
  57. data = this.data[name];
  58. if (data.prefix_exceptions) {
  59. prefix = data.prefix_exceptions[version];
  60. }
  61. prefix || (prefix = data.prefix);
  62. return '-' + prefix + '-';
  63. };
  64. Browsers.prototype.isSelected = function(browser) {
  65. return this.selected.indexOf(browser) !== -1;
  66. };
  67. return Browsers;
  68. })();
  69. module.exports = Browsers;
  70. }).call(this);