index.d.ts 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  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]: {
  116. [version: string]: string
  117. }
  118. }
  119. }
  120. /**
  121. * Default browsers query
  122. */
  123. let defaults: readonly string[]
  124. /**
  125. * Which statistics should be used. Country code or custom statistics.
  126. * Pass `"my stats"` to load statistics from `Browserslist` files.
  127. */
  128. type StatsOptions = string | 'my stats' | Stats | { dataByBrowser: Stats }
  129. /**
  130. * Return browsers market coverage.
  131. *
  132. * ```js
  133. * browserslist.coverage(browserslist('> 1% in US'), 'US') //=> 83.1
  134. * ```
  135. *
  136. * @param browsers Browsers names in Can I Use.
  137. * @param stats Which statistics should be used.
  138. * @returns Total market coverage for all selected browsers.
  139. */
  140. function coverage(browsers: readonly string[], stats?: StatsOptions): number
  141. /**
  142. * Get queries AST to analyze the config content.
  143. *
  144. * @param queries Browser queries.
  145. * @param opts Options.
  146. * @returns An array of the data of each query in the config.
  147. */
  148. function parse(
  149. queries?: string | readonly string[] | null,
  150. opts?: browserslist.Options
  151. ): Query[]
  152. /**
  153. * Return queries for specific file inside the project.
  154. *
  155. * ```js
  156. * browserslist.loadConfig({
  157. * file: process.cwd()
  158. * }) ?? browserslist.defaults
  159. * ```
  160. */
  161. function loadConfig(options: LoadConfigOptions): string[] | undefined
  162. function clearCaches(): void
  163. function parseConfig(string: string): Config
  164. function readConfig(file: string): Config
  165. function findConfig(...pathSegments: string[]): Config | undefined
  166. function findConfigFile(...pathSegments: string[]): string | undefined
  167. interface LoadConfigOptions {
  168. /**
  169. * Path to config file
  170. * */
  171. config?: string
  172. /**
  173. * Path to file inside the project to find Browserslist config
  174. * in closest folder
  175. */
  176. path?: string
  177. /**
  178. * Environment to choose part of config.
  179. */
  180. env?: string
  181. }
  182. }
  183. declare global {
  184. namespace NodeJS {
  185. interface ProcessEnv {
  186. BROWSERSLIST?: string
  187. BROWSERSLIST_CONFIG?: string
  188. BROWSERSLIST_DANGEROUS_EXTEND?: string
  189. BROWSERSLIST_DISABLE_CACHE?: string
  190. BROWSERSLIST_ENV?: string
  191. BROWSERSLIST_IGNORE_OLD_DATA?: string
  192. BROWSERSLIST_STATS?: string
  193. BROWSERSLIST_ROOT_PATH?: string
  194. }
  195. }
  196. }
  197. export = browserslist