diff --git a/app/package/js/ordinal.js b/app/package/js/ordinal.js new file mode 100644 index 0000000..845a194 --- /dev/null +++ b/app/package/js/ordinal.js @@ -0,0 +1,24 @@ +/* global angular */ + +angular + .module('ordinal', []) + .factory('ordinalService', function () { + var ordinal = function (input) { + var n = input % 100; + return n === 0 ? 'th' : (n < 11 || n > 13) ? + ['st', 'nd', 'rd', 'th'][Math.min((n - 1) % 10, 3)] : 'th'; + }; + return { + ordinal: ordinal + }; + }) + .filter('ordinal', ['ordinalService', function (ordinalService) { + return function (input) { + return input + ordinalService.ordinal(input); + }; + }]) + .filter('ordinalOnly', ['ordinalService', function (ordinalService) { + return function (input) { + return ordinalService.ordinal(input); + }; + }]); diff --git a/app/package/js/ordinal.min.js b/app/package/js/ordinal.min.js new file mode 100644 index 0000000..ad0949b --- /dev/null +++ b/app/package/js/ordinal.min.js @@ -0,0 +1 @@ +angular.module("ordinal",[]).factory("ordinalService",function(){var n=function(n){var r=n%100;return 0===r?"th":11>r||r>13?["st","nd","rd","th"][Math.min((r-1)%10,3)]:"th"};return{ordinal:n}}).filter("ordinal",["ordinalService",function(n){return function(r){return r+n.ordinal(r)}}]).filter("ordinalOnly",["ordinalService",function(n){return function(r){return n.ordinal(r)}}]); \ No newline at end of file