diff options
Diffstat (limited to 'src/pybind/mgr/dashboard/frontend/src/app/shared/pipes/ordinal.pipe.ts')
-rw-r--r-- | src/pybind/mgr/dashboard/frontend/src/app/shared/pipes/ordinal.pipe.ts | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/src/pybind/mgr/dashboard/frontend/src/app/shared/pipes/ordinal.pipe.ts b/src/pybind/mgr/dashboard/frontend/src/app/shared/pipes/ordinal.pipe.ts new file mode 100644 index 000000000..da89a0240 --- /dev/null +++ b/src/pybind/mgr/dashboard/frontend/src/app/shared/pipes/ordinal.pipe.ts @@ -0,0 +1,25 @@ +import { Pipe, PipeTransform } from '@angular/core'; + +@Pipe({ + name: 'ordinal' +}) +export class OrdinalPipe implements PipeTransform { + transform(value: any): any { + const num = parseInt(value, 10); + if (isNaN(num)) { + return value; + } + return ( + value + + (Math.floor(num / 10) === 1 + ? 'th' + : num % 10 === 1 + ? 'st' + : num % 10 === 2 + ? 'nd' + : num % 10 === 3 + ? 'rd' + : 'th') + ); + } +} |