better-eval
Advanced tools
Comparing version 1.2.7 to 1.2.8
{ | ||
"name": "better-eval", | ||
"version": "1.2.7", | ||
"version": "1.2.8", | ||
"description": "🔧 An alternative to the 'eval' function in JavaScript that is faster, easier/better to use, and has less security issues.", | ||
@@ -5,0 +5,0 @@ "main": "src/index.js", |
@@ -1,9 +0,8 @@ | ||
# 🔧 better-eval | ||
# <img src="https://raw.githubusercontent.com/bharadwajduggaraju/better-eval/master/.github/assets/logo.png" alt="better-eval logo" /> | ||
### An alternative to `eval()` in JavaScript that is customizable and safer! | ||
The eval function sucks, and there lacks alternatives that provide the same simplicity of the original eval function. **better-eval** solves this problem by adressing the security and speed issues, while delivering a sensible API. | ||
*The eval function is a **crutch**, lacking any form of security and customizability. Other implementations are **inadequate** - ranging from being abandonded to overcomplicated, and there isn't a all-in-one package.* **better-eval** offers a solution, providing a **modern** alternative to the eval function with all the **bells and whistles** out of the box.. | ||
<a href="https://www.producthunt.com/posts/better-eval?utm_source=badge-featured&utm_medium=badge&utm_souce=badge-better-eval" target="_blank"><img src="https://api.producthunt.com/widgets/embed-image/v1/featured.svg?post_id=327967&theme=light" alt="better-eval - 🔧 An alternative to 'eval' that is just better! | Product Hunt" style="width: 250px; height: 54px;" width="250" height="54" /></a> | ||
<br /><br /> | ||
<a href="https://www.npmjs.com/package/better-eval"> | ||
@@ -14,9 +13,11 @@ <img src="https://img.shields.io/npm/v/better-eval?style=flat-square&color=FF524C&labelColor=000" alt="NPM Version"> | ||
</a> | ||
<br /><br /> | ||
<a href="https://www.producthunt.com/posts/better-eval?utm_source=badge-featured&utm_medium=badge&utm_souce=badge-better-eval" target="_blank"><img src="https://api.producthunt.com/widgets/embed-image/v1/featured.svg?post_id=327967&theme=light" alt="better-eval - 🔧 An alternative to 'eval' that is just better! | Product Hunt" style="width: 250px; height: 54px;" width="250" height="54" /></a> | ||
## Why Better-Eval? | ||
- 🕊 Small and Lightweight. | ||
- 🕊 Small and lightweight. | ||
- ⚡ A simple and easy to use API. | ||
- 🛠️ Easily customizable for your needs. | ||
- ✅ Tested and Mantained. | ||
- ✅ Tested and mantained. | ||
@@ -83,3 +84,3 @@ ## Installation | ||
> 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. | ||
> 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. | ||
@@ -86,0 +87,0 @@ ## Configuring the VM |
@@ -21,3 +21,2 @@ // blacklisted variables (no fn) to be passed in through vars param in betterEval | ||
module.exports = { | ||
@@ -24,0 +23,0 @@ blackListedVariablesNode, |
@@ -11,7 +11,7 @@ "use strict"; | ||
/** | ||
* @description takes code to execute and exexcutes it safely! | ||
* @param {string} code - code to be executed. | ||
* @description takes code to evaluate and evalutes it in a vm with your configuration. | ||
* @param {string} code - code to be evaluated. | ||
* @param {object} insertedVariables - variables from your code to pass into the execution context. passed in like: {variableName, variableValue} | ||
* @param {object} vmOptions - the options for how to run the VM to execute the code (more info in vm pkg docs). | ||
* @returns {any} if your evaluated code returns a value, then betterEval will return that. | ||
* @returns {any} if your evaluated code produces a value, then betterEval will return that to you. | ||
*/ | ||
@@ -18,0 +18,0 @@ function betterEval(code, insertedVariables = null, vmOptions = {}) { |
const { blackListedVariablesNode } = require("./blackList"); | ||
/** | ||
* @param {object} vars | ||
* @param {'local' | 'vm'} execContext | ||
* @description parses user variables into context and prevents mal variables and objects (lv 1). | ||
* @param {object} vars - user variables | ||
* @param {object} sandbox - context with user variables | ||
* @description adds user variables into exec context and prevents mal variables and objects (basic). | ||
* @returns {object} sandbox context with user variables. | ||
@@ -8,0 +8,0 @@ */ |
9650
104