New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.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.1.1 to 2.2.0

lib/rules.js

6

.eslint.json

@@ -39,8 +39,2 @@ {

"no-loop-func": "error",
"no-magic-numbers": ["error", {
"ignore": [-1,0,1],
"ignoreArrayIndexes": true,
"enforceConst": true,
"detectObjects": true
}],
"no-multi-spaces": "error",

@@ -47,0 +41,0 @@ "no-sequences": "error",

210

dist/indefinite.js

@@ -73,3 +73,3 @@ (function webpackUniversalModuleDefinition(root, factory) {

/******/ // Load entry module and return exports
/******/ return __webpack_require__(__webpack_require__.s = 1);
/******/ return __webpack_require__(__webpack_require__.s = 2);
/******/ })

@@ -81,2 +81,25 @@ /************************************************************************/

var STARTS_WITH_VOWEL = /^[aeiouAEIOU]/;
/**
* Array#indexOf is faster IF the word starts with "a" (for example),
* but negligibly faster when you have to .toLowerCase() the word, and
* slower if the word happens to start with (e.g.) "u."
*/
exports.startsWithVowel = function (word) {
return STARTS_WITH_VOWEL.test(word);
};
exports.capitalize = function (article, word, opts) {
if (opts.capitalize) {
article = "" + article.charAt(0).toUpperCase() + article.slice(1);
}
return article + " " + word;
};
/***/ }),
/* 1 */
/***/ (function(module, exports) {
exports.check = function (word, ending) {

@@ -153,49 +176,25 @@ if (ending) {

/***/ }),
/* 1 */
/* 2 */
/***/ (function(module, exports, __webpack_require__) {
var irregulars = __webpack_require__(0);
var irregulars = __webpack_require__(1);
var rules = __webpack_require__(3);
var _require = __webpack_require__(2),
startsWithVowel = _require.startsWithVowel,
xor = _require.xor,
bothOrNeither = _require.bothOrNeither,
isAcronym = _require.isAcronym,
isIrregularAcronym = _require.isIrregularAcronym,
checkForIrregulars = _require.checkForIrregulars,
capitalize = _require.capitalize,
getFirst = _require.getFirst;
var indefinite = function indefinite(word) {
var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
var hasInitialVowel = startsWithVowel(word);
var result = void 0;
// If it's an acronym, make different checks.
if (isAcronym(word, opts.caseInsensitive)) {
var isIrregular = isIrregularAcronym(word);
/*
* If it starts with U: "a"
* If it starts with any other vowel: "an"
* If it starts with F, H, L, M, N, R, S, or X: "an"
* If it starts with any other consonant: "a"
*/
var article = bothOrNeither(hasInitialVowel, isIrregular) ? 'a' : 'an';
return capitalize(article, word, opts);
} else {
// Only check the first word. Also, if it's hyphenated, only
// check the first part. Finally, if it's possessive, ignore
// the possessive part.
var first = getFirst(word);
var _isIrregular = checkForIrregulars(first);
/**
* I'd really prefer to use for of here, but babel converts that
* to something using Symbol.iterator, which PhantomJS chokes on.
*/
rules.some(function (rule) {
if (rule.check(word, opts)) {
result = rule.run(word, opts);
return true;
}
});
/**
* If it starts with a vowel and isn't irregular: "an"
* If it starts with a vowel and IS irregular: "a"
* If it starts with a consonant and isn't irregular: "a"
* If it starts with a consonant and IS irregular: "an"
*/
var _article = xor(hasInitialVowel, _isIrregular) ? 'an' : 'a';
return capitalize(_article, word, opts);
}
return result;
};

@@ -208,24 +207,61 @@

/***/ }),
/* 2 */
/* 3 */
/***/ (function(module, exports, __webpack_require__) {
var irregulars = __webpack_require__(0);
module.exports = [__webpack_require__(4), __webpack_require__(5), __webpack_require__(6)];
/***/ }),
/* 4 */
/***/ (function(module, exports, __webpack_require__) {
var _require = __webpack_require__(0),
capitalize = _require.capitalize;
var NUMBERS = /^([0-9,]+)/;
var EIGHT_ELEVEN_EIGHTEEN = /^(11|8|18)/;
var ELEVEN_EIGHTEEN = /^(11|18)/;
exports.check = function (word) {
return NUMBERS.test(word);
};
exports.run = function (word, opts) {
var number = word.toString().match(NUMBERS)[1].replace(/,/g, '');
var article = 'a';
if (EIGHT_ELEVEN_EIGHTEEN.test(number)) {
var startsWith11Or18 = ELEVEN_EIGHTEEN.test(number);
// If the number starts with 11 or 18, the pronunciation is ambiguous
// so check the opts.numbers to see how to render it. Otherwise, if it
// starts with 11 or 18 and has 2, 5, 8, 11, etc. digits, use 'an'.
// Finally, if it starts with an 8, use 'an.' For everything else,
// use 'a.'
if (startsWith11Or18 && number.length === 4) {
article = opts.numbers === 'colloquial' ? 'an' : 'a';
} else if (startsWith11Or18 && (number.length - 2) % 3 === 0) {
article = 'an';
} else {
article = number.startsWith('8') ? 'an' : 'a';
}
}
return capitalize(article, word, opts);
};
/***/ }),
/* 5 */
/***/ (function(module, exports, __webpack_require__) {
var _require = __webpack_require__(0),
startsWithVowel = _require.startsWithVowel,
capitalize = _require.capitalize;
var ACRONYM = /^[A-Z]+$/;
var IRREGULAR_ACRONYM = /^[UFHLMNRSX]/;
var STARTS_WITH_VOWEL = /^[aeiouAEIOU]/;
var EXTRAS = /[\s'-]/;
/**
* Array#indexOf is faster IF the word starts with "a" (for example),
* but negligibly faster when you have to .toLowerCase() the word, and
* slower if the word happens to start with (e.g.) "u."
*/
exports.startsWithVowel = function (word) {
return STARTS_WITH_VOWEL.test(word);
var isIrregularAcronym = function isIrregularAcronym(word) {
return IRREGULAR_ACRONYM.test(word.charAt(0));
};
exports.xor = function (a, b) {
return (a || b) && !(a && b);
};
/**

@@ -239,3 +275,3 @@ * Both = a && b

*/
exports.bothOrNeither = function (a, b) {
var bothOrNeither = function bothOrNeither(a, b) {
return a === b;

@@ -248,10 +284,39 @@ };

*/
exports.isAcronym = function (word, caseInsensitive) {
exports.check = function (word, _ref) {
var caseInsensitive = _ref.caseInsensitive;
return caseInsensitive ? false : ACRONYM.test(word.split(' ')[0]);
};
exports.isIrregularAcronym = function (word) {
return IRREGULAR_ACRONYM.test(word.charAt(0));
exports.run = function (word, opts) {
var isIrregular = isIrregularAcronym(word);
var initialVowel = startsWithVowel(word);
/*
* If it starts with U: "a"
* If it starts with any other vowel: "an"
* If it starts with F, H, L, M, N, R, S, or X: "an"
* If it starts with any other consonant: "a"
*/
var article = bothOrNeither(initialVowel, isIrregular) ? 'a' : 'an';
return capitalize(article, word, opts);
};
/***/ }),
/* 6 */
/***/ (function(module, exports, __webpack_require__) {
var _require = __webpack_require__(0),
capitalize = _require.capitalize,
startsWithVowel = _require.startsWithVowel;
var irregulars = __webpack_require__(1);
var EXTRAS = /[\s'-]/;
var getFirst = function getFirst(word) {
return word.split(EXTRAS)[0].toLowerCase();
};
var xor = function xor(a, b) {
return (a || b) && !(a && b);
};
/**

@@ -262,3 +327,3 @@ * Try some variations on the word to determine whether it's irregular.

*/
exports.checkForIrregulars = function (part) {
var checkForIrregulars = function checkForIrregulars(part) {
return [null, 's', 'es', 'ed'].reduce(function (memo, ending) {

@@ -269,12 +334,21 @@ return memo || irregulars.check(part, ending);

exports.capitalize = function (article, word, opts) {
if (opts.capitalize) {
article = '' + article.charAt(0).toUpperCase() + article.slice(1);
}
return article + ' ' + word;
exports.check = function () {
return true;
};
exports.getFirst = function (word) {
return word.split(EXTRAS)[0].toLowerCase();
exports.run = function (word, opts) {
// Only check the first word. Also, if it's hyphenated, only
// check the first part. Finally, if it's possessive, ignore
// the possessive part.
var first = getFirst(word);
var isIrregular = checkForIrregulars(first);
/**
* If it starts with a vowel and isn't irregular: "an"
* If it starts with a vowel and IS irregular: "a"
* If it starts with a consonant and isn't irregular: "a"
* If it starts with a consonant and IS irregular: "an"
*/
var article = xor(startsWithVowel(word), isIrregular) ? 'an' : 'a';
return capitalize(article, word, opts);
};

@@ -281,0 +355,0 @@

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

!function(e,u){"object"==typeof exports&&"object"==typeof module?module.exports=u():"function"==typeof define&&define.amd?define([],u):"object"==typeof exports?exports.indefinite=u():e.indefinite=u()}("undefined"!=typeof self?self:this,function(){return function(e){function u(t){if(r[t])return r[t].exports;var n=r[t]={i:t,l:!1,exports:{}};return e[t].call(n.exports,n,n.exports,u),n.l=!0,n.exports}var r={};return u.m=e,u.c=r,u.d=function(e,r,t){u.o(e,r)||Object.defineProperty(e,r,{configurable:!1,enumerable:!0,get:t})},u.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e};return u.d(r,"a",r),r},u.o=function(e,u){return Object.prototype.hasOwnProperty.call(e,u)},u.p="",u(u.s=1)}([function(e,u){u.check=function(e,r){if(r){var t=new RegExp(r+"$");e=e.replace(t,"")}return u.list.indexOf(e)>-1},u.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"]},function(e,u,r){var t=r(0),n=r(2),i=n.startsWithVowel,o=n.xor,s=n.bothOrNeither,a=n.isAcronym,l=n.isIrregularAcronym,c=n.checkForIrregulars,f=n.capitalize,y=n.getFirst,p=function(e){var u=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=i(e);if(a(e,u.caseInsensitive)){var t=l(e),n=s(r,t)?"a":"an";return f(n,e,u)}var p=y(e),h=c(p),d=o(r,h)?"an":"a";return f(d,e,u)};p.irregularWords=t.list,e.exports=p},function(e,u,r){var t=r(0),n=/^[A-Z]+$/,i=/^[UFHLMNRSX]/,o=/^[aeiouAEIOU]/,s=/[\s'-]/;u.startsWithVowel=function(e){return o.test(e)},u.xor=function(e,u){return(e||u)&&!(e&&u)},u.bothOrNeither=function(e,u){return e===u},u.isAcronym=function(e,u){return!u&&n.test(e.split(" ")[0])},u.isIrregularAcronym=function(e){return i.test(e.charAt(0))},u.checkForIrregulars=function(e){return[null,"s","es","ed"].reduce(function(u,r){return u||t.check(e,r)},!1)},u.capitalize=function(e,u,r){return r.capitalize&&(e=""+e.charAt(0).toUpperCase()+e.slice(1)),e+" "+u},u.getFirst=function(e){return e.split(s)[0].toLowerCase()}}])});
!function(e,u){"object"==typeof exports&&"object"==typeof module?module.exports=u():"function"==typeof define&&define.amd?define([],u):"object"==typeof exports?exports.indefinite=u():e.indefinite=u()}("undefined"!=typeof self?self:this,function(){return function(e){function u(n){if(t[n])return t[n].exports;var r=t[n]={i:n,l:!1,exports:{}};return e[n].call(r.exports,r,r.exports,u),r.l=!0,r.exports}var t={};return u.m=e,u.c=t,u.d=function(e,t,n){u.o(e,t)||Object.defineProperty(e,t,{configurable:!1,enumerable:!0,get:n})},u.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return u.d(t,"a",t),t},u.o=function(e,u){return Object.prototype.hasOwnProperty.call(e,u)},u.p="",u(u.s=2)}([function(e,u){var t=/^[aeiouAEIOU]/;u.startsWithVowel=function(e){return t.test(e)},u.capitalize=function(e,u,t){return t.capitalize&&(e=""+e.charAt(0).toUpperCase()+e.slice(1)),e+" "+u}},function(e,u){u.check=function(e,t){if(t){var n=new RegExp(t+"$");e=e.replace(n,"")}return u.list.indexOf(e)>-1},u.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"]},function(e,u,t){var n=t(1),r=t(3),i=function(e){var u=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},t=void 0;return r.some(function(n){if(n.check(e,u))return t=n.run(e,u),!0}),t};i.irregularWords=n.list,e.exports=i},function(e,u,t){e.exports=[t(4),t(5),t(6)]},function(e,u,t){var n=t(0),r=n.capitalize,i=/^([0-9,]+)/,o=/^(11|8|18)/,a=/^(11|18)/;u.check=function(e){return i.test(e)},u.run=function(e,u){var t=e.toString().match(i)[1].replace(/,/g,""),n="a";if(o.test(t)){var s=a.test(t);n=s&&4===t.length?"colloquial"===u.numbers?"an":"a":s&&(t.length-2)%3==0?"an":t.startsWith("8")?"an":"a"}return r(n,e,u)}},function(e,u,t){var n=t(0),r=n.startsWithVowel,i=n.capitalize,o=/^[A-Z]+$/,a=/^[UFHLMNRSX]/,s=function(e){return a.test(e.charAt(0))},c=function(e,u){return e===u};u.check=function(e,u){return!u.caseInsensitive&&o.test(e.split(" ")[0])},u.run=function(e,u){var t=s(e),n=r(e),o=c(n,t)?"a":"an";return i(o,e,u)}},function(e,u,t){var n=t(0),r=n.capitalize,i=n.startsWithVowel,o=t(1),a=/[\s'-]/,s=function(e){return e.split(a)[0].toLowerCase()},c=function(e,u){return(e||u)&&!(e&&u)},l=function(e){return[null,"s","es","ed"].reduce(function(u,t){return u||o.check(e,t)},!1)};u.check=function(){return!0},u.run=function(e,u){var t=s(e),n=l(t),o=c(i(e),n)?"an":"a";return r(o,e,u)}}])});

@@ -10,3 +10,3 @@ const gulp = require('gulp');

gulp.task('spawn:nyc', task('npm', ['run', 'cover']));
gulp.task('spawn:webpack', task('webpack', []));
gulp.task('spawn:nyc', task('npm', [ 'run', 'cover' ]));
gulp.task('spawn:webpack', task('npm', [ 'run', 'webpack' ]));

@@ -10,3 +10,3 @@ // Karma configuration

reporters: ['dots'],
browsers: ['Chrome', 'PhantomJS', 'Firefox', 'Safari'],
browsers: [ 'Chrome', 'PhantomJS', 'Firefox', 'Safari' ],
preprocessors: {

@@ -18,2 +18,3 @@ 'test/**/*.js': ['webpack']

files: [
'node_modules/babel-polyfill/dist/polyfill.js',
'test/**/*.js'

@@ -33,3 +34,3 @@ ],

presets: [
['env', { modules: false }]
[ 'env', { modules: false }]
]

@@ -46,2 +47,2 @@ }

});
}
};

@@ -1,6 +0,2 @@

const irregulars = require('./irregular-words');
const ACRONYM = /^[A-Z]+$/;
const IRREGULAR_ACRONYM = /^[UFHLMNRSX]/;
const STARTS_WITH_VOWEL = /^[aeiouAEIOU]/;
const EXTRAS = /[\s'-]/;

@@ -14,29 +10,2 @@ /**

exports.xor = (a, b) => (a || b) && !(a && b);
/**
* Both = a && b
* Neither = !a && !b
* In the case of Booleans, this means
* either both true or both false, so
* we can just compare the equality of
* a and b.
*/
exports.bothOrNeither = (a, b) => a === b;
/**
* If the entirety of the first word is capital letters
* and case insensitivity is off, it's an acronym.
*/
exports.isAcronym = (word, caseInsensitive) => caseInsensitive ? false : ACRONYM.test(word.split(' ')[0]);
exports.isIrregularAcronym = word => IRREGULAR_ACRONYM.test(word.charAt(0));
/**
* 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).
*/
exports.checkForIrregulars = part => [ null, 's', 'es', 'ed' ].reduce((memo, ending) => memo || irregulars.check(part, ending), false);
exports.capitalize = (article, word, opts) => {

@@ -49,3 +18,1 @@ if (opts.capitalize) {

};
exports.getFirst = word => word.split(EXTRAS)[0].toLowerCase();
const irregulars = require('./irregular-words');
const {
startsWithVowel,
xor,
bothOrNeither,
isAcronym,
isIrregularAcronym,
checkForIrregulars,
capitalize,
getFirst
} = require('./helpers');
const rules = require('./rules');
const indefinite = (word, opts = {}) => {
let hasInitialVowel = startsWithVowel(word);
let result;
// If it's an acronym, make different checks.
if (isAcronym(word, opts.caseInsensitive)) {
let isIrregular = isIrregularAcronym(word);
/*
* If it starts with U: "a"
* If it starts with any other vowel: "an"
* If it starts with F, H, L, M, N, R, S, or X: "an"
* If it starts with any other consonant: "a"
*/
let article = bothOrNeither(hasInitialVowel, isIrregular) ? 'a' : 'an';
return capitalize(article, word, opts);
} else {
// 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 first = getFirst(word);
let isIrregular = checkForIrregulars(first);
/**
* I'd really prefer to use for of here, but babel converts that
* to something using Symbol.iterator, which PhantomJS chokes on.
*/
rules.some((rule) => {
if (rule.check(word, opts)) {
result = rule.run(word, opts);
return true;
}
});
/**
* If it starts with a vowel and isn't irregular: "an"
* If it starts with a vowel and IS irregular: "a"
* If it starts with a consonant and isn't irregular: "a"
* If it starts with a consonant and IS irregular: "an"
*/
let article = xor(hasInitialVowel, isIrregular) ? 'an' : 'a';
return capitalize(article, word, opts);
}
return result;
};

@@ -44,0 +20,0 @@

{
"name": "indefinite",
"description": "Prefix a noun with an indefinite article - a or an - based on whether it begins with a vowel",
"version": "2.1.1",
"version": "2.2.0",
"main": "lib/indefinite.js",

@@ -10,2 +10,3 @@ "browser": "dist/indefinite.js",

"travis": "gulp ci",
"webpack": "webpack",
"cover": "nyc --reporter=html --reporter=lcov --reporter=text-summary mocha --timeout=3000 --reporter=dot test/**/*.js"

@@ -36,11 +37,13 @@ },

"devDependencies": {
"babel-core": "^6.26.0",
"babel-core": "^6.26.3",
"babel-loader": "^7.1.2",
"babel-preset-env": "^1.6.1",
"babel-polyfill": "^6.26.0",
"babel-preset-env": "^1.7.0",
"eslint-codeframe-formatter": "^1.0.2",
"file-manifest": "^2.0.4",
"gulp": "github:gulpjs/gulp#4.0",
"file-manifest": "^2.0.5",
"gulp": "^4.0.0",
"gulp-cli": "^2.0.1",
"gulp-codeclimate-reporter": "github:tandrewnichols/gulp-codeclimate-reporter",
"gulp-eslint": "^4.0.0",
"gulp-rename": "^1.2.2",
"gulp-rename": "^1.4.0",
"karma": "^2.0.0",

@@ -55,5 +58,5 @@ "karma-chrome-launcher": "^2.2.0",

"nyc": "^11.4.1",
"opn": "^5.1.0",
"opn": "^5.4.0",
"rimraf": "^2.6.2",
"should": "^13.1.3",
"should": "^13.2.3",
"webpack": "^3.10.0"

@@ -60,0 +63,0 @@ },

@@ -31,4 +31,8 @@ [![Build Status](https://travis-ci.org/tandrewnichols/indefinite.png)](https://travis-ci.org/tandrewnichols/indefinite) [![downloads](http://img.shields.io/npm/dm/indefinite.svg)](https://npmjs.org/package/indefinite) [![npm](http://img.shields.io/npm/v/indefinite.svg)](https://npmjs.org/package/indefinite) [![Code Climate](https://codeclimate.com/github/tandrewnichols/indefinite/badges/gpa.svg)](https://codeclimate.com/github/tandrewnichols/indefinite) [![Test Coverage](https://codeclimate.com/github/tandrewnichols/indefinite/badges/coverage.svg)](https://codeclimate.com/github/tandrewnichols/indefinite) [![dependencies](https://david-dm.org/tandrewnichols/indefinite.png)](https://david-dm.org/tandrewnichols/indefinite) ![Size](https://img.shields.io/badge/size-2kb-brightgreen.svg)

Indefinite also accepts an options object as the second parameter. Currently, two options are supported: `capitalize`, for capitalizing the article, and `caseInsensitive` for ignoring the casing of the word passed in (i.e. bypassing the acronym checking). This is useful if, for some reason, you're yelling on the internet and want to make sure "UGLY GARDEN GNOME" doesn't become "a UGLY GARDEN GNOME."
Indefinite also accepts an options object as the second parameter. The following options are supported:
- `capitalize` - Capitalize the article.
- `caseInsensitive` - Ignore the casing of the word passed in (i.e. bypassing the acronym checking). This is useful if, for some reason, you're yelling on the internet and want to make sure "UGLY GARDEN GNOME" doesn't become "a UGLY GARDEN GNOME."
- `numbers` - When numbers are passed in, they are prefixed with "a" except for 8, 11, 18, and higher numbers starting with 8. _However_, numbers like 1100 are ambiguous. Should it be "a one thousand one hundred" or "an eleven hundred"? There's not really any programmatic way to know this for sure, but if _you_ know for sure, you can use the `numbers` option to tell `indefinite` how to handle these cases. The default is "formal" in which numbers are read literally (the way you'd say them if they were written out), but if you pass `numbers: 'colloquial'`, the "eleven hundred"/"eighteen hundred" readings will be used.
```js

@@ -38,2 +42,6 @@ console.log(a('apple', { capitalize: true })); // 'An apple'

console.log(a('UGLY SWEATER', { caseInsensitve: true })); // 'an UGLY SWEATER'
console.log(a('2')); // 'a 2'
console.log(a('8')); // 'an 8'
console.log(a('1892')); // 'a 1892' -> read "a one thousand eight hundred ninety-two"
console.log(a('1892', { numbers: 'colloquial' })); // 'an 1892' -> read "an eighteen ninety-two"
```

@@ -40,0 +48,0 @@

@@ -9,4 +9,4 @@ require('should');

indefinite('apple').should.equal('an apple');
})
})
});
});

@@ -16,4 +16,4 @@ context('a word that starts with a consonant', () => {

indefinite('banana').should.equal('a banana');
})
})
});
});

@@ -23,4 +23,4 @@ context('a word that starts with a capital vowel', () => {

indefinite('Apple').should.equal('an Apple');
})
})
});
});

@@ -30,4 +30,4 @@ context('a word that starts with a capital consonant', () => {

indefinite('Banana').should.equal('a Banana');
})
})
});
});

