Skip to content

ContraHacker/exec-string

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

exec-string

Utility to execute a string as a function.

npm bundle size version

Installation

npm install exec-string

Usage

const execString = require('exec-string');

// Example use-cases

const result = execString('420 + 1337') // Returns 1757

const num1 = 42;
const num2 = 43;
const comparator = '<';

const comparison = execString(`${num1} ${comparator} ${num2}`); // Returns true

Can also be used with React or other libraries.

For instance, you can use it to pass a mathematical expression as props to a component. exec-string can return the value of the expression and display it in the UI.


Disclamer

Make sure you undestand why JavaScript's eval function is no longer used. Please refer to this link for more information.

About

Utility to execute a string as a function.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published