RegExp expressions to parse javascript code context - for node and the browser.
Install with npm
$ npm install js-code-context
For a more comprehensive examples, see the tests.
var fs = require('fs');
var parseCodeContext = require('js-code-context');
var context = fs.readFileSync('./fixture.js','utf-8');
parseCodeContext(context, function(err, obj) {
console.log(obj)
//=> returns array of parsed objects
});
parseCodeContext(context, 6, function(err, obj) {
console.log(obj)
//=> returns array with 1 object for parsed 7th line of context
});
var response = parseCodeContext.sync(context, 6);
//=> returns array with 1 object for parsed 7th line of context
//=> or array with error object
CLI uses
.sync
method. But it's not so sync, if we must be honest - in fact it's asynchronous. It just returns resulted array in variable, not in callback.
$ npm install --global js-code-context
$ jsCodeContext --help
Options
--help | -h show help
--line | -l specify which line to parse
--file | -f file that want to parse
Example
$ jsCodeContext -f ./test/fixture.js -l 6
//=> array with one object
As usual -
npm test
or if you have mocha globally -mocha
.
$ npm test
Charlike Mike Reagent
Copyright (c) 2014 Charlike Mike Reagent, contributors.
Released under the MIT
license.