Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/varharrie/run-my-code
Execute javascript code from a string based on new function.
https://github.com/varharrie/run-my-code
code execute function javascript run
Last synced: 16 days ago
JSON representation
Execute javascript code from a string based on new function.
- Host: GitHub
- URL: https://github.com/varharrie/run-my-code
- Owner: varHarrie
- License: mit
- Created: 2021-05-13T09:37:49.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2021-05-13T09:55:25.000Z (over 3 years ago)
- Last Synced: 2024-11-19T12:27:13.603Z (3 months ago)
- Topics: code, execute, function, javascript, run
- Language: TypeScript
- Homepage:
- Size: 21.5 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# run-my-code
Execute javascript code from a string based on new function, inspired by [zx](https://github.com/google/zx).
## Install
```bash
$ npm install --save run-my-code
```## Usage
**Tagged Template:**
```javascript
const $ = require('run-my-code');const obj = { foo: 'foo' };
const arr = [1, 2];console.log($`return 1 + 1`); // 2
console.log($`return ${obj}`); // { foo: 'foo' }
console.log($`return ${arr}.map((n) => n * 2)`); // [2, 4]
```**Normal Function:**
```javascript
const $ = require('run-my-code');console.log($('return 1 + 1')); // 2
```**With Context:**
```javascript
console.log($({ a: 1, b: 2 })(`return a + b`)); // 3
console.log($({ a: 1, b: 2 })`return a + b`); // 3
```## License
[MIT](./LICENSE)