modulify

0.1.0-1 • Public • Published

modulify

Generates nodejs modules from source code.

Where do I get it?

You can download it from github at https://github.com/matthewkastor/modulify or, if you have node installed you can get it from npm

npm install modulify

Usage

In Browser

Using this module in your browser is as simple as including both src/modulify.js and node_modules/esprima/esprima.js in the page, parsing the source code with esprima and calling modulify.generateModuleString. There is an example below. It is much easier to use this code within nodejs and that is the recommended method. See try it.html in the root directory of this package for a working example of browser usage.

<script type="text/javascript" src="./node_modules/esprima/esprima.js"></script>
<script type="text/javascript" src="./src/modulify.js"></script>
<script type="text/javascript">
    var src = // get the source code as a string.
    var ast = esprima.parse(src, {tolerant: true});
    var result = modulify.utils.generateModuleString(ast, src, '\r\n');
    // result will contain the modulified version of the source.
</script>

In Nodejs

Simply require it and use it.

var modulify = require('modulify');
var result = modulify.file( /** file path **/);
// result will contain the modulified version of the source.

There is also a method modulify.string that takes a single string argument and returns a modulified version. See the documentation for other utility methods.

Docs

Documentation is in the docs/jsdoc folder. Visual Studio intellisense files are in docs/vsdocs

Tests

Run the tests in node with npm test. Run the tests in your browser by opening modulify tester.html.

Readme

Keywords

none

Package Sidebar

Install

npm i modulify

Weekly Downloads

3

Version

0.1.0-1

License

gpl-3.0

Last publish

Collaborators

  • kastor