From 693263e936763a851e3c8c020e3739def8bd4eca Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 4 Apr 2019 10:44:18 +0200 Subject: Refactor videos selection components --- .../src/app/shared/angular/number-formatter.pipe.ts | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 client/src/app/shared/angular/number-formatter.pipe.ts (limited to 'client/src/app/shared/angular/number-formatter.pipe.ts') diff --git a/client/src/app/shared/angular/number-formatter.pipe.ts b/client/src/app/shared/angular/number-formatter.pipe.ts new file mode 100644 index 000000000..8a0756a36 --- /dev/null +++ b/client/src/app/shared/angular/number-formatter.pipe.ts @@ -0,0 +1,19 @@ +import { Pipe, PipeTransform } from '@angular/core' + +// Thanks: https://github.com/danrevah/ngx-pipes/blob/master/src/pipes/math/bytes.ts + +@Pipe({ name: 'myNumberFormatter' }) +export class NumberFormatterPipe implements PipeTransform { + private dictionary: Array<{max: number, type: string}> = [ + { max: 1000, type: '' }, + { max: 1000000, type: 'K' }, + { max: 1000000000, type: 'M' } + ] + + transform (value: number) { + const format = this.dictionary.find(d => value < d.max) || this.dictionary[this.dictionary.length - 1] + const calc = Math.floor(value / (format.max / 1000)) + + return `${calc}${format.type}` + } +} -- cgit v1.2.3