@@ -37,4 +37,4 @@ context('a word that starts with a capital that would be a irregular if it were an acronym', () => {

indefinite('Umbrella').should.equal('an Umbrella');
})
})
});
});

@@ -44,4 +44,4 @@ context('a word that starts with a vowel when capitalize is passed in', () => {

indefinite('apple', { capitalize: true }).should.equal('An apple');
})
})
});
});

@@ -51,4 +51,4 @@ context('a word that starts with a consonant when capitalize is passed in', () => {

indefinite('banana', { capitalize: true }).should.equal('A banana');
})
})
});
});

@@ -58,4 +58,4 @@ context('an acronym that starts with a regular vowel', () => {

indefinite('IOU').should.equal('an IOU');
})
})
});
});

@@ -65,4 +65,4 @@ context('an acronym that starts with an irregular vowel', () => {

indefinite('UFO').should.equal('a UFO');
})
})
});
});

@@ -72,4 +72,4 @@ context('an acronym that starts with a consonant', () => {

indefinite('CEO').should.equal('a CEO');
})
})
});
});

@@ -79,4 +79,4 @@ context('an acronym that starts with an irregular consonant', () => {

indefinite('FFA prodigy').should.equal('an FFA prodigy');
})
})
});
});

@@ -86,4 +86,4 @@ context('an acronym that starts with U but with caseInsensitive passed in', () => {

indefinite('UNCLE', { caseInsensitive: true }).should.equal('an UNCLE');
})
})
});
});

