]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/shared/angular/number-formatter.pipe.ts
Add checkbox focus shadows, and admin resolution descriptions
[github/Chocobozzz/PeerTube.git] / client / src / app / shared / angular / number-formatter.pipe.ts
CommitLineData
9bf9d2a5
C
1import { Pipe, PipeTransform } from '@angular/core'
2
3// Thanks: https://github.com/danrevah/ngx-pipes/blob/master/src/pipes/math/bytes.ts
4
be447678 5@Pipe({ name: 'myNumberFormatter' })
9bf9d2a5
C
6export class NumberFormatterPipe implements PipeTransform {
7 private dictionary: Array<{max: number, type: string}> = [
8 { max: 1000, type: '' },
9 { max: 1000000, type: 'K' },
10 { max: 1000000000, type: 'M' }
11 ]
12
13 transform (value: number) {
14 const format = this.dictionary.find(d => value < d.max) || this.dictionary[this.dictionary.length - 1]
15 const calc = Math.floor(value / (format.max / 1000))
16
17 return `${calc}${format.type}`
18 }
19}