![PyPI Now Supports iOS and Android Wheels for Mobile Python Development](https://cdn.sanity.io/images/cgdhsj6q/production/96416c872705517a6a65ad9646ce3e7caef623a0-1024x1024.webp?w=400&fit=max&auto=format)
Security News
PyPI Now Supports iOS and Android Wheels for Mobile Python Development
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
better-eval
Advanced tools
🔧 An alternative to the 'eval' function in JavaScript that is faster, easier/better to use, and has less security issues.
eval()
in JavaScript that is customizable and safer!The eval function sucks, lacking any form of security and customizability. Other implementations are inadequate - ranging from being abandonded to overcomplicated. better-eval offers a solution, providing a modern alternative to the eval function with all the bells and whistles out of the box.
npm install better-eval
First, import the package:
const betterEval = require("better-eval");
Then call the function with something you want to be evaluated:
betterEval("1+1"); // returns 2
And its as simple as that! Any code will not be able to access variables you define unless explicitly passed.
Include any variables as part of an object which you pass in as the second parameter:
const name = "Sam";
betterEval("`Hey ${name}`", { name }); // returns 'Hey Sam'
You can also pass functions as a part of the second parameter, and evaluate them in your code:
const returnName = () => "Bob";
betterEval("`Hey ${returnName()}`", { returnName }); // returns 'Hey Bob'
For your safety, any of these global variables on the blacklist will not be added to your variables:
global
process
module
require
document
window
Window
eval
Function
Here is how they will be handled:
betterEval("`Sum is ${eval('1+1')}`", { eval }); // eval is null!
Remember: never use better-eval blindly with user code. These checks are precautions for your own usage, but any user with maltious intent could find a way to get through them. Thus, use this package with caution.
If you want to have more control over the VM that runs your code, you can pass in an vmOptions
parameter:
betterEval(
"1+1", {},
{
fileName: "counting",
lineOffset: 1,
}
);
A complete list of options can be found here.
better-eval is MIT-licensed open-source software created by Bharadwaj Duggaraju.
FAQs
🔧 An alternative to the 'eval' function in JavaScript that is faster, easier/better to use, and has less security issues.
The npm package better-eval receives a total of 0 weekly downloads. As such, better-eval popularity was classified as not popular.
We found that better-eval demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.