index.d.ts 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  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. * Throw a error if env is not found.
  40. */
  41. throwOnMissing?: boolean
  42. /**
  43. * Disable security checks for extend query.
  44. */
  45. dangerousExtend?: boolean
  46. /**
  47. * Alias mobile browsers to the desktop version when Can I Use
  48. * doesn’t have data about the specified version.
  49. */
  50. mobileToDesktop?: boolean
  51. }
  52. type Config = {
  53. defaults: string[]
  54. [section: string]: string[] | undefined
  55. }
  56. interface Stats {
  57. [browser: string]: {
  58. [version: string]: number
  59. }
  60. }
  61. /**
  62. * Browser names aliases.
  63. */
  64. let aliases: {
  65. [alias: string]: string | undefined
  66. }
  67. /**
  68. * Aliases to work with joined versions like `ios_saf 7.0-7.1`.
  69. */
  70. let versionAliases: {
  71. [browser: string]:
  72. | {
  73. [version: string]: string | undefined
  74. }
  75. | undefined
  76. }
  77. /**
  78. * Can I Use only provides a few versions for some browsers (e.g. `and_chr`).
  79. *
  80. * Fallback to a similar browser for unknown versions.
  81. */
  82. let desktopNames: {
  83. [browser: string]: string | undefined
  84. }
  85. let data: {
  86. [browser: string]:
  87. | {
  88. name: string
  89. versions: string[]
  90. released: string[]
  91. releaseDate: {
  92. [version: string]: number | undefined | null
  93. }
  94. }
  95. | undefined
  96. }
  97. let nodeVersions: string[]
  98. interface Usage {
  99. [version: string]: number
  100. }
  101. let usage: {
  102. global?: Usage
  103. custom?: Usage | null
  104. [country: string]: Usage | undefined | null
  105. }
  106. let cache: {
  107. [feature: string]: {
  108. [name: string]: 'y' | 'n'
  109. }
  110. }
  111. /**
  112. * Default browsers query
  113. */
  114. let defaults: readonly string[]
  115. /**
  116. * Which statistics should be used. Country code or custom statistics.
  117. * Pass `"my stats"` to load statistics from `Browserslist` files.
  118. */
  119. type StatsOptions = string | 'my stats' | Stats | { dataByBrowser: Stats }
  120. /**
  121. * Return browsers market coverage.
  122. *
  123. * ```js
  124. * browserslist.coverage(browserslist('> 1% in US'), 'US') //=> 83.1
  125. * ```
  126. *
  127. * @param browsers Browsers names in Can I Use.
  128. * @param stats Which statistics should be used.
  129. * @returns Total market coverage for all selected browsers.
  130. */
  131. function coverage(browsers: readonly string[], stats?: StatsOptions): number
  132. function clearCaches(): void
  133. function parseConfig(string: string): Config
  134. function readConfig(file: string): Config
  135. function findConfig(...pathSegments: string[]): Config | undefined
  136. interface LoadConfigOptions {
  137. config?: string
  138. path?: string
  139. env?: string
  140. }
  141. function loadConfig(options: LoadConfigOptions): string[] | undefined
  142. }
  143. declare global {
  144. namespace NodeJS {
  145. interface ProcessEnv {
  146. BROWSERSLIST?: string
  147. BROWSERSLIST_CONFIG?: string
  148. BROWSERSLIST_DANGEROUS_EXTEND?: string
  149. BROWSERSLIST_DISABLE_CACHE?: string
  150. BROWSERSLIST_ENV?: string
  151. BROWSERSLIST_IGNORE_OLD_DATA?: string
  152. BROWSERSLIST_STATS?: string
  153. }
  154. }
  155. }
  156. export = browserslist