Namespace modulify
Namepsace for atropa's modulify.
Defined in: <src/modulify.js>.
Constructor Attributes | Constructor Name and Description |
---|---|
Namepsace for atropa's modulify.
|
Method Attributes | Method Name and Description |
---|---|
<static> |
modulify.file(srcFile)
Converts a javascript file into a commonjs module.
|
<static> |
modulify.string(src)
Converts a string of source code into a commonjs module.
|
Method Detail
<static>
{String}
modulify.file(srcFile)
Converts a javascript file into a commonjs module. **Caution** This function
runs the given script through eval so if the script is supposed to do things
like delete all your files, then it will.
var str = modulify.file('myfile.js'); console.log(str);
- Parameters:
- {String} srcFile
- The path to the file to evaluate.
- Returns:
- {String} Returns a script as a string. The script will be a commonjs module exporting the new global properties, vars, and functions declared in the top scope. The module exports statements will be wrapped in a try catch block so the script will continue to work in the browser and only export if `module.exports` is assignable.
<static>
{String}
modulify.string(src)
Converts a string of source code into a commonjs module. **Caution** This
function runs the given script through eval so if the script is supposed to
do things like delete all your files, then it will.
var src = 'a = "global prop"; ' + 'var d = "I am a declared variable"; function e () {};'; var str = modulify.string(src); console.log(str);
- Parameters:
- {String} src
- The source code to evaluate.
- Returns:
- {String} Returns a script as a string. The script will be a commonjs module exporting the new global properties, vars, and functions declared in the top scope. The module exports statements will be wrapped in a try catch block so the script will continue to work in the browser and only export if `module.exports` is assignable.
- Requires:
- esprima