Skip to content

Commit

Permalink
Move to Prettier and update ESLint config
Browse files Browse the repository at this point in the history
  • Loading branch information
ai committed Nov 2, 2021
1 parent 1c87364 commit f5e85f7
Show file tree
Hide file tree
Showing 20 changed files with 615 additions and 743 deletions.
26 changes: 15 additions & 11 deletions browser.js
Original file line number Diff line number Diff line change
@@ -1,36 +1,40 @@
var BrowserslistError = require('./error')

function noop () { }
function noop() {}

module.exports = {
loadQueries: function loadQueries () {
loadQueries: function loadQueries() {
throw new BrowserslistError(
'Sharable configs are not supported in client-side build of Browserslist')
'Sharable configs are not supported in client-side build of Browserslist'
)
},

getStat: function getStat (opts) {
getStat: function getStat(opts) {
return opts.stats
},

loadConfig: function loadConfig (opts) {
loadConfig: function loadConfig(opts) {
if (opts.config) {
throw new BrowserslistError(
'Browserslist config are not supported in client-side build')
'Browserslist config are not supported in client-side build'
)
}
},

loadCountry: function loadCountry () {
loadCountry: function loadCountry() {
throw new BrowserslistError(
'Country statistics are not supported ' +
'in client-side build of Browserslist')
'in client-side build of Browserslist'
)
},

loadFeature: function loadFeature () {
loadFeature: function loadFeature() {
throw new BrowserslistError(
'Supports queries are not available in client-side build of Browserslist')
'Supports queries are not available in client-side build of Browserslist'
)
},

currentNode: function currentNode (resolve, context) {
currentNode: function currentNode(resolve, context) {
return resolve(['maintained node versions'], context)[0]
},

Expand Down
35 changes: 18 additions & 17 deletions cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,27 @@ var pkg = require('./package.json')

var args = process.argv.slice(2)

var USAGE = 'Usage:\n' +
' npx browserslist\n' +
' npx browserslist "QUERIES"\n' +
' npx browserslist --json "QUERIES"\n' +
' npx browserslist --config="path/to/browserlist/file"\n' +
' npx browserslist --coverage "QUERIES"\n' +
' npx browserslist --coverage=US "QUERIES"\n' +
' npx browserslist --coverage=US,RU,global "QUERIES"\n' +
' npx browserslist --env="environment name defined in config"\n' +
' npx browserslist --stats="path/to/browserlist/stats/file"\n' +
' npx browserslist --mobile-to-desktop\n' +
' npx browserslist --update-db'

function isArg (arg) {
var USAGE =
'Usage:\n' +
' npx browserslist\n' +
' npx browserslist "QUERIES"\n' +
' npx browserslist --json "QUERIES"\n' +
' npx browserslist --config="path/to/browserlist/file"\n' +
' npx browserslist --coverage "QUERIES"\n' +
' npx browserslist --coverage=US "QUERIES"\n' +
' npx browserslist --coverage=US,RU,global "QUERIES"\n' +
' npx browserslist --env="environment name defined in config"\n' +
' npx browserslist --stats="path/to/browserlist/stats/file"\n' +
' npx browserslist --mobile-to-desktop\n' +
' npx browserslist --update-db'

function isArg(arg) {
return args.some(function (str) {
return str === arg || str.indexOf(arg + '=') === 0
})
}

function error (msg) {
function error(msg) {
process.stderr.write('browserslist: ' + msg + '\n')
process.exit(1)
}
Expand All @@ -42,7 +43,7 @@ if (isArg('--help') || isArg('-h')) {
})
} else {
var mode = 'browsers'
var opts = { }
var opts = {}
var queries
var areas

Expand Down Expand Up @@ -138,7 +139,7 @@ if (isArg('--help') || isArg('-h')) {
data.coverage = coverage.reduce(function (object, j) {
object[j[0]] = j[1]
return object
}, { })
}, {})
}
process.stdout.write(JSON.stringify(data, null, ' ') + '\n')
}
Expand Down
2 changes: 1 addition & 1 deletion error.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function BrowserslistError (message) {
function BrowserslistError(message) {
this.name = 'BrowserslistError'
this.message = message
this.browserslist = true
Expand Down
14 changes: 7 additions & 7 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* @param queries Browser queries.
* @returns Array with browser names in Can I Use.
*/
declare function browserslist (
declare function browserslist(
queries?: string | readonly string[] | null,
opts?: browserslist.Options
): string[]
Expand Down Expand Up @@ -136,23 +136,23 @@ declare namespace browserslist {
* @param stats Which statistics should be used.
* @returns Total market coverage for all selected browsers.
*/
function coverage (browsers: readonly string[], stats?: StatsOptions): number
function coverage(browsers: readonly string[], stats?: StatsOptions): number

function clearCaches (): void
function clearCaches(): void

function parseConfig (string: string): Config
function parseConfig(string: string): Config

function readConfig (file: string): Config
function readConfig(file: string): Config

function findConfig (...pathSegments: string[]): Config | undefined
function findConfig(...pathSegments: string[]): Config | undefined

interface LoadConfigOptions {
config?: string
path?: string
env?: string
}

function loadConfig (options: LoadConfigOptions): string[] | undefined
function loadConfig(options: LoadConfigOptions): string[] | undefined
}

declare global {
Expand Down
Loading

0 comments on commit f5e85f7

Please sign in to comment.