Last active
May 15, 2018 09:07
-
-
Save sillygwailo/6913981 to your computer and use it in GitHub Desktop.
Node module to provide the correct article for words starting with vowels
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
TODO: * An article that starts a sentence should be capitalized. | |
* A more comprehensive list of subtleties like "a useful", "a once", "an hour", "an historical" | |
* Tests | |
*/ | |
exports.article = function(text) { | |
var vowels = 'aeiou'; | |
var an_exceptions = ['eucalyptus', 'eunuch', 'euphemism', 'euphemistic', 'euphonium', 'euphoric', 'european', 'once', 'one', 'onesie', 'union', 'unique', 'unison', 'united', 'useful', 'utopia', 'utopic', 'user', 'unicorn']; | |
var a_exceptions = ['hour', 'historical', 'honorable', 'honourable']; | |
if (a_exceptions.indexOf(text) != -1 || (vowels.indexOf(text.charAt(1)) == -1 && an_exceptions.indexOf(text) == -1)) { | |
return 'an'; | |
} | |
else { | |
return 'a'; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment