TL;DRI built an LLM-powered replacement for JavaScript's
eval()function that can handle any code or code-like text you throw at it, marking the dawn of a new era in software development.
Dear friends, I present to you the next generation in software development: eval++!
Inspired by GitHub's recent release of their Copilot SDK, I decided to take a stab at one of the most controversial functions of all time and make it better, using the power of AI.
Eval++ is an LLM-powered replacement of JavaScript's eval() function that can probably handle any code or code-like text you throw at it, marking our ascension from the purgatory that is deterministic software development to a new enlightenment of "anything codes, anything goes."
So far, eval++ supports only JavaScript, but Python, PHP, and Ruby are all on the evolutionary roadmap.
Here's how it works:
import evil from '@zachflower/eval-plus-plus';
// Evaluate code
const result = await evil('2 + 2');
console.log(result); // "4"
// Analyze complex code
const analysis = await evil(`
function fibonacci(n) {
if (n <= 1) return n;
return fibonacci(n - 1) + fibonacci(n - 2);
}
fibonacci(10)
`);
The result of the above will be exactly what you expect: the number 55. Hell, it doesn't even have to be valid JavaScript code! You can throw in some Python or Ruby and it will still give you a result, because eval++ is powered by an LLM that can understand multiple programming languages.
const result = await evil(`
def fibonacci(n):
if n <= 1:
return n
return fibonacci(n - 1) + fibonacci(n - 2)
fibonacci(10)
`);
Same result, different language! But what makes eval++ truly revolutionary is that it can also handle code that isn't even code! For example:
const result = await evil('What is the meaning of life, the universe, and everything?');
The result of this will probably be 42, but it might be something entirely different, depending on the whims of the AI. The point is that with eval++, you can throw anything at it and it will give you something back, whether it's a valid JavaScript expression or a philosophical question.
So, if you are interested in trying out eval++, you can learn more about it and get the code on GitHub here: Eval++ Website and Eval++ GitHub Repository.
--
If you like this post or one of my projects, you can buy me a coffee, or send me a note. I'd love to hear from you!