Keine Beschreibung

browsers.js 2.1KB

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(data1, requirements, options) {
  31. this.data = data1;
  32. this.options = 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, ref, selected, versions;
  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, ref, version;
  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);