Revision 6cd9781c-fb6c-4215-96e1-87f75d317466 - Code Golf Stack Exchange
# [JavaScript (Node.js)], 131 bytes
[JavaScript (Node.js)]: https://nodejs.org
<!-- language-all: lang-javascript -->
s=>s.replace(/[a-z]/gi,c=>(s+g(i=B(c)[0]-1)?"":"ei")+(h=j=>g(i)^g(j=-~j%26)?h(j):B([j+1|i&96]))(i&31),B=Buffer,g=i=>s=1065233>>i&1)
[Try it online!](https://tio.run/##Xc9Ra4MwEAfw930KCVRyqLXRTWghlvk09j42EAcuJvFC2hQz91DGvrqLY0@9p@Pu9@c403/1Xkx4@czObpCL4ovntd9O8mJ7IWne9tm1yzWmgtfUJ5oib6iAdtdlDI6EHIhEAgkdueF12MK7poZnP2ZTVHAcqYFDQ1uTsG@M91UHQDEuGaQNb2al5JRqjuEgZ7vqoSjLusaYwSLc2Tsrt9Zpqih5kta66NVNdiAAUZ5Hz3iSeJqjt9nLtVV3NxERvtHOqtWHCpFhVjjOwepb@3JlRXn/L//s48c6WX4B "JavaScript (Node.js) – Try It Online")
### Commented
s => s.replace( // replace in the input string s ...
/[a-z]/gi, c => // ... each letter c (case insensitive)
( //
s + // if the previous letter was a vowel (or this
// is the 1st iteration and s is still a string)
g( // or the current letter
i = // whose ASCII code - 1 is loaded in i
B(c)[0] - 1 //
) ? // is a vowel:
"" // append nothing
: // else:
"ei" // append "ei"
) + ( //
h = j => // h is a recursive function looking for the
// replacement letter
g(i) ^ // if the type of the current letter
g( // does not match the type of
j = -~j % 26 // the next letter in the alphabet
// obtained by incrementing j modulo 26
) ? // then:
h(j) // keep advancing by doing a recursive call
: // else:
B([ // output the letter
j + 1 | // whose ASCII code is j + 1
i & 96 // with bits #5 and #6 taken from i
]) //
)(i & 31), // initial call to h with j = i mod 32
B = Buffer, // define B for Buffer
g = i => // g is a helper function taking an integer
s = 1065233 // representing an ASCII code minus 1,
>> i & 1 // returning 0 for consonant / 1 for vowel,
// and also saving the result in s
) // end of replace()