source: trip-planner-front/node_modules/require-from-string/index.js@ 8d391a1

Last change on this file since 8d391a1 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 866 bytes
RevLine 
[6a3a178]1'use strict';
2
3var Module = require('module');
4var path = require('path');
5
6module.exports = function requireFromString(code, filename, opts) {
7 if (typeof filename === 'object') {
8 opts = filename;
9 filename = undefined;
10 }
11
12 opts = opts || {};
13 filename = filename || '';
14
15 opts.appendPaths = opts.appendPaths || [];
16 opts.prependPaths = opts.prependPaths || [];
17
18 if (typeof code !== 'string') {
19 throw new Error('code must be a string, not ' + typeof code);
20 }
21
22 var paths = Module._nodeModulePaths(path.dirname(filename));
23
24 var parent = module.parent;
25 var m = new Module(filename, parent);
26 m.filename = filename;
27 m.paths = [].concat(opts.prependPaths).concat(paths).concat(opts.appendPaths);
28 m._compile(code, filename);
29
30 var exports = m.exports;
31 parent && parent.children && parent.children.splice(parent.children.indexOf(m), 1);
32
33 return exports;
34};
Note: See TracBrowser for help on using the repository browser.