Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

require-from-string

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

require-from-string - npm Package Compare versions

Comparing version 1.0.2 to 1.1.0

license

17

index.js

@@ -6,3 +6,13 @@ 'use strict';

module.exports = function requireFromString(code, filename) {
module.exports = function requireFromString(code, filename, opts) {
if (typeof filename === 'object') {
opts = filename;
filename = undefined;
}
opts = opts || {};
opts.appendPaths = opts.appendPaths || [];
opts.prependPaths = opts.prependPaths || [];
if (typeof code !== 'string') {

@@ -12,7 +22,10 @@ throw new Error('code must be a string, not ' + typeof code);

var paths = Module._nodeModulePaths(path.dirname(filename));
var m = new Module(filename, module.parent);
m.filename = filename;
m.paths = Module._nodeModulePaths(path.dirname(filename));
m.paths = [].concat(opts.prependPaths).concat(paths).concat(opts.appendPaths);
m._compile(code, filename);
return m.exports;
};

2

package.json
{
"name": "require-from-string",
"version": "1.0.2",
"version": "1.1.0",
"description": "Require module from string",

@@ -5,0 +5,0 @@ "license": "MIT",

@@ -24,3 +24,3 @@ # require-from-string [![Build Status](https://travis-ci.org/floatdrop/require-from-string.svg?branch=master)](https://travis-ci.org/floatdrop/require-from-string)

### requireFromString(code, [filename])
### requireFromString(code, [filename], [options])

@@ -40,4 +40,18 @@ #### code

#### options
Type: `object`
##### appendPaths
Type: `Array`
List of `paths`, that will be appended to module `paths`. Useful, when you want
to be able require modules from these paths.
##### prependPaths
Type: `Array`
Same as `appendPath`, but paths will be prepended.
## License
MIT © [Vsevolod Strukchinsky](http://github.com/floatdrop)
SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc