node package manager

ordinal

Letters following a numeral denoting that it is an ordinal number

ordinal

Letters following a numeral denoting that it is an ordinal number.

npm install ordinal

Use with numbers or numeric strings. Anything else will throw an exception.

var ordinal = require('ordinal');

ordinal(1);   //=> '1st'
ordinal(2);   //=> '2nd'
ordinal(3);   //=> '3rd'
ordinal(4);   //=> '4th'

ordinal(11);  //=> '11th'
ordinal(12);  //=> '12th'
ordinal(13);  //=> '13th'

ordinal(21);  //=> '21st'
ordinal(22);  //=> '22nd'
ordinal(23);  //=> '23rd'
ordinal(24);  //=> '24th'

// Behaves correctly when the tens digit of a number is 1.
ordinal(112); //=> '112th'

MIT