feature.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. 'use strict';
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = unpackFeature;
  6. var _statuses = require('../lib/statuses');
  7. var _statuses2 = _interopRequireDefault(_statuses);
  8. var _supported = require('../lib/supported');
  9. var _supported2 = _interopRequireDefault(_supported);
  10. var _browsers = require('./browsers');
  11. var _browserVersions = require('./browserVersions');
  12. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  13. function unpackSupport(cipher) {
  14. // bit flags
  15. var stats = Object.keys(_supported2.default).reduce(function (list, support) {
  16. if (cipher & _supported2.default[support]) list.push(support);
  17. return list;
  18. }, []);
  19. // notes
  20. var notes = cipher >> 7;
  21. var notesArray = [];
  22. while (notes) {
  23. var note = Math.floor(Math.log2(notes)) + 1;
  24. notesArray.unshift('#' + note);
  25. notes -= Math.pow(2, note - 1);
  26. }
  27. return stats.concat(notesArray).join(' ');
  28. }
  29. function unpackFeature(packed) {
  30. var unpacked = { status: _statuses2.default[packed.B], title: packed.C };
  31. unpacked.stats = Object.keys(packed.A).reduce(function (browserStats, key) {
  32. var browser = packed.A[key];
  33. browserStats[_browsers.browsers[key]] = Object.keys(browser).reduce(function (stats, support) {
  34. var packedVersions = browser[support].split(' ');
  35. var unpacked = unpackSupport(support);
  36. packedVersions.forEach(function (v) {
  37. return stats[_browserVersions.browserVersions[v]] = unpacked;
  38. });
  39. return stats;
  40. }, {});
  41. return browserStats;
  42. }, {});
  43. return unpacked;
  44. }