MCPcopy Create free account
hub / github.com/breck7/scroll / getIndefiniteArticle

Method getIndefiniteArticle

external/.scrollLibs.js:14045–14083  ·  view source on GitHub ↗
(phrase)

Source from the content-addressed store, hash-verified

14043 }
14044 // https://github.com/rigoneri/indefinite-article.js/blob/master/indefinite-article.js
14045 static getIndefiniteArticle(phrase) {
14046 // Getting the first atom
14047 const match = /\w+/.exec(phrase)
14048 let atom
14049 if (match) atom = match[0]
14050 else return "an"
14051 var l_atom = atom.toLowerCase()
14052 // Specific start of atoms that should be preceded by 'an'
14053 var alt_cases = ["honest", "hour", "hono"]
14054 for (var i in alt_cases) {
14055 if (l_atom.indexOf(alt_cases[i]) == 0) return "an"
14056 }
14057 // Single letter atom which should be preceded by 'an'
14058 if (l_atom.length == 1) {
14059 if ("aedhilmnorsx".indexOf(l_atom) >= 0) return "an"
14060 else return "a"
14061 }
14062 // Capital atoms which should likely be preceded by 'an'
14063 if (atom.match(/(?!FJO|[HLMNS]Y.|RY[EO]|SQU|(F[LR]?|[HL]|MN?|N|RH?|S[CHKLMNPTVW]?|X(YL)?)[AEIOU])[FHLMNRSX][A-Z]/)) {
14064 return "an"
14065 }
14066 // Special cases where a atom that begins with a vowel should be preceded by 'a'
14067 const regexes = [/^e[uw]/, /^onc?e\b/, /^uni([^nmd]|mo)/, /^u[bcfhjkqrst][aeiou]/]
14068 for (var i in regexes) {
14069 if (l_atom.match(regexes[i])) return "a"
14070 }
14071 // Special capital atoms (UK, UN)
14072 if (atom.match(/^U[NK][AIEO]/)) {
14073 return "a"
14074 } else if (atom == atom.toUpperCase()) {
14075 if ("aedhilmnorsx".indexOf(l_atom[0]) >= 0) return "an"
14076 else return "a"
14077 }
14078 // Basic method of atoms that begin with a vowel being preceded by 'an'
14079 if ("aeiou".indexOf(l_atom[0]) >= 0) return "an"
14080 // Instances where y follwed by specific letters is preceded by 'an'
14081 if (l_atom.match(/^y(b[lor]|cl[ea]|fere|gg|p[ios]|rou|tt)/)) return "an"
14082 return "a"
14083 }
14084 static htmlEscaped(content = "") {
14085 return content.replace(/</g, "&lt;")
14086 }

Callers

nothing calls this directly

Calls 1

indexOfMethod · 0.80

Tested by

no test coverage detected