js-code-context

1.1.0 • Public • Published

js-code-context

RegExp expressions to parse javascript code context - for node and the browser.

NPM version Using ferver Build Status

Install Nodei.co stats

Install with npm

$ npm install js-code-context

Usage & Example

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

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

Tests

As usual - npm test or if you have mocha globally - mocha.

$ npm test

Authors & Contributors author tips

Charlike Mike Reagent

License MIT license

Copyright (c) 2014 Charlike Mike Reagent, contributors.
Released under the MIT license.

Package Sidebar

Install

npm i js-code-context

Weekly Downloads

0

Version

1.1.0

License

none

Last publish

Collaborators

  • vanchoy
  • tunnckocore