{"name":"redeyed","version":"2.1.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":"npm run run-test && npm run lint","run-test":"tape test/*.js","lint":"standart","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":{"cardinal":"~1.0.0","readdirp":"~2.1.0","standart":"^6.1.0","tape":"~4.9.0"},"dependencies":{"esprima":"~4.0.0"},"gitHead":"98aa2752cb89e384e673b25bb132c45dd19f3523","bugs":{"url":"https://github.com/thlorenz/redeyed/issues"},"homepage":"https://github.com/thlorenz/redeyed#readme","_id":"redeyed@2.1.0","_shasum":"de8bbb0c89e496e2e285ddc200ea822fdbe25c2f","_from":".","_npmVersion":"2.15.12","_nodeVersion":"10.0.0","_npmUser":{"name":"thlorenz","email":"thlorenz@gmx.de"},"dist":{"shasum":"de8bbb0c89e496e2e285ddc200ea822fdbe25c2f","tarball":"http://registry-npm.ywwl.com/redeyed/download/redeyed-2.1.0.tgz","fileCount":31,"unpackedSize":61841,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJbA0mmCRA9TVsSAnZWagAAZRUQAItX+V34QB6z76/JnwFz\nNaLrZF5SCC3izXSqc6VKYbtZcp+xJjbINrd+95SgfHMhCMpzBRPV5giaMiOz\nqNz/d8hJnk4zL1dNN05ccnn+15x0cyxFq2EbF0KfFJ1UE2ddw1tDXXisBcjX\nBSemUAsTDWDNdf+sI+xOMDy4aK9klZsK36qSF6uWFnYcTVdk0K5W54PXFr7M\nVJpdyvnukNjm6NGkVN1cPqHBPIGgrjTO9v5ZnI39h5nsVZzFFMrhjAmhvTlF\nmZIMPmHA16igkWDDmqBPWSpgkVOM7Eb9wwNm19oJbYaszSGZpMUofEp3r1Md\n3u/dw8b4AZDg45tvmWUz/djjLyfU/SLu2kF1sfvH3ItyLr+5KDjbb24AL28V\nOuhH7KEOr+6GvE8Nx1DyFpWGVuE9K0coYxbaoJhMMS667LIGpQTZrdW9XtEn\nzSkNYmnFUJBHkoC/8L1GCTPCqAmvaUF0oM26gHvNtVjGO1DfPBf9BPozel+u\nJvXrfcgsddMWDVwLJ7ouVXyu2BOE1v9iVwDkTB+O9eirDw4NLJwimhXm5I8q\nEdjLrr6e5jtWFpk7M/7umxrOpKGc24tsRPtjQByqujh3xPQ0DABIUsr7y274\nkHZSSO9kCzW/sPHG7sTiAP5yOvTaAd9rKLxrYoUl7qZWiVv1Kj2Wp88JM/0U\nLDub\r\n=HRPf\r\n-----END PGP SIGNATURE-----\r\n","integrity":"sha512-WbDZRAspVi4/pFOovO4X8D0ev9uJCwmlNsrO7S5PGKaGTjqlUBKHiqjpv3z2n60DKvYElmSEtwnqf5BWYTLyxQ==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCdcqYT4xJ9PFdEDnfpDouFXyCEg1aBqKPAOJNnMhfyeQIhAMCdwAiE62wIVTe0XBdiOg/luASG691WkpPMQV6LbA7s"}],"size":14687,"noattachment":false,"key":"/redeyed/-/redeyed-2.1.0.tgz"},"maintainers":[{"name":"thlorenz","email":"thlorenz@gmx.de"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/redeyed_2.1.0_1526942117668_0.329805503578946"},"_hasShrinkwrap":false,"readme":"# redeyed [![build status](https://secure.travis-ci.org/thlorenz/redeyed.svg?branch=master)](http://travis-ci.org/thlorenz/redeyed)\n\n<a href=\"https://www.patreon.com/bePatron?u=8663953\"><img alt=\"become a patron\" src=\"https://c5.patreon.com/external/logo/become_a_patron_button.png\" height=\"35px\"></a>\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.ast` property contains the abstract syntax tree of the code\n  // if false (default) `result.ast` is not assigned and therefore `undefined`\n  buildAst: true|false\n  // {Boolean}\n  // if `true`, jsx syntax is supported, default `false`\n  // due to how esprima works, the AST is built when this option is `true`, even if\n  // `buildAST` is `false`\n, jsx: true|false\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://unpkg.com/esprima\"></script>\n<script type=\"text/javascript\" src=\"https://unpkg.com/redeyed\"></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","publish_time":1526942117780,"_cnpm_publish_time":1526942117780,"dist-tags":{"latest":"2.1.1"}}