index.d.ts 4.3 KB

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