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.

157 lines
3.1 KiB

4 years ago
  1. # caniuse-api [![Build Status](https://travis-ci.org/Nyalab/caniuse-api.svg?branch=master)](https://travis-ci.org/Nyalab/caniuse-api) [![Build status](https://ci.appveyor.com/api/projects/status/6j3na522bv3bxfa5/branch/master?svg=true)](https://ci.appveyor.com/project/MoOx/caniuse-api/branch/master)
  2. request the caniuse data to check browsers compatibilities
  3. ## Installation
  4. ```console
  5. $ yarn add caniuse-api
  6. ```
  7. ## Usage
  8. ```js
  9. const caniuse = require('caniuse-api')
  10. caniuse.getSupport('border-radius')
  11. caniuse.isSupported('border-radius', 'ie 8, ie 9')
  12. caniuse.setBrowserScope('> 5%, last 1 version')
  13. caniuse.getSupport('border-radius')
  14. // ...
  15. ```
  16. ## API
  17. #### `caniuse.getSupport(feature)`
  18. _ask since which browsers versions a feature is available_
  19. * `y`: Since which browser version the feature is available
  20. * `n`: Up to which browser version the feature is unavailable
  21. * `a`: Up to which browser version the feature is partially supported
  22. * `x`: Up to which browser version the feature is prefixed
  23. ```js
  24. caniuse.getSupport('border-radius', true)
  25. /*
  26. { and_chr: { y: 67 },
  27. and_ff: { y: 60 },
  28. and_qq: { y: 1.2 },
  29. and_uc: { y: 11.8 },
  30. android: { y: 2.1, x: 2.1 },
  31. baidu: { y: 7.12 },
  32. chrome: { y: 4, x: 4 },
  33. edge: { y: 12 },
  34. firefox: { a: 2, x: 3.6, y: 3 },
  35. ie: { n: 8, y: 9 },
  36. ie_mob: { y: 10 },
  37. ios_saf: { y: 3.2, x: 3.2 },
  38. op_mini: {},
  39. op_mob: { n: 10, y: 11 },
  40. opera: { n: 10, y: 10.5 },
  41. safari: { y: 3.1, x: 4 },
  42. samsung: { y: 4 } }
  43. */
  44. ```
  45. #### `caniuse.isSupported(feature, browsers)`
  46. _ask if a feature is supported by some browsers_
  47. ```js
  48. caniuse.isSupported('border-radius', 'ie 8, ie 9') // false
  49. caniuse.isSupported('border-radius', 'ie 9') // true
  50. ```
  51. #### `caniuse.find(query)`
  52. _search for a caniuse feature name_
  53. Ex:
  54. ```js
  55. caniuse.find('radius') // ['border-radius']
  56. caniuse.find('nothingness') // []
  57. caniuse.find('css3')
  58. /*
  59. [ 'css3-attr',
  60. 'css3-boxsizing',
  61. 'css3-colors',
  62. 'css3-cursors-grab',
  63. 'css3-cursors-newer',
  64. 'css3-cursors',
  65. 'css3-tabsize' ]
  66. */
  67. ```
  68. #### `caniuse.getLatestStableBrowsers()`
  69. _get the current version for each browser_
  70. ```js
  71. caniuse.getLatestStableBrowsers()
  72. /*
  73. [ 'and_chr 67',
  74. 'and_ff 60',
  75. 'and_qq 1.2',
  76. 'and_uc 11.8',
  77. 'android 67',
  78. 'baidu 7.12',
  79. 'bb 10',
  80. 'chrome 67',
  81. 'edge 17',
  82. 'firefox 61',
  83. 'ie 11',
  84. 'ie_mob 11',
  85. 'ios_saf 11.3-11.4',
  86. 'op_mini all',
  87. 'op_mob 46',
  88. 'opera 53',
  89. 'safari 11.1',
  90. 'samsung 7.2' ]
  91. */
  92. ```
  93. #### `caniuse.getBrowserScope()`
  94. _returns a list of browsers currently used for the scope of operations_
  95. ```js
  96. caniuse.getBrowserScope()
  97. /*
  98. [ 'and_chr',
  99. 'and_ff',
  100. 'and_qq',
  101. 'and_uc',
  102. 'android',
  103. 'baidu',
  104. 'chrome',
  105. 'edge',
  106. 'firefox',
  107. 'ie',
  108. 'ie_mob',
  109. 'ios_saf',
  110. 'op_mini',
  111. 'op_mob',
  112. 'opera',
  113. 'safari',
  114. 'samsung' ]
  115. */
  116. ```
  117. #### `caniuse.setBrowserScope(browserscope)`
  118. _if you do not like the default browser scope, you can set it globally by using this method_
  119. * browserscope should be a 'autoprefixer' formatted string
  120. ```js
  121. caniuse.setBrowserScope('> 5%, last 2 versions, Firefox ESR, Opera 12.1')
  122. ```
  123. ---
  124. ## [Changelog](CHANGELOG.md)
  125. ## [License](LICENSE)