basant307/AI_Governance_Project
048
1'use strict'2 3const statuses = require('../lib/statuses')4const supported = require('../lib/supported')5const browsers = require('./browsers').browsers6const versions = require('./browserVersions').browserVersions7 8const MATH2LOG = Math.log(2)9 10function unpackSupport(cipher) {11 // bit flags12 let stats = Object.keys(supported).reduce((list, support) => {13 if (cipher & supported[support]) list.push(support)14 return list15 }, [])16 17 // notes18 let notes = cipher >> 719 let notesArray = []20 while (notes) {21 let note = Math.floor(Math.log(notes) / MATH2LOG) + 122 notesArray.unshift(`#${note}`)23 notes -= Math.pow(2, note - 1)24 }25 26 return stats.concat(notesArray).join(' ')27}28 29function unpackFeature(packed) {30 let unpacked = {31 status: statuses[packed.B],32 title: packed.C,33 shown: packed.D34 }35 unpacked.stats = Object.keys(packed.A).reduce((browserStats, key) => {36 let browser = packed.A[key]37 browserStats[browsers[key]] = Object.keys(browser).reduce(38 (stats, support) => {39 let packedVersions = browser[support].split(' ')40 let unpacked2 = unpackSupport(support)41 packedVersions.forEach(v => (stats[versions[v]] = unpacked2))42 return stats43 },44 {}45 )46 return browserStats47 }, {})48 return unpacked49}50 51module.exports = unpackFeature52module.exports.default = unpackFeature53 