Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ability to convert numbers to numeral adverbs #23

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
module.exports = {
toOrdinal: require('./toOrdinal'),
toWords: require('./toWords'),
toWordsOrdinal: require('./toWordsOrdinal')
toWordsOrdinal: require('./toWordsOrdinal'),
toWordsNumeralAdverb: require('./toWordsNumeralAdverb')
};
29 changes: 29 additions & 0 deletions src/toWordsNumeralAdverb.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
'use strict';

var toWords = require('./toWords');

numeralAdverbsLessThanFour = {
one: 'once',
two: 'twice',
three: 'thrice'
}

/**
* Converts a number into a numeral adverb.
* @example toWordsNumeralAdverb(12) => 'twelve times'
* @example toWordsNumeralAdverb(3, false) => 'thrice'
* @example toWordsNumeralAdverb(3, true) => 'three times'
* @param {number|string} number
* @param {boolean} ignoreThrice if thrice should be ignored for those who don't like it
* @returns {string}
*/
function toWordsNumeralAdverb(number, ignoreThrice = false) {
var words = toWords(number);
if (numeralAdverbsLessThanFour.hasOwnProperty(words) && (number !== 3 || !ignoreThrice)) {
return numeralAdverbsLessThanFour[words];
} else {
return words + ' times';

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 - One times <------------
2 - Two times
3 - Three times

}
}

module.exports = toWordsNumeralAdverb;