import { badgen } from 'badgen' ; import { getReadableFileSize , getHexColor } from './npm-parser' ; import { pages , productionHostname } from '../util/constants' ; export function getBadgeSvg ( pkgSize ) { const { installSize } = pkgSize ; const { pretty } = getReadableFileSize ( installSize ) ; return badgen ( { label : 'install size' , status : pretty , color : getHexColor ( installSize ) , } ) ; } export function getBadgeUrl ( pkgSize , isLatest ) { const { name , version } = pkgSize ; const pkgNameAndVersion = isLatest ? name : `${ name }@${ version }` ; return `https://${ productionHostname }${ pages . badge }?p=${ pkgNameAndVersion }` ; } export function getBadgeMarkdown ( pkgNameAndVersion ) { const badgePage = `https://${ productionHostname }${ pages . badge }?p=${ pkgNameAndVersion }` ; const resultPage = `https://${ productionHostname }${ pages . result }?p=${ pkgNameAndVersion }` ; return `[![install size](${ badgePage })](${ resultPage })` ; } export function getApiResponseSize ( bytes , files ) { const { pretty } = getReadableFileSize ( bytes ) ; const color = '#' + getHexColor ( bytes ) ; return { bytes , files , pretty , color } ; }