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