Initial commit
[yaffs-website] / node_modules / require-from-string / index.js
1 'use strict';
2
3 var Module = require('module');
4 var path = require('path');
5
6 module.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 m = new Module(filename, module.parent);
25         m.filename = filename;
26         m.paths = [].concat(opts.prependPaths).concat(paths).concat(opts.appendPaths);
27         m._compile(code, filename);
28
29         return m.exports;
30 };