@@ -9,7 +9,6 @@ import type { PackageLikes } from '#shared/types/social'
99import { encodePackageName } from '#shared/utils/npm'
1010import type { PackageAnalysisResponse } from './usePackageAnalysis'
1111import { isBinaryOnlyPackage } from '#shared/utils/binary-detection'
12- import { formatBytes } from '~/utils/formatters'
1312import { getDependencyCount } from '~/utils/npm/dependency-count'
1413
1514/** Special identifier for the "What Would James Do?" comparison column */
@@ -71,6 +70,9 @@ export interface PackageComparisonData {
7170 */
7271export function usePackageComparison ( packageNames : MaybeRefOrGetter < string [ ] > ) {
7372 const { t } = useI18n ( )
73+ const numberFormatter = useNumberFormatter ( )
74+ const compactNumberFormatter = useCompactNumberFormatter ( )
75+ const bytesFormatter = useBytesFormatter ( )
7476 const packages = computed ( ( ) => toValue ( packageNames ) )
7577
7678 // Cache of fetched data by package name (source of truth)
@@ -260,7 +262,14 @@ export function usePackageComparison(packageNames: MaybeRefOrGetter<string[]>) {
260262
261263 return packagesData . value . map ( pkg => {
262264 if ( ! pkg ) return null
263- return computeFacetValue ( facet , pkg , t )
265+ return computeFacetValue (
266+ facet ,
267+ pkg ,
268+ numberFormatter . value . format ,
269+ compactNumberFormatter . value . format ,
270+ bytesFormatter . format ,
271+ t ,
272+ )
264273 } )
265274 }
266275
@@ -342,6 +351,9 @@ function resolveNoDependencyDisplay(
342351function computeFacetValue (
343352 facet : ComparisonFacet ,
344353 data : PackageComparisonData ,
354+ formatNumber : ( num : number ) => string ,
355+ formatCompactNumber : ( num : number ) => string ,
356+ formatBytes : ( num : number ) => string ,
345357 t : ( key : string , params ?: Record < string , unknown > ) => string ,
346358) : FacetValue | null {
347359 const { isNoDependency } = data
@@ -513,7 +525,7 @@ function computeFacetValue(
513525 if ( depCount == null ) return null
514526 return {
515527 raw : depCount ,
516- display : String ( depCount ) ,
528+ display : formatNumber ( depCount ) ,
517529 status : depCount > 10 ? 'warning' : 'neutral' ,
518530 }
519531 }
@@ -532,7 +544,7 @@ function computeFacetValue(
532544 const totalDepCount = data . installSize . dependencyCount
533545 return {
534546 raw : totalDepCount ,
535- display : String ( totalDepCount ) ,
547+ display : formatNumber ( totalDepCount ) ,
536548 status : totalDepCount > 50 ? 'warning' : 'neutral' ,
537549 }
538550 }
0 commit comments