Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

indefinite

Package Overview
Dependencies
Maintainers
1
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

indefinite - npm Package Compare versions

Comparing version 2.0.2 to 2.0.3

lib/irregular-words.js

75

dist/indefinite.js

@@ -69,19 +69,33 @@ window["indefinite"] =

/* 0 */
/***/ (function(module, exports) {
/***/ (function(module, exports, __webpack_require__) {
var checkList = function checkList(word, ending) {
if (ending) {
// If the word ends in the ending, remove it.
var regex = new RegExp(ending + '$');
word = word.replace(regex, '');
}
var irregulars = __webpack_require__(1);
var ACRONYM = /^U[A-Z]+$/;
var STARTS_WITH_VOWEL = /^[aeiou]/;
var EXTRAS = /[\s'-]/;
return indefinite.irregularWords.indexOf(word) > -1;
var xor = function xor(a, b) {
return (a || b) && !(a && b);
};
var checkForAcronyms = function checkForAcronyms(word, caseInsensitive) {
return caseInsensitive ? false : ACRONYM.test(word.split(' ')[0]);
};
var cap = function cap(str) {
return '' + str.charAt(0).toUpperCase() + str.slice(1);
};
var indefinite = function indefinite(noun) {
// Try some variations on the word to determine whether it's irregular.
// Specifically, try trimming s, then es, then ed because those are common
// forms of plurals and past tense verbs (which can be used like adjectives).
var checkForIrregulars = function checkForIrregulars(part) {
return [null, 's', 'es', 'ed'].reduce(function (memo, ending) {
return memo || irregulars.check(part, ending);
}, false);
};
var indefinite = function indefinite(word) {
var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
var isAcronymWithU = opts.caseInsensitive ? false : /^U[A-Z]+$/.test(noun.split(' ')[0]);
var startsWithVowel = /[aeiou]/.test(noun.charAt(0).toLowerCase());
var isAcronymWithU = checkForAcronyms(word, opts.caseInsensitive);
var startsWithVowel = STARTS_WITH_VOWEL.test(word.toLowerCase());

@@ -91,10 +105,5 @@ // Only check the first word. Also, if it's hyphenated, only

// the possessive part.
var part = noun.split(/[\s'-]/)[0].toLowerCase();
var part = word.split(EXTRAS)[0].toLowerCase();
// Try some variations on the word to determine whether it's irregular.
// Specifically, try trimming s, then es, then ed because those are common
// forms of plurals and past tense verbs (which can be used like adjectives).
var isIrregular = [null, 's', 'es', 'ed'].reduce(function (memo, ending) {
return memo || checkList(part, ending);
}, false);
var isIrregular = checkForIrregulars(part);

@@ -108,9 +117,23 @@ /**

*/
var article = !isAcronymWithU && (startsWithVowel || isIrregular) && !(startsWithVowel && isIrregular) ? 'an' : 'a';
var article = !isAcronymWithU && xor(startsWithVowel, isIrregular) ? 'an' : 'a';
if (opts.capitalize) {
article = '' + article.charAt(0).toUpperCase() + article.slice(1);
return opts.capitalize ? cap(article) + ' ' + word : article + ' ' + word;
};
indefinite.irregularWords = irregulars.list;
module.exports = indefinite;
/***/ }),
/* 1 */
/***/ (function(module, exports) {
exports.check = function (word, ending) {
if (ending) {
// If the word ends in the ending, remove it.
var regex = new RegExp(ending + '$');
word = word.replace(regex, '');
}
return article + ' ' + noun;
return exports.list.indexOf(word) > -1;
};

@@ -136,3 +159,3 @@

*/
indefinite.irregularWords = [
exports.list = [
// Nouns: eu like y

@@ -148,3 +171,3 @@ 'eunuch', 'eucalyptus', 'eugenics', 'eulogy', 'euphemism', 'euphony', 'euphoria', 'eureka',

// Nouns: silent h
'herb', 'hour', 'heir', 'heiress', 'honesty', 'honor', 'honour',
'heir', 'heiress', 'herb', 'homage', 'honesty', 'honor', 'honour', 'hour',

@@ -155,3 +178,3 @@ // Adjectives: silent h

// Adverbs: silent h
'hourly', 'honestly',
'honestly', 'hourly',

@@ -181,5 +204,3 @@ // Nouns: o like w

module.exports = indefinite;
/***/ })
/******/ ]);

@@ -1,1 +0,1 @@

window.indefinite=function(u){function e(i){if(r[i])return r[i].exports;var n=r[i]={i:i,l:!1,exports:{}};return u[i].call(n.exports,n,n.exports,e),n.l=!0,n.exports}var r={};return e.m=u,e.c=r,e.d=function(u,r,i){e.o(u,r)||Object.defineProperty(u,r,{configurable:!1,enumerable:!0,get:i})},e.n=function(u){var r=u&&u.__esModule?function(){return u.default}:function(){return u};return e.d(r,"a",r),r},e.o=function(u,e){return Object.prototype.hasOwnProperty.call(u,e)},e.p="",e(e.s=0)}([function(u,e){var r=function(u,e){if(e){var r=new RegExp(e+"$");u=u.replace(r,"")}return i.irregularWords.indexOf(u)>-1},i=function(u){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},i=!e.caseInsensitive&&/^U[A-Z]+$/.test(u.split(" ")[0]),n=/[aeiou]/.test(u.charAt(0).toLowerCase()),t=u.split(/[\s'-]/)[0].toLowerCase(),o=[null,"s","es","ed"].reduce(function(u,e){return u||r(t,e)},!1),s=i||!n&&!o||n&&o?"a":"an";return e.capitalize&&(s=""+s.charAt(0).toUpperCase()+s.slice(1)),s+" "+u};i.irregularWords=["eunuch","eucalyptus","eugenics","eulogy","euphemism","euphony","euphoria","eureka","european","euphemistic","euphonic","euphoric","euphemistically","euphonically","euphorically","herb","hour","heir","heiress","honesty","honor","honour","honest","honorous","hourly","honestly","one","ouija","once","ubiquity","udometer","ufo","uke","ukelele","ululate","unicorn","unicycle","uniform","unify","union","unison","unit","unity","universe","university","upas","ural","uranium","urea","ureter","urethra","urine","urology","urus","usage","use","usual","usurp","usury","utensil","uterus","utility","utopia","utricle","uvarovite","uvea","uvula","ubiquitous","ugandan","ukrainian","unanimous","unicameral","unified","unique","unisex","universal","urinal","urological","useful","useless","usurious","usurped","utilitarian","utopic","ubiquitously","unanimously","unicamerally","uniquely","universally","urologically","usefully","uselessly","usuriously","yttria","yggdrasil","ylem","yperite","ytterbia","ytterbium","yttrium","ytterbous","ytterbic","yttric"],u.exports=i}]);
window.indefinite=function(u){function e(n){if(r[n])return r[n].exports;var i=r[n]={i:n,l:!1,exports:{}};return u[n].call(i.exports,i,i.exports,e),i.l=!0,i.exports}var r={};return e.m=u,e.c=r,e.d=function(u,r,n){e.o(u,r)||Object.defineProperty(u,r,{configurable:!1,enumerable:!0,get:n})},e.n=function(u){var r=u&&u.__esModule?function(){return u.default}:function(){return u};return e.d(r,"a",r),r},e.o=function(u,e){return Object.prototype.hasOwnProperty.call(u,e)},e.p="",e(e.s=0)}([function(u,e,r){var n=r(1),i=/^U[A-Z]+$/,t=/^[aeiou]/,o=/[\s'-]/,s=function(u,e){return(u||e)&&!(u&&e)},l=function(u,e){return!e&&i.test(u.split(" ")[0])},a=function(u){return""+u.charAt(0).toUpperCase()+u.slice(1)},c=function(u){return[null,"s","es","ed"].reduce(function(e,r){return e||n.check(u,r)},!1)},y=function(u){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=l(u,e.caseInsensitive),n=t.test(u.toLowerCase()),i=u.split(o)[0].toLowerCase(),y=c(i),p=!r&&s(n,y)?"an":"a";return e.capitalize?a(p)+" "+u:p+" "+u};y.irregularWords=n.list,u.exports=y},function(u,e){e.check=function(u,r){if(r){var n=new RegExp(r+"$");u=u.replace(n,"")}return e.list.indexOf(u)>-1},e.list=["eunuch","eucalyptus","eugenics","eulogy","euphemism","euphony","euphoria","eureka","european","euphemistic","euphonic","euphoric","euphemistically","euphonically","euphorically","heir","heiress","herb","homage","honesty","honor","honour","hour","honest","honorous","honestly","hourly","one","ouija","once","ubiquity","udometer","ufo","uke","ukelele","ululate","unicorn","unicycle","uniform","unify","union","unison","unit","unity","universe","university","upas","ural","uranium","urea","ureter","urethra","urine","urology","urus","usage","use","usual","usurp","usury","utensil","uterus","utility","utopia","utricle","uvarovite","uvea","uvula","ubiquitous","ugandan","ukrainian","unanimous","unicameral","unified","unique","unisex","universal","urinal","urological","useful","useless","usurious","usurped","utilitarian","utopic","ubiquitously","unanimously","unicamerally","uniquely","universally","urologically","usefully","uselessly","usuriously","yttria","yggdrasil","ylem","yperite","ytterbia","ytterbium","yttrium","ytterbous","ytterbic","yttric"]}]);

@@ -1,26 +0,25 @@

const checkList = (word, ending) => {
if (ending) {
// If the word ends in the ending, remove it.
let regex = new RegExp(`${ending}$`);
word = word.replace(regex, '');
}
const irregulars = require('./irregular-words');
const ACRONYM = /^U[A-Z]+$/;
const STARTS_WITH_VOWEL = /^[aeiou]/;
const EXTRAS = /[\s'-]/;
return indefinite.irregularWords.indexOf(word) > -1;
};
const xor = (a, b) => (a || b) && !(a && b);
const checkForAcronyms = (word, caseInsensitive) => caseInsensitive ? false : ACRONYM.test(word.split(' ')[0]);
const cap = str => `${str.charAt(0).toUpperCase()}${str.slice(1)}`;
const indefinite = (noun, opts = {}) => {
let isAcronymWithU = opts.caseInsensitive ? false : /^U[A-Z]+$/.test(noun.split(' ')[0]);
let startsWithVowel = /[aeiou]/.test(noun.charAt(0).toLowerCase());
// Try some variations on the word to determine whether it's irregular.
// Specifically, try trimming s, then es, then ed because those are common
// forms of plurals and past tense verbs (which can be used like adjectives).
const checkForIrregulars = part => [ null, 's', 'es', 'ed' ].reduce((memo, ending) => memo || irregulars.check(part, ending), false);
const indefinite = (word, opts = {}) => {
let isAcronymWithU = checkForAcronyms(word, opts.caseInsensitive);
let startsWithVowel = STARTS_WITH_VOWEL.test(word.toLowerCase());
// Only check the first word. Also, if it's hyphenated, only
// check the first part. Finally, if it's possessive, ignore
// the possessive part.
let part = noun.split(/[\s'-]/)[0].toLowerCase();
let part = word.split(EXTRAS)[0].toLowerCase();
// Try some variations on the word to determine whether it's irregular.
// Specifically, try trimming s, then es, then ed because those are common
// forms of plurals and past tense verbs (which can be used like adjectives).
let isIrregular = [ null, 's', 'es', 'ed' ].reduce((memo, ending) => {
return memo || checkList(part, ending);
}, false);
let isIrregular = checkForIrregulars(part);

@@ -34,77 +33,9 @@ /**

*/
let article = (!isAcronymWithU && (startsWithVowel || isIrregular) && !(startsWithVowel && isIrregular)) ? 'an' : 'a';
let article = !isAcronymWithU && xor(startsWithVowel, isIrregular) ? 'an' : 'a';
if (opts.capitalize) {
article = `${article.charAt(0).toUpperCase()}${article.slice(1)}`;
}
return `${article} ${noun}`;
return opts.capitalize ? `${cap(article)} ${word}` : `${article} ${word}`;
};
/**
* Here follows a List of words that take irregular articles because their
* first letter is either a consonant pronounced like a vowel (hour) or a
* vowel proncounced like a consonant (ukelele). Note that this is not only
* nouns because adjectives and adverbs that start with these letters could
* also follow an article when they identify a later noun, as in "a useless
* tool."
*
* This is not an attempt at a complete list, but rather a collection of
* words used in at least moderate frequency. A list of ALL irregular words
* would be too exhaustive to compile without some sort of tool.
* http://www.thefreedictionary.com/words-that-start-with-eu says there are
* over 1800 words starting with "eu" alone.
*
* At least for now, this list omits proper names, as they aren't USUALLY
* used in such a way as to require an _indefinite_ article. I can't think,
* for example, of a case where you'd want to say "a Eustace."
*/
indefinite.irregularWords = [
// Nouns: eu like y
'eunuch', 'eucalyptus', 'eugenics', 'eulogy', 'euphemism', 'euphony', 'euphoria', 'eureka',
indefinite.irregularWords = irregulars.list;
// Adjectives: eu like y
'european', 'euphemistic', 'euphonic', 'euphoric',
// Adverbs: eu like y
'euphemistically', 'euphonically', 'euphorically',
// Nouns: silent h
'herb', 'hour', 'heir', 'heiress', 'honesty', 'honor', 'honour',
// Adjectives: silent h
'honest', 'honorous',
// Adverbs: silent h
'hourly', 'honestly',
// Nouns: o like w
'one', 'ouija',
// Adjectives: o like w
'once',
// Adverbs: o like w
// Nouns: u like y
'ubiquity', 'udometer', 'ufo', 'uke', 'ukelele', 'ululate', 'unicorn', 'unicycle', 'uniform',
'unify', 'union', 'unison', 'unit', 'unity', 'universe', 'university', 'upas', 'ural', 'uranium',
'urea', 'ureter', 'urethra', 'urine', 'urology', 'urus', 'usage', 'use', 'usual', 'usurp',
'usury', 'utensil', 'uterus', 'utility', 'utopia', 'utricle', 'uvarovite', 'uvea', 'uvula',
// Adjectives: u like y
'ubiquitous', 'ugandan', 'ukrainian', 'unanimous', 'unicameral', 'unified', 'unique', 'unisex',
'universal', 'urinal', 'urological', 'useful', 'useless', 'usurious', 'usurped', 'utilitarian',
'utopic',
// Adverbs: u like y
'ubiquitously', 'unanimously', 'unicamerally', 'uniquely', 'universally', 'urologically', 'usefully', 'uselessly', 'usuriously',
// Nouns: y like i
'yttria', 'yggdrasil', 'ylem', 'yperite', 'ytterbia', 'ytterbium', 'yttrium',
// Adjectives: y like i
'ytterbous', 'ytterbic', 'yttric'
];
module.exports = indefinite;
{
"name": "indefinite",
"description": "Prefix a noun with an indefinite article - a or an - based on whether it begins with a vowel",
"version": "2.0.2",
"version": "2.0.3",
"main": "lib/indefinite.js",

@@ -6,0 +6,0 @@ "scripts": {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc