Skip to content

Instantly share code, notes, and snippets.

@donald-slagle
Created July 5, 2015 18:25
Show Gist options
  • Save donald-slagle/c3995f75218b0fbc3f84 to your computer and use it in GitHub Desktop.
Save donald-slagle/c3995f75218b0fbc3f84 to your computer and use it in GitHub Desktop.
Aurelia ordinal string value converter
/**
* 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