|
Last change
on this file since e4c61dd was 2058e5c, checked in by istevanoska <ilinastevanoska@…>, 6 months ago |
|
Working / before login
|
-
Property mode
set to
100644
|
|
File size:
1.3 KB
|
| Line | |
|---|
| 1 | 'use strict'
|
|---|
| 2 |
|
|---|
| 3 | const statuses = require('../lib/statuses')
|
|---|
| 4 | const supported = require('../lib/supported')
|
|---|
| 5 | const browsers = require('./browsers').browsers
|
|---|
| 6 | const versions = require('./browserVersions').browserVersions
|
|---|
| 7 |
|
|---|
| 8 | const MATH2LOG = Math.log(2)
|
|---|
| 9 |
|
|---|
| 10 | function 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 |
|
|---|
| 29 | function unpackFeature(packed) {
|
|---|
| 30 | let unpacked = {
|
|---|
| 31 | status: statuses[packed.B],
|
|---|
| 32 | title: packed.C,
|
|---|
| 33 | shown: packed.D
|
|---|
| 34 | }
|
|---|
| 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 stats
|
|---|
| 43 | },
|
|---|
| 44 | {}
|
|---|
| 45 | )
|
|---|
| 46 | return browserStats
|
|---|
| 47 | }, {})
|
|---|
| 48 | return unpacked
|
|---|
| 49 | }
|
|---|
| 50 |
|
|---|
| 51 | module.exports = unpackFeature
|
|---|
| 52 | module.exports.default = unpackFeature
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.