first commit

This commit is contained in:
2025-10-26 23:10:15 +08:00
commit 8f0345b7be
14961 changed files with 2356381 additions and 0 deletions

35
node_modules/indefinite/lib/rules/acronyms.js generated vendored Normal file
View File

@@ -0,0 +1,35 @@
const { startsWithVowel } = require('../helpers');
const ACRONYM = /^[A-Z]+$/;
const IRREGULAR_ACRONYM = /^[UFHLMNRSX]/;
const isIrregularAcronym = word => IRREGULAR_ACRONYM.test(word.charAt(0));
/**
* 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.
*/
const 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.check = (word, { caseInsensitive }) => caseInsensitive ? false : ACRONYM.test(word.split(' ')[0]);
exports.run = (word) => {
let isIrregular = isIrregularAcronym(word);
let 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"
*/
let article = bothOrNeither(initialVowel, isIrregular) ? 'a' : 'an';
return article;
};

29
node_modules/indefinite/lib/rules/numbers.js generated vendored Normal file
View File

@@ -0,0 +1,29 @@
const NUMBERS = /^([0-9,]+)/;
const EIGHT_ELEVEN_EIGHTEEN = /^(11|8|18)/;
const ELEVEN_EIGHTEEN = /^(11|18)/;
exports.check = (word) => NUMBERS.test(word);
exports.run = (word, opts) => {
let number = word.toString().match(NUMBERS)[1].replace(/,/g, '');
let article = 'a';
if (EIGHT_ELEVEN_EIGHTEEN.test(number)) {
const startsWith11Or18 = ELEVEN_EIGHTEEN.test(number);
// If the number starts with 11 or 18 and is of length 4,
// the pronunciation is ambiguous so check 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 article;
};

33
node_modules/indefinite/lib/rules/other.js generated vendored Normal file
View File

@@ -0,0 +1,33 @@
const { startsWithVowel } = require('../helpers');
const irregulars = require('../irregular-words');
const EXTRAS = /[\s'-]/;
const getFirst = word => word.split(EXTRAS)[0].toLowerCase();
const xor = (a, b) => (a || b) && !(a && b);
/**
* 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);
exports.check = () => true;
exports.run = (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.
let first = getFirst(word);
let 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"
*/
let article = xor(startsWithVowel(word), isIrregular) ? 'an' : 'a';
return article;
};