index.d.ts 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. /**
  2. * Return array of browsers by selection queries.
  3. *
  4. * ```js
  5. * browserslist('IE >= 10, IE 8') //=> ['ie 11', 'ie 10', 'ie 8']
  6. * ```
  7. *
  8. * @param queries Browser queries.
  9. * @returns Array with browser names in Can I Use.
  10. */
  11. declare function browserslist (
  12. queries?: string | readonly string[] | null,
  13. opts?: browserslist.Options
  14. ): string[]
  15. declare namespace browserslist {
  16. interface Options {
  17. /**
  18. * Path to processed file. It will be used to find config files.
  19. */
  20. path?: string | false
  21. /**
  22. * Processing environment. It will be used to take right queries
  23. * from config file.
  24. */
  25. env?: string
  26. /**
  27. * Custom browser usage statistics for "> 1% in my stats" query.
  28. */
  29. stats?: Stats | string
  30. /**
  31. * Path to config file with queries.
  32. */
  33. config?: string
  34. /**
  35. * Do not throw on unknown version in direct query.
  36. */
  37. ignoreUnknownVersions?: boolean
  38. /**
  39. * Disable security checks for extend query.
  40. */
  41. dangerousExtend?: boolean
  42. /**
  43. * Alias mobile browsers to the desktop version when Can I Use
  44. * doesn’t have data about the specified version.
  45. */
  46. mobileToDesktop?: boolean
  47. }
  48. type Config = {
  49. defaults: string[]
  50. [section: string]: string[] | undefined
  51. }
  52. interface Stats {
  53. [browser: string]: {
  54. [version: string]: number
  55. }
  56. }
  57. /**
  58. * Browser names aliases.
  59. */
  60. let aliases: {
  61. [alias: string]: string | undefined
  62. }
  63. /**
  64. * Aliases to work with joined versions like `ios_saf 7.0-7.1`.
  65. */
  66. let versionAliases: {
  67. [browser: string]:
  68. | {
  69. [version: string]: string | undefined
  70. }
  71. | undefined
  72. }
  73. /**
  74. * Can I Use only provides a few versions for some browsers (e.g. `and_chr`).
  75. *
  76. * Fallback to a similar browser for unknown versions.
  77. */
  78. let desktopNames: {
  79. [browser: string]: string | undefined
  80. }
  81. let data: {
  82. [browser: string]:
  83. | {
  84. name: string
  85. versions: string[]
  86. released: string[]
  87. releaseDate: {
  88. [version: string]: number | undefined | null
  89. }
  90. }
  91. | undefined
  92. }
  93. interface Usage {
  94. [version: string]: number
  95. }
  96. let usage: {
  97. global?: Usage
  98. custom?: Usage | null
  99. [country: string]: Usage | undefined | null
  100. }
  101. let cache: {
  102. [feature: string]: {
  103. [name: string]: 'y' | 'n'
  104. }
  105. }
  106. /**
  107. * Default browsers query
  108. */
  109. let defaults: readonly string[]
  110. /**
  111. * Which statistics should be used. Country code or custom statistics.
  112. * Pass `"my stats"` to load statistics from `Browserslist` files.
  113. */
  114. type StatsOptions = string | 'my stats' | Stats | { dataByBrowser: Stats }
  115. /**
  116. * Return browsers market coverage.
  117. *
  118. * ```js
  119. * browserslist.coverage(browserslist('> 1% in US'), 'US') //=> 83.1
  120. * ```
  121. *
  122. * @param browsers Browsers names in Can I Use.
  123. * @param stats Which statistics should be used.
  124. * @returns Total market coverage for all selected browsers.
  125. */
  126. function coverage (browsers: readonly string[], stats?: StatsOptions): number
  127. function clearCaches (): void
  128. function parseConfig (string: string): Config
  129. function readConfig (file: string): Config
  130. function findConfig (...pathSegments: string[]): Config | undefined
  131. interface LoadConfigOptions {
  132. config?: string
  133. path?: string
  134. env?: string
  135. }
  136. function loadConfig (options: LoadConfigOptions): string[] | undefined
  137. }
  138. declare global {
  139. namespace NodeJS {
  140. interface ProcessEnv {
  141. BROWSERSLIST?: string
  142. BROWSERSLIST_CONFIG?: string
  143. BROWSERSLIST_DANGEROUS_EXTEND?: string
  144. BROWSERSLIST_DISABLE_CACHE?: string
  145. BROWSERSLIST_ENV?: string
  146. BROWSERSLIST_IGNORE_OLD_DATA?: string
  147. BROWSERSLIST_STATS?: string
  148. }
  149. }
  150. }
  151. export = browserslist