import numlang from 'numlang';
// Options
const options = {
useCommas: false,
useAnd: false,
appendOnly: false,
uppercase: false,
capitalize: false
};
// Convert to words
const words = numlang.toWords(12345, options);
// "twelve thousand three hundred forty-five"
// Convert to ordinal
const ordinal = numlang.toOrdinal(12345);
// "12345th"
// Convert to ordinal words
const ordinalWords = numlang.toWordsOrdinal(12345, options);
// "twelve thousand three hundred forty-fifth"
You can install numlang via npm:
npm install numlang
Or yarn:
yarn add numlang
Import the library:
// ES Modules
import numlang from 'numlang';
// or specific functions
import { toWords, toOrdinal, toWordsOrdinal } from 'numlang';
// CommonJS
const numlang = require('numlang');