* Build(deps-dev): bump eslint-plugin-import from 2.17.3 to 2.18.0 Bumps [eslint-plugin-import](https://github.com/benmosher/eslint-plugin-import) from 2.17.3 to 2.18.0. - [Release notes](https://github.com/benmosher/eslint-plugin-import/releases) - [Changelog](https://github.com/benmosher/eslint-plugin-import/blob/master/CHANGELOG.md) - [Commits](https://github.com/benmosher/eslint-plugin-import/compare/v2.17.3...v2.18.0) Signed-off-by: dependabot-preview[bot] <support@dependabot.com> * Autofixes
112 lines
2.8 KiB
JavaScript
112 lines
2.8 KiB
JavaScript
'use strict'
|
|
|
|
const Joi = require('@hapi/joi')
|
|
const prettyBytes = require('pretty-bytes')
|
|
const { nonNegativeInteger } = require('../validators')
|
|
const { BaseJsonService } = require('..')
|
|
|
|
const schema = Joi.object({
|
|
size: nonNegativeInteger,
|
|
gzip: nonNegativeInteger,
|
|
}).required()
|
|
|
|
const keywords = ['node', 'bundlephobia']
|
|
|
|
module.exports = class Bundlephobia extends BaseJsonService {
|
|
static get category() {
|
|
return 'size'
|
|
}
|
|
|
|
static get route() {
|
|
return {
|
|
base: 'bundlephobia',
|
|
pattern: ':format(min|minzip)/:scope(@[^/]+)?/:packageName/:version?',
|
|
}
|
|
}
|
|
|
|
static get examples() {
|
|
return [
|
|
{
|
|
title: 'npm bundle size',
|
|
pattern: ':format(min|minzip)/:packageName',
|
|
namedParams: {
|
|
format: 'min',
|
|
packageName: 'react',
|
|
},
|
|
staticPreview: this.render({ format: 'min', size: 6652 }),
|
|
keywords,
|
|
},
|
|
{
|
|
title: 'npm bundle size (scoped)',
|
|
pattern: ':format(min|minzip)/:scope/:packageName',
|
|
namedParams: {
|
|
format: 'min',
|
|
scope: '@cycle',
|
|
packageName: 'core',
|
|
},
|
|
staticPreview: this.render({ format: 'min', size: 3562 }),
|
|
keywords,
|
|
},
|
|
{
|
|
title: 'npm bundle size (version)',
|
|
pattern: ':format(min|minzip)/:packageName/:version',
|
|
namedParams: {
|
|
format: 'min',
|
|
packageName: 'react',
|
|
version: '15.0.0',
|
|
},
|
|
staticPreview: this.render({ format: 'min', size: 20535 }),
|
|
keywords,
|
|
},
|
|
{
|
|
title: 'npm bundle size (scoped version)',
|
|
pattern: ':format(min|minzip)/:scope/:packageName/:version',
|
|
namedParams: {
|
|
format: 'min',
|
|
scope: '@cycle',
|
|
packageName: 'core',
|
|
version: '7.0.0',
|
|
},
|
|
staticPreview: this.render({ format: 'min', size: 3562 }),
|
|
keywords,
|
|
},
|
|
]
|
|
}
|
|
|
|
static get defaultBadgeData() {
|
|
return {
|
|
label: 'bundlephobia',
|
|
color: 'informational',
|
|
}
|
|
}
|
|
|
|
static render({ format, size }) {
|
|
const label = format === 'min' ? 'minified size' : 'minzipped size'
|
|
return {
|
|
label,
|
|
message: prettyBytes(size),
|
|
}
|
|
}
|
|
|
|
async fetch({ scope, packageName, version }) {
|
|
const packageQuery = `${scope ? `${scope}/` : ''}${packageName}${
|
|
version ? `@${version}` : ''
|
|
}`
|
|
const options = { qs: { package: packageQuery } }
|
|
return this._requestJson({
|
|
schema,
|
|
url: 'https://bundlephobia.com/api/size',
|
|
options,
|
|
errorMessages: {
|
|
404: 'package or version not found',
|
|
},
|
|
})
|
|
}
|
|
|
|
async handle({ format, scope, packageName, version }) {
|
|
const json = await this.fetch({ scope, packageName, version })
|
|
const size = format === 'min' ? json.size : json.gzip
|
|
return this.constructor.render({ format, size })
|
|
}
|
|
}
|