agents.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. 'use strict'
  2. const browsers = require('./browsers').browsers
  3. const versions = require('./browserVersions').browserVersions
  4. const agentsData = require('../../data/agents')
  5. function unpackBrowserVersions(versionsData) {
  6. return Object.keys(versionsData).reduce((usage, version) => {
  7. usage[versions[version]] = versionsData[version]
  8. return usage
  9. }, {})
  10. }
  11. module.exports.agents = Object.keys(agentsData).reduce((map, key) => {
  12. let versionsData = agentsData[key]
  13. map[browsers[key]] = Object.keys(versionsData).reduce((data, entry) => {
  14. if (entry === 'A') {
  15. data.usage_global = unpackBrowserVersions(versionsData[entry])
  16. } else if (entry === 'C') {
  17. data.versions = versionsData[entry].reduce((list, version) => {
  18. if (version === '') {
  19. list.push(null)
  20. } else {
  21. list.push(versions[version])
  22. }
  23. return list
  24. }, [])
  25. } else if (entry === 'D') {
  26. data.prefix_exceptions = unpackBrowserVersions(versionsData[entry])
  27. } else if (entry === 'E') {
  28. data.browser = versionsData[entry]
  29. } else if (entry === 'F') {
  30. data.release_date = Object.keys(versionsData[entry]).reduce(
  31. (map2, key2) => {
  32. map2[versions[key2]] = versionsData[entry][key2]
  33. return map2
  34. },
  35. {}
  36. )
  37. } else {
  38. // entry is B
  39. data.prefix = versionsData[entry]
  40. }
  41. return data
  42. }, {})
  43. return map
  44. }, {})