Skip to content

Instantly share code, notes, and snippets.

@prosoftwaredev
Created March 24, 2018 03:00
Show Gist options
  • Save prosoftwaredev/2ae9825fe871ad248f40f39fcb09a20c to your computer and use it in GitHub Desktop.
Save prosoftwaredev/2ae9825fe871ad248f40f39fcb09a20c to your computer and use it in GitHub Desktop.
import { DecimalPipe } from "@angular/common";
import { Pipe, PipeTransform } from "@angular/core";
@Pipe({name: "currency"})
export class CurrencyPipe implements PipeTransform {
private assetFormats = {
"USD": "1.2-2",
"BTC": "1.6-6"
};
constructor(private decimalPipe: DecimalPipe) {}
transform(value: any, ...args: any[]): any {
const asset = args[0];
const format = this.assetFormats[asset];
if (format === undefined) {
throw new Error("Unknown asset type");
}
return this.decimalPipe.transform(value, format);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment