Skip to content

Instantly share code, notes, and snippets.

@Qarun-Qadir-Bissoondial
Created April 9, 2020 13:34
Show Gist options
  • Save Qarun-Qadir-Bissoondial/49545f609e242c30a4118dd4a8c8b527 to your computer and use it in GitHub Desktop.
Save Qarun-Qadir-Bissoondial/49545f609e242c30a4118dd4a8c8b527 to your computer and use it in GitHub Desktop.
Pipes Demo - Order Suffix Pipe (part 2)
import { Pipe, PipeTransform } from '@angular/core';
@Pipe({
name: 'orderSuffix'
})
export class OrderSuffixPipe implements PipeTransform {
suffixMap = {
1: 'st',
2: 'nd',
3: 'rd'
};
transform(value: number, args?: any): string {
const lastDigit = value % 10;
const suffix = this.suffixMap[lastDigit];
return !suffix
? `${value}th`
: `${value}${suffix}`;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment