export const make = (text) =>
text
.split(/\b/g)
.map((token) => {
if (!/[a-z]/i.test(token)) return token
// Is this a standard case, or is there a leading vowel?
let [front, back] = /^([aeiou]|[^aeiouy]+$)/i.test(token)
? [token, "yay"]
: [token.match(/[aeiouy].*$/i)[0], token.match(/[^aeiouy]+/i)[0] + "ay"]
// Flip capitalisation
if (back[0] !== back[0].toLowerCase()) {
back = back[0].toLowerCase() + back.slice(1)
front = front[0].toUpperCase() + front.slice(1)
}
// Don't double "y" in the suffix
if (back[0] === "y" && front[front.length - 1] === "y") {
back = back.slice(1)
}
return front + back
})
.join("")