source: trip-planner-front/node_modules/caniuse-lite/dist/unpacker/feature.js@ 6a3a178

Last change on this file since 6a3a178 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 1.3 KB
Line 
1'use strict'
2
3const statuses = require('../lib/statuses')
4const supported = require('../lib/supported')
5const browsers = require('./browsers').browsers
6const versions = require('./browserVersions').browserVersions
7
8const MATH2LOG = Math.log(2)
9
10function unpackSupport(cipher) {
11 // bit flags
12 let stats = Object.keys(supported).reduce((list, support) => {
13 if (cipher & supported[support]) list.push(support)
14 return list
15 }, [])
16
17 // notes
18 let notes = cipher >> 7
19 let notesArray = []
20 while (notes) {
21 let note = Math.floor(Math.log(notes) / MATH2LOG) + 1
22 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 = { status: statuses[packed.B], title: packed.C }
31 unpacked.stats = Object.keys(packed.A).reduce((browserStats, key) => {
32 let browser = packed.A[key]
33 browserStats[browsers[key]] = Object.keys(browser).reduce(
34 (stats, support) => {
35 let packedVersions = browser[support].split(' ')
36 let unpacked2 = unpackSupport(support)
37 packedVersions.forEach(v => (stats[versions[v]] = unpacked2))
38 return stats
39 },
40 {}
41 )
42 return browserStats
43 }, {})
44 return unpacked
45}
46
47module.exports = unpackFeature
48module.exports.default = unpackFeature
Note: See TracBrowser for help on using the repository browser.