UNPKG

ordinal-number-suffix

Version:
32 lines (29 loc) 537 B
/** * Get the ordinal number with suffix from `n` * * @api public * @param {Number} n * @return {String} */ exports = module.exports = function (n) { return n + exports.suffix(+n); }; /** * Get the suffix for the given `n` * * @api private * @param {Number} n * @return {String} */ exports.suffix = function (n) { n %= 100 return Math.floor(n / 10) === 1 ? 'th' : (n % 10 === 1 ? 'st' : (n % 10 === 2 ? 'nd' : (n % 10 === 3 ? 'rd' : 'th'))); };