Created
July 5, 2015 18:25
-
-
Save donald-slagle/c3995f75218b0fbc3f84 to your computer and use it in GitHub Desktop.
Aurelia ordinal string value converter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Based off of ordinal converter function found at https://gist.github.com/jlbruno/1535691 | |
* example: | |
* <tr repeat.for="item of items"> | |
* <td>${($index + 1) | ordinal} item</td> | |
* </tr> | |
**/ | |
export class OrdinalValueConverter { | |
s = ["th","st","nd","rd"]; | |
toView(value) { | |
return this.getOrdinal(value); | |
} | |
getOrdinal(n) { | |
var v = n % 100; | |
return n + (this.s[(v - 20) % 10] || this.s[v] || this.s[0]); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment