{"name":"redeyed","version":"0.5.0","description":"Takes JavaScript code, along with a config and returns the original code with tokens wrapped as configured.","author":{"name":"Thorsten Lorenz","email":"thlorenz@gmx.de","url":"thlorenz.com"},"main":"redeyed.js","scripts":{"test":"tap test/*.js","demo-log":"node examples/replace-log","demo":"cd examples/browser; open index.html"},"repository":{"type":"git","url":"git://github.com/thlorenz/redeyed.git"},"keywords":["ast","syntax","tree","source","wrap","metadata"],"license":"MIT","devDependencies":{"tap":"~0.4.8","readdirp":"~0.3.3","cardinal":"~0.4.4"},"dependencies":{"esprima-fb":"~12001.1.0-dev-harmony-fb"},"readme":"# redeyed [![build status](https://secure.travis-ci.org/thlorenz/redeyed.png?branch=master)](http://travis-ci.org/thlorenz/redeyed)\n\n*Add color to your JavaScript!*\n\n![frog](http://allaboutfrogs.org/gallery/photos/redeyes/red1.gif)\n\n[Red Eyed Tree Frog](http://allaboutfrogs.org/info/species/redeye.html) *(Agalychnis callidryas)*\n\n## What?\n\nTakes JavaScript code, along with a config and returns the original code with tokens wrapped and/or replaced as configured.\n\n## Where?\n\n- server side using nodejs\n- in the [browser](#browser-support)\n\n## What for?\n\nOne usecase is adding metadata to your code that can then be used to apply syntax highlighting.\n\n## How?\n\n- copy the [config.js](https://github.com/thlorenz/redeyed/blob/master/config.js) and edit it in order to specify how\n  certain tokens are to be surrounded/replaced\n- replace the `undefined` of each token you want to configure with one of the following\n\n### {String} config\n\n`'before:after'`\n\nwraps the token inside before/after \n\n### {Object} config\n\n`{ _before: 'before', _after: 'after' }`\n\nwraps token inside before/after\n\n#### Missing before and after resolution for {String} and {Object} config\n\nFor the `{String}` and `{Object}` configurations, 'before' or 'after' may be omitted:\n\n- `{String}`: \n  - `'before:'` (omitting 'after')\n  - `':after'` (omitting 'before')\n- `{Object}`: \n  - `{ _before: 'before' }` (omitting '_after')\n  - `{ _after: 'after' }` (omitting '_before')\n\nIn these cases the missing half is resolved as follows:\n\n- from the `parent._default` (i.e., `Keyword._default`) if found\n- otherwise from the `config._default` if found\n- otherwise `''` (empty string)\n\n### {Function} config\n\n`function (tokenString, info) { return {String}|{Object}; }`\n\n#### Inputs\n\n- tokenString: the content of the token that is currently being processed\n- info: an object with the following structure\n\n```js\n{\n    // {Int}\n    // the index of the token being processed inside tokens\n    tokenIndex\n\n    // {Array}\n    // all tokens that are being processed including comments \n    // (i.e. the result of merging esprima tokens and comments)\n  , tokens  \n\n    // {Object} \n    // the abstract syntax tree of the parsed code\n  , ast  \n\n    // {String}\n    // the code that was parsed (same string as the one passed to redeyed(code ..)\n  , code\n}\n```\n\nIn most cases the `tokenString` is all you need. The extra info object is passed in case you need to gather more\ninformation about the `token`'s surroundings in order to decide how to transform it. \nSee: [replace-log-example](https://github.com/thlorenz/redeyed/blob/master/examples/replace-log.js)\n\n#### Output\n\nYou can return a {String} or an {Object} from a {Function} config.\n\n- when returning a {String}, the token value will be replaced with it\n- when returning an {Object}, it should be of the following form:\n\n```js\n{\n    // {String}\n    // the string that should be substituted for the value of the current and all skipped tokens\n    replacement\n\n    // {Object} (Token)\n    // the token after which processing should continue\n    // all tokens in between the current one and this one inclusive will be ignored\n  , skipPastToken\n}\n```\n\n### Transforming JavaScript code\n\n***redeyed(code, config[, opts])***\n\nInvoke redeyed with your **config**uration, a **code** snippet and maybe **opts** as in the below example:\n\n```javascript\nvar redeyed = require('redeyed')\n  , config = require('./path/to/config')\n  , code = 'var a = 3;'\n  , result;\n\n// redeyed will throw an error (caused by the esprima parser) if the code has invalid javascript\ntry {\n  result = redeyed(code, config);\n  console.log(result.code);\n} catch(err) {\n  console.error(err);\n}\n```\n\n***opts***:\n```js\n{ // {Boolean}\n  // if true `result.code` is not assigned and therefore `undefined`\n  // if false (default) `result.code` property contains the result of `split.join`\n  nojoin: true|false\n  // {Object}\n  // overrides default parser `esprima-fb` and needs to be compatible with it\n  parser: require('esprima') \n}\n```\n\n***return value***:\n\n```js\n{   ast      \n  , tokens   \n  , comments \n  , splits   \n  , code     \n}\n```\n\n- ast `{Array}`: [abstract syntax tree](http://en.wikipedia.org/wiki/Abstract_syntax_tree) as returned by [esprima\n  parse](http://en.wikipedia.org/wiki/Abstract_syntax_tree)\n- tokens `{Array}`: [tokens](http://en.wikipedia.org/wiki/Token_(parser)) provided by esprima (excluding\n  comments)\n- comments `{Array}`: block and line comments as provided by esprima\n- splits `{Array}`: code pieces split up, some of which where transformed as configured\n- code `{String}`: transformed code, same as `splits.join('')` unless this step has been skipped (see opts)\n\n## Browser Support\n\n### AMD\n\nEnsure to include [esprima](https://github.com/ariya/esprima) as one of your dependencies\n\n```js\ndefine(['redeyed'], function (redeyed) {\n [ .. ]\n});\n```\n\n### Attached to global window object\n\nThe `redeyed {Function}` will be exposed globally as `window.redeyed` - big surprise!\n\n```html\n<script type=\"text/javascript\" src=\"https://raw.github.com/ariya/esprima/master/esprima.js\"></script>\n<script type=\"text/javascript\" src=\"path/to/redeyed.js\"></script>\n```\n\n## redeyed in the wild\n\n- [cardinal](https://github.com/thlorenz/cardinal): Syntax highlights JavaScript code with ANSI colors to be printed to\n  the terminal\n- [peacock](http://thlorenz.github.com/peacock/): JavaScript syntax highlighter that generates html that is compatible\n  with pygments styles.\n\n## Examples\n\n- `npm explore redeyed; npm demo` will let you try the [browser example](https://github.com/thlorenz/redeyed/tree/master/examples/browser)\n- `npm explore redeyed; npm demo-log` will let you try the [replace log example](https://github.com/thlorenz/redeyed/blob/master/examples/replace-log.js)\n\n","readmeFilename":"README.md","bugs":{"url":"https://github.com/thlorenz/redeyed/issues"},"homepage":"https://github.com/thlorenz/redeyed","_id":"redeyed@0.5.0","_shasum":"7ab000e60ee3875ac115d29edb32c1403c6c25d1","_from":"https://registry.npmjs.org/redeyed/-/redeyed-0.5.0.tgz","_resolved":"https://registry.npmjs.org/redeyed/-/redeyed-0.5.0.tgz"}