@@ -93,4 +93,4 @@ context('an irregular word beginning with a silent consonant', () => {

indefinite('honor').should.equal('an honor');
})
})
});
});

@@ -100,4 +100,4 @@ context('an irregular word beginning with a vowel that makes a consonant sound', () => {

indefinite('ukelele').should.equal('a ukelele');
})
})
});
});

@@ -107,4 +107,4 @@ context('an irregular word when multiple words are passed in', () => {

indefinite('ouija board').should.equal('a ouija board');
})
})
});
});

@@ -114,4 +114,4 @@ context('an irregular word that is hyphenated is passed in', () => {

indefinite('honor-bound').should.equal('an honor-bound');
})
})
});
});

@@ -121,4 +121,4 @@ context('a plural form of an irregular word is passed in', () => {

indefinite('hours').should.equal('an hours');
})
})
});
});

@@ -128,4 +128,4 @@ context('an irregular plural form of an irregular word is passed in', () => {

indefinite('heiresses').should.equal('an heiresses');
})
})
});
});

@@ -135,4 +135,4 @@ context('a past tense verb form of an irregular word is passed in', () => {

indefinite('honored').should.equal('an honored');
})
})
});
});

@@ -142,4 +142,4 @@ context('a possessive form of an irregular word is passed in', () => {

indefinite('heir\'s').should.equal('an heir\'s');
})
})
});
});

