Socket
Socket
Sign inDemoInstall

eval-abfork

Package Overview
Dependencies
1
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    eval-abfork

Evaluate node require() module content directly, aminbros fork, https://github.com/pierrec/node-eval


Version published
Weekly downloads
2
Maintainers
1
Created
Weekly downloads
 

Readme

Source

Eval - require() for module content!

Overview

This module is a simple way to evaluate a module content in the same way as require() but without loading it from a file. Effectively, it mimicks the javascript evil eval function but leverages Node's VM module instead.

Benefits

Why would you be using the eval module over the nativerequire? Most of the time require is fine but in some situations, I have found myself wishing for the following:

  • Ability to supply a context to a module
  • Ability to load the module file(s) from non node standard places

Or simply to leverage JavaScript's eval but with sandboxing.

Download

It is published on node package manager (npm). To install, do:

npm install eval

Usage

var _eval = require('eval')
var res = _eval(content /*, filename, scope, includeGlobals */)

The following options are available:

  • content (String): the content to be evaluated
  • filename (String): optional dummy name to be given (used in stacktraces)
  • scope (Object): scope properties are provided as variables to the content
  • includeGlobals (Boolean): allow/disallow global variables (and require) to be supplied to the content (default=false)

Examples

var _eval = require('eval')
var res = _eval('var x = 123; exports.x = x')
// => res === { x: 123 }

res = _eval('module.exports = function () { return 123 }')
// => res() === 123

res = _eval('module.exports = require("events")', true)
// => res === require('events')

res = _eval('exports.x = process', true)
// => res.x === process

License

Here

Keywords

FAQs

Last updated on 14 May 2017

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc