Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions src/utils/__tests__/numberFormat.utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
formatNumber,
formatCompactNumber,
formatFollowerCount,
formatHolderCount,
formatPercent,
} from '../numberFormat.utils';

Expand Down Expand Up @@ -145,6 +146,34 @@ describe('formatFollowerCount: Legacy follower abbreviation', () => {
});
});

// ---------------------------------------------------------------------------
// Feature: Holder count formatting
// Validates: Issue #438 acceptance criteria
// ---------------------------------------------------------------------------
describe('formatHolderCount: Holder count abbreviation', () => {
it('returns values under 1000 as a plain string', () => {
expect(formatHolderCount(0)).toBe('0');
expect(formatHolderCount(42)).toBe('42');
expect(formatHolderCount(999)).toBe('999');
});

it('formats values in the K range with one decimal place', () => {
expect(formatHolderCount(1200)).toBe('1.2K');
expect(formatHolderCount(1500)).toBe('1.5K');
expect(formatHolderCount(999_999)).toBe('1000K');
});

it('formats values in the M range with one decimal place', () => {
expect(formatHolderCount(2_400_000)).toBe('2.4M');
expect(formatHolderCount(1_250_000)).toBe('1.3M');
});

it('handles boundary values at 1000 and 1000000', () => {
expect(formatHolderCount(1000)).toBe('1K');
expect(formatHolderCount(1_000_000)).toBe('1M');
});
});

// ---------------------------------------------------------------------------
// Feature: Percentage formatting
// Validates: Acceptance Criteria for badge display
Expand Down
13 changes: 12 additions & 1 deletion src/utils/numberFormat.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,14 @@ export function formatCompactNumber(
return formatNumber(value, { ...options, style: 'compact' });
}

export function formatFollowerCount(count: number): string {
/**
* Formats holder counts for compact display across creator profile surfaces.
*
* - Below 1,000: plain string (e.g. `999`)
* - 1,000–999,999: one decimal K suffix (e.g. `1.2K`, `1K` at exactly 1,000)
* - 1,000,000+: one decimal M suffix (e.g. `2.4M`, `1M` at exactly 1,000,000)
*/
export function formatHolderCount(count: number): string {
if (count >= 1_000_000) {
return `${(count / 1_000_000).toFixed(1).replace(/\.0$/, '')}M`;
}
Expand All @@ -55,6 +62,10 @@ export function formatFollowerCount(count: number): string {
return count.toString();
}

export function formatFollowerCount(count: number): string {
return formatHolderCount(count);
}

export interface FormatPercentOptions {
/** Maximum fractional digits in the rendered value. Defaults to 2. */
maximumFractionDigits?: number;
Expand Down
Loading