@@ -149,4 +149,89 @@ context('an irregular word with some capitalization is passed', () => {

indefinite('Hour').should.equal('an Hour');
})
})
})
});
});
context('Numbers', () => {
context('starting with 11', () => {
it('should be prefixed with an', () => {
indefinite('11').should.equal('an 11');
indefinite('110').should.equal('a 110');
indefinite('11000').should.equal('an 11000');
indefinite('110000').should.equal('a 110000');
indefinite('1100000').should.equal('a 1100000');
indefinite('11000000').should.equal('an 11000000');
indefinite('110000000').should.equal('a 110000000');
indefinite('1100000000').should.equal('a 1100000000');
indefinite('11000000000').should.equal('an 11000000000');
indefinite('110000000000').should.equal('a 110000000000');
indefinite('1100000000000').should.equal('a 1100000000000');
indefinite('11000000000000').should.equal('an 11000000000000');
indefinite('110000000000000').should.equal('a 110000000000000');
indefinite('1100000000000000').should.equal('a 1100000000000000');
indefinite('11000000000000000').should.equal('an 11000000000000000');
});
});
context('starting with 18', () => {
it('should be prefixed with an', () => {
indefinite('18').should.equal('an 18');
indefinite('180').should.equal('a 180');
indefinite('18000').should.equal('an 18000');
indefinite('180000').should.equal('a 180000');
indefinite('1800000').should.equal('a 1800000');
indefinite('18000000').should.equal('an 18000000');
indefinite('180000000').should.equal('a 180000000');
indefinite('1800000000').should.equal('a 1800000000');
indefinite('18000000000').should.equal('an 18000000000');
indefinite('180000000000').should.equal('a 180000000000');
indefinite('1800000000000').should.equal('a 1800000000000');
indefinite('18000000000000').should.equal('an 18000000000000');
indefinite('180000000000000').should.equal('a 180000000000000');
indefinite('1800000000000000').should.equal('a 1800000000000000');
indefinite('18000000000000000').should.equal('an 18000000000000000');
});
});
context('starting with 8', () => {
it('should be prefixed with an', () => {
indefinite('8').should.equal('an 8');
indefinite('80').should.equal('an 80');
indefinite('800').should.equal('an 800');
indefinite('8000').should.equal('an 8000');
indefinite('80000').should.equal('an 80000');
indefinite('800000').should.equal('an 800000');
indefinite('8000000').should.equal('an 8000000');
indefinite('80000000').should.equal('an 80000000');
indefinite('800000000').should.equal('an 800000000');
});
});
context('1100 and 1800 range', () => {
context('with formal pronunciation', () => {
it('should be prefixed with a', () => {
indefinite('1100').should.equal('a 1100');
indefinite('1800').should.equal('a 1800');
});
});
context('with colloquial pronunciation', () => {
it('should be prefixed with an', () => {
indefinite('1100', { numbers: 'colloquial' }).should.equal('an 1100');
indefinite('1800', { numbers: 'colloquial' }).should.equal('an 1800');
});
});
});
context('other numbers', () => {
it('should be prefixed with a', () => {
indefinite('17').should.equal('a 17');
});
});
context('with actual numbers', () => {
it('should be prefixed the same as with strings', () => {
indefinite(7).should.equal('a 7');
indefinite(8).should.equal('an 8');
});
});
});
});
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