b36805edd796fbbfe458521cf68e4c11584b88a44e196f330cd37c8ad43c09fb8659ed6c9fe3f5a2fe8600eed9af43c241f59f7e5f3afbb667f678a93e281c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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. $ npm install caniuse-api --save
  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. [ safari: { y: 3.1, x: 4 },
  27. opera: { n: 10, y: 10.5 },
  28. ios_saf: { y: 3.2, x: 3.2 },
  29. ie_mob: { y: 10 },
  30. ie: { n: 8, y: 9 },
  31. firefox: { a: 2, x: 3.6, y: 3 },
  32. chrome: { y: 4, x: 4 },
  33. and_chr: { y: 39 } ]
  34. */
  35. ```
  36. #### `caniuse.isSupported(feature, browsers)`
  37. _ask if a feature is supported by some browsers_
  38. ```js
  39. caniuse.isSupported('border-radius', 'ie 8, ie 9') // false
  40. caniuse.isSupported('border-radius', 'ie 9') // true
  41. ```
  42. #### `caniuse.find(query)`
  43. _search for a caniuse feature name_
  44. Ex:
  45. ```js
  46. caniuse.find('radius') // ['border-radius']
  47. caniuse.find('nothingness') // []
  48. caniuse.find('css3')
  49. /*
  50. [ 'css3-boxsizing',
  51. 'css3-colors',
  52. 'css3-cursors-newer',
  53. 'css3-cursors',
  54. 'css3-tabsize' ]
  55. */
  56. ```
  57. #### `caniuse.getLatestStableBrowsers()`
  58. _get the current version for each browser_
  59. ```js
  60. caniuse.getLatestStableBrowsers()
  61. /*
  62. [ 'safari 8',
  63. 'opera 26',
  64. 'ios_saf 8.1',
  65. 'ie_mob 11',
  66. 'ie 11',
  67. 'firefox 33',
  68. 'chrome 39' ]
  69. */
  70. ```
  71. #### `caniuse.getBrowserScope()`
  72. _returns a list of browsers currently used for the scope of operations_
  73. ```js
  74. caniuse.getBrowserScope()
  75. /*
  76. [ 'safari',
  77. 'opera',
  78. 'op_mini',
  79. 'ios_saf',
  80. 'ie_mob',
  81. 'ie',
  82. 'firefox',
  83. 'chrome',
  84. 'android',
  85. 'and_uc',
  86. 'and_chr' ]
  87. */
  88. ```
  89. #### `caniuse.setBrowserScope(browserscope)`
  90. _if you do not like the default browser scope, you can set it globally by using this method_
  91. * browserscope should be a 'autoprefixer' formatted string
  92. ```js
  93. caniuse.setBrowserScope('> 5%, last 2 versions, Firefox ESR, Opera 12.1')
  94. ```
  95. ---
  96. ## [Changelog](CHANGELOG.md)
  97. ## [License](LICENSE)