You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

57 lines
1.7 KiB

4 years ago
  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. var MATH2LOG = Math.log(2);
  14. function unpackSupport(cipher) {
  15. // bit flags
  16. var stats = Object.keys(_supported2.default).reduce(function (list, support) {
  17. if (cipher & _supported2.default[support]) list.push(support);
  18. return list;
  19. }, []);
  20. // notes
  21. var notes = cipher >> 7;
  22. var notesArray = [];
  23. while (notes) {
  24. var note = Math.floor(Math.log(notes) / MATH2LOG) + 1;
  25. notesArray.unshift('#' + note);
  26. notes -= Math.pow(2, note - 1);
  27. }
  28. return stats.concat(notesArray).join(' ');
  29. }
  30. function unpackFeature(packed) {
  31. var unpacked = { status: _statuses2.default[packed.B], title: packed.C };
  32. unpacked.stats = Object.keys(packed.A).reduce(function (browserStats, key) {
  33. var browser = packed.A[key];
  34. browserStats[_browsers.browsers[key]] = Object.keys(browser).reduce(function (stats, support) {
  35. var packedVersions = browser[support].split(' ');
  36. var unpacked = unpackSupport(support);
  37. packedVersions.forEach(function (v) {
  38. return stats[_browserVersions.browserVersions[v]] = unpacked;
  39. });
  40. return stats;
  41. }, {});
  42. return browserStats;
  43. }, {});
  44. return unpacked;
  45. }