mirror of
				https://github.com/Unleash/unleash.git
				synced 2025-10-27 11:02:16 +01:00 
			
		
		
		
	refactor: centralize number formatting (#10716)
This commit is contained in:
		
							parent
							
								
									921130a9c0
								
							
						
					
					
						commit
						c2b598d8d9
					
				| @ -7,14 +7,14 @@ describe('formatLargeNumbers', () => { | |||||||
|     }); |     }); | ||||||
| 
 | 
 | ||||||
|     it('formats thousands correctly', () => { |     it('formats thousands correctly', () => { | ||||||
|         expect(formatLargeNumbers(1000)).toBe('1k'); |         expect(formatLargeNumbers(1000)).toBe('1K'); | ||||||
|         expect(formatLargeNumbers(1200)).toBe('1.2k'); |         expect(formatLargeNumbers(1200)).toBe('1.2K'); | ||||||
|         expect(formatLargeNumbers(1400)).toBe('1.4k'); |         expect(formatLargeNumbers(1400)).toBe('1.4K'); | ||||||
|         expect(formatLargeNumbers(1600)).toBe('1.6k'); |         expect(formatLargeNumbers(1600)).toBe('1.6K'); | ||||||
|         expect(formatLargeNumbers(5000)).toBe('5k'); |         expect(formatLargeNumbers(5000)).toBe('5K'); | ||||||
|         expect(formatLargeNumbers(9500)).toBe('9.5k'); |         expect(formatLargeNumbers(9500)).toBe('9.5K'); | ||||||
|         expect(formatLargeNumbers(10000)).toBe('10k'); |         expect(formatLargeNumbers(10000)).toBe('10K'); | ||||||
|         expect(formatLargeNumbers(999000)).toBe('999k'); |         expect(formatLargeNumbers(999000)).toBe('999K'); | ||||||
|     }); |     }); | ||||||
| 
 | 
 | ||||||
|     it('formats millions correctly', () => { |     it('formats millions correctly', () => { | ||||||
|  | |||||||
| @ -53,11 +53,7 @@ export const getSeriesLabel = (metric: Record<string, string>): string => { | |||||||
|     return `${__name__} (${labelParts})`; |     return `${__name__} (${labelParts})`; | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| export const formatLargeNumbers = (value: number): string => { | export const formatLargeNumbers = prettifyLargeNumber(1000, 1); | ||||||
|     const formatter = prettifyLargeNumber(1000, 1); |  | ||||||
|     const result = formatter(value); |  | ||||||
|     return result.replace(/K/g, 'k'); |  | ||||||
| }; |  | ||||||
| 
 | 
 | ||||||
| export const getMetricType = (seriesName: string) => { | export const getMetricType = (seriesName: string) => { | ||||||
|     if (seriesName.startsWith('unleash_counter_')) return 'counter'; |     if (seriesName.startsWith('unleash_counter_')) return 'counter'; | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user