Files
shields/services/github/github-code-size.service.js
chris48s 151c70dd17 Add ability to format bytes as metric or IEC; affects [bundlejs bundlephobia ChromeWebStoreSize CratesSize DockerSize GithubRepoSize GithubCodeSize GithubSize NpmUnpackedSize SpigetDownloadSize steam VisualStudioAppCenterReleasesSize whatpulse] (#10547)
* add renderSizeBadge helper, use it everywhere

- switch from pretty-bytes to byte-size
- add renderSizeBadge() helper function
- match upstream conventions for metric/IEC units
- add new test helpers and use them in service tests

* unrelated: fix npm unpacked size query param schema

not strictly related to this PR
but I noticed it was broken

* chromewebstore: reformat size string, test against isIecFileSize
2024-12-01 19:53:26 +00:00

39 lines
996 B
JavaScript

import { pathParams } from '../index.js'
import { renderSizeBadge } from '../size.js'
import { BaseGithubLanguage } from './github-languages-base.js'
import { documentation } from './github-helpers.js'
export default class GithubCodeSize extends BaseGithubLanguage {
static category = 'size'
static route = {
base: 'github/languages/code-size',
pattern: ':user/:repo',
}
static openApi = {
'/github/languages/code-size/{user}/{repo}': {
get: {
summary: 'GitHub code size in bytes',
description: documentation,
parameters: pathParams(
{
name: 'user',
example: 'badges',
},
{
name: 'repo',
example: 'shields',
},
),
},
},
}
static defaultBadgeData = { label: 'code size' }
async handle({ user, repo }) {
const data = await this.fetch({ user, repo })
return renderSizeBadge(this.getTotalSize(data), 'iec', 'code size')
}
}