{"name":"gonzales-pe","description":"Gonzales Preprocessor Edition (fast CSS parser)","version":"2.0.0-alpha","homepage":"http://github.com/tonyganch/gonzales-pe","bugs":"http://github.com/tonyganch/gonzales-pe/issues","license":"MIT","author":{"name":"Tony Ganch","email":"tonyganch@gmail.com"},"main":"./lib/gonzales","repository":{"type":"git","url":"http://github.com/tonyganch/gonzales-pe.git"},"scripts":{"test":"(make && mkdir -p log && node ./test/test.js) | tee ./log/test.log"},"devDependencies":{"benchmark":"~1.0.0","microtime":"~0.3.3"},"engines":{"node":">=0.6.0"},"_id":"gonzales-pe@2.0.0-alpha","dist":{"shasum":"69bd8eecf8871e65e088aa25663123d1679bb81e","tarball":"http://registry-npm.ywwl.com/gonzales-pe/download/gonzales-pe-2.0.0-alpha.tgz","integrity":"sha512-vPq3Eq4zH30ert1yinUIRrINmZxbFWjxrRQ/ox91WkMcoUXA34PO0nELjtEJiZnqI4rauQSCE/VbFOD7qBuNow==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIBA2lzQkx0B6iiQh2wnUWmRWN9bv9scCRqrYCjxde43YAiEA/SXLL/0BCUnyN2WevcwHNrJ5hGoKDe9NFeBXDwyOhvQ="}],"size":83717,"noattachment":false,"key":"/gonzales-pe/-/gonzales-pe-2.0.0-alpha.tgz"},"_npmVersion":"1.1.61","_npmUser":{"name":"tonyganch","email":"tonyganch@gmail.com"},"maintainers":[{"name":"tonyganch","email":"tonyganch@gmail.com"}],"directories":{},"readme":"# Gonzales PE @dev\n\n[![NPM version][npm-img]][npm]\n[![Build Status][travis-img]][travis]\n[![AppVeyor Build Status][appveyor-img]][appveyor]\n\n[npm-img]:      https://img.shields.io/npm/v/gonzales-pe.svg\n[npm]:          https://www.npmjs.com/package/gonzales-pe\n[travis-img]:   https://travis-ci.org/tonyganch/gonzales-pe.svg\n[travis]:       https://travis-ci.org/tonyganch/gonzales-pe\n[appveyor-img]: https://ci.appveyor.com/api/projects/status/m29jphtrqt398v2o/branch/dev?svg=true\n[appveyor]:     https://ci.appveyor.com/project/tonyganch/gonzales-pe/branch/dev\n\nGonzales PE is a CSS parser which plays nicely with preprocessors.    \nCurrently those are supported: SCSS, Sass, LESS.    \nTry out Gonzales PE online: [Gonzales PE Playground](https://tonyganch.io/gonzales-pe/).\n\n## Install\n\n(1) To install command-line tool globally:\n\n```bash\nnpm install -g git://github.com/tonyganch/gonzales-pe.git#dev\n```\n\n(2) To install parser as a project dependency:\n\n```bash\nnpm install --save git://github.com/tonyganch/gonzales-pe.git#dev\n```\n\n(3) If for some reason you want to build files yourself:\n\n```bash\n# Clone the repo.\ngit clone git@github.com:tonyganch/gonzales-pe.git\n# Go to dev branch.\ngit checkout dev\n# Install project dependencies.\nnpm install\n# Install git hooks and build files.\nnpm run init\n```\n\n## API\n\nBasically there are a few things you can do:\n\n1. parse css string and get a parse tree in return;\n2. modify tree nodes;\n3. remove tree nodes;\n4. add new nodes to the tree;\n5. convert modified tree back to a string.\n\nThe different type of tree nodes can be found in [docs/node-types.md](https://github.com/tonyganch/gonzales-pe/blob/dev/docs/node-types.md).\n\nIn examples below I assume that `gonzales` is a parser module and `parseTree`\nis some parsed css:\n\n```js\nlet gonzales = require('gonzales-pe');\nlet parseTree = gonzales.parse(css);\n```\n\n### gonzales.createNode(options)\n\n##### Description\n\nCreates a new node. Useful when you need to add something to a tree.\n\n##### Parameters\n\n<table>\n  <tr>\n    <td><i>{Object}</i></td>\n    <td>options</td>\n    <td>Options to pass to a `Node` constructor.</td>\n  </tr>\n  <tr>\n</table>\n\n##### Returns\n\n<table>\n  <tr>\n    <td><i>{Object}</i></td>\n    <td>A new node.</td>\n  </tr>\n</table>\n\n##### Examples\n\n```js\nlet css = 'a {color: tomato}';\nlet parseTree = gonzales.parse(css);\nlet node = gonzales.createNode({ type: 'animal', content: 'panda' });\nparseTree.content.push(node);\n```\n\n\n### gonzales.parse(css[, options])\n\n##### Description\n\nParses a css string.\n\n##### Parameters\n\n<table>\n  <tr>\n    <td><i>{string}</i></td>\n    <td>css</td>\n    <td>A string to parse.</td>\n  </tr>\n  <tr>\n    <td><i>{Object=}</i></td>\n    <td>options</td>\n    <td>Optional. Additional options:\n      <ul>\n        <li>\n          <code>{string} syntax</code> — any of the following: <code>css</code>,\n          <code>less</code>, <code>sass</code>, <code>scss</code>.\n          Default one is <code>css</code>.\n        </li>\n        <li>\n          <code>{string} context</code> — root node's type. For a list of available\n          values see <a href=\"docs/node-types.md\">\"Node types\"</a>. Default\n          one is <code>stylesheet</code>.\n        </li>\n        <li>\n          <code>{number} tabSize</code> — size of a tab character in spaces.\n          Default one is 1.\n        </li>\n      </ul>\n    </td>\n  </tr>\n</table>\n\n##### Returns\n\n<table>\n  <tr>\n    <td><i>{Object}</i></td>\n    <td>Parse tree.</td>\n  </tr>\n</table>\n\n##### Examples\n\n```js\nlet css = 'a {color: tomato}';\nlet parseTree = gonzales.parse(css);\n```\n\n```js\nlet less = 'a {$color: tomato}';\nlet parseTree = gonzales.parse(less, {syntax: 'less'});\n```\n\n```js\nlet less = '$color: tomato';\nlet parseTree = gonzales.parse(less, {syntax: 'less', rule: 'declaration'});\n```\n\n### parseTree.contains(type)\n\n##### Description\n\nChecks whether there is a child node of given type.\n\n##### Parameters\n\n<table>\n  <tr>\n    <td><i>{string}</i></td>\n    <td>type</td>\n    <td>\n      Node type we're looking for. For a list of available values see\n      <a href=\"docs/node-types.md\">\"Node types\"</a>.\n    </td>\n  </tr>\n</table>\n\n##### Returns\n\n<table>\n  <tr>\n    <td><i>{boolean}</i></td>\n    <td>\n      <code>true</code> if a tree contains a child node of a given type,\n      <code>false</code> otherwise.\n    </td>\n  </tr>\n</table>\n\n##### Examples\n\n```js\nif (parseTree.contains('space')) {\n  doSomething();\n}\n```\n\n### parseTree.content\n\n##### Returns\n\n<table>\n  <tr>\n    <td><i>{string|Array}</i></td>\n    <td>Node's content (child nodes or a string).</td>\n  </tr>\n</table>\n\n### parseTree.eachFor([type, ]callback)\n\n##### Description\n\nCalls a function for every child node in tree. If `type` parameter is passed,\ncalls a function only for child nodes of a given type. The main difference from\n`parseTree.forEach()` is that this method loops through node list from the end\nto beginning.\n\n##### Parameters\n\n<table>\n  <tr>\n    <td><i>{string=}</i></td>\n    <td>type</td>\n    <td>\n      Optional. A node type by which to filter child nodes before applying\n      a callback function. For a list of available values see\n      <a href=\"docs/node-types.md\">\"Node types\"</a>.\n    </td>\n  </tr>\n  <tr>\n    <td><i>{Function}</i></td>\n    <td>callback</td>\n    <td>\n      Function to call for every child node. Accepts following parameters:\n      <ul>\n        <li><code>{Object}</code> — a child node;</li>\n        <li><code>{number}</code> — index of the child node in node list;</li>\n        <li>\n          <code>{Object}</code> — parent node (equals to <code>parseTree</code>).\n        </li>\n      </ul>\n    </td>\n  </tr>\n</table>\n\n##### Examples\n\n```js\nparseTree.eachFor(function(childNode) {\n  doSomething(childNode);\n});\n```\n\n```js\n// Remove all child spaces.\nparseTree.eachFor('space', function(spaceNode, i) {\n  parseTree.removeChild(i);\n});\n```\n\n### parseTree.end\n\n##### Returns\n\n<table>\n  <tr>\n    <td><i>{Object}</i></td>\n    <td>\n      End position of the node. Contains following info:\n      <ul>\n        <li>\n          <code>{number} line</code> — last symbol's line number\n          (1-based index);\n        </li>\n        <li>\n          <code>{number} column</code> — last symbol's column number\n          (1-based index).\n        </li>\n      </ul>\n    </td>\n  </tr>\n</table>\n\n### parseTree.first([type])\n\n##### Description\n\nGets the first child node. If `type` parameter is passed, gets the first child\nnode of a given type. If no node has been found, returns `null`.\n\n##### Parameters\n\n<table>\n  <tr>\n    <td><i>{string=}</i></td>\n    <td>type</td>\n    <td>\n      Optional. Node type to look for. For a list of available values see\n      <a href=\"docs/node-types.md\">\"Node types\"</a>.\n    </td>\n  </tr>\n</table>\n\n##### Returns\n\n<table>\n  <tr>\n    <td><i>{?Object}</i></td>\n    <td>A node.</td>\n  </tr>\n</table>\n\n##### Examples\n\n```js\nlet node = parseTree.first();\nnode.content = 'panda';\n```\n\n```js\nlet node = parseTree.first('multilineComment');\nnode.content = 'panda';\n```\n\n### parseTree.forEach([type, ]callback)\n\n##### Description\n\nCalls a function for every child node in tree. If `type` parameter is passed,\ncalls a function only for child nodes of a given type. The main difference from\n`parseTree.eachFor()` is that this method loops through node list from the\nbeginnig to end.\n\n##### Parameters\n\n<table>\n  <tr>\n    <td><i>{string=}</i></td>\n    <td>type</td>\n    <td>\n      Optional. A node type by which to filter child nodes before applying\n      a callback function. For a list of available values see\n      <a href=\"docs/node-types.md\">\"Node types\"</a>.\n    </td>\n  </tr>\n  <tr>\n    <td><i>{Function}</i></td>\n    <td>callback</td>\n    <td>\n      Function to call for every child node. Accepts following parameters:\n      <ul>\n        <li><code>{Object}</code> — a child node;</li>\n        <li><code>{number}</code> — index of the child node in node list;</li>\n        <li>\n          <code>{Object}</code> — parent node (equals to <code>parseTree</code>).\n        </li>\n      </ul>\n    </td>\n  </tr>\n</table>\n\n##### Examples\n\n```js\nparseTree.forEach(function(childNode) {\n  doSomething();\n});\n```\n\n```js\nparseTree.forEach('space', function(spaceNode) {\n  doSomething();\n});\n```\n\n### parseTree.get(index)\n\n##### Description\n\nGets *nth* child of the `parseTree`. If no node has been found, returns `null`.\n\n##### Parameters\n\n<table>\n  <tr>\n    <td><i>{number}</i></td>\n    <td>index</td>\n    <td>Index number of node which we're looking for.</td>\n  </tr>\n</table>\n\n##### Returns\n\n<table>\n  <tr>\n    <td><i>{?Object}</i></td>\n    <td>A node.</td>\n  </tr>\n</table>\n\n##### Examples\n\n```js\nvar node = parseTree.get(2);\ndoSomething(node);\n```\n\n### parseTree.insert(index, node)\n\n##### Description\n\nInserts a node to a given position in `parseTree`.\n\n##### Parameters\n\n<table>\n  <tr>\n    <td><i>{number}</i></td>\n    <td>index</td>\n    <td>Index of position where to insert the node.</td>\n  </tr>\n  <tr>\n    <td><i>{Object}</i></td>\n    <td>node</td>\n    <td>A node to insert.</td>\n  </tr>\n</table>\n\n##### Examples\n\n```js\nlet node = gonzales.createNode({type: 'animal', content: 'panda'});\nparseTree.insert(2, node);\n```\n\n### parseTree.is(type)\n\n##### Description\n\nChecks whether the node is of given type.\n\n##### Parameters\n\n<table>\n  <tr>\n    <td><i>{string}</i></td>\n    <td>type</td>\n    <td>\n      A node type against which to check type of <code>parseTree</code>.\n      For a list of available values see\n      <a href=\"docs/node-types.md\">\"Node types\"</a>.\n    </td>\n  </tr>\n</table>\n\n##### Returns\n\n<table>\n  <tr>\n    <td><i>{boolean}</i></td>\n    <td>\n      <code>true</code> if types are equal, <code>false</code> otherwise.\n    </td>\n  </tr>\n</table>\n\n##### Examples\n\n```js\nif (node.is('space')) {\n  node.content = '';\n}\n```\n\n### parseTree.last(type)\n\nGets the last child node. If `type` parameter is passed, gets the last child\nnode of a given type. If no node has been found, returns `null`.\n\n##### Parameters\n\n<table>\n  <tr>\n    <td><i>{string=}</i></td>\n    <td>type</td>\n    <td>\n      Optional. Node type to look for. For a list of available values see\n      <a href=\"docs/node-types.md\">\"Node types\"</a>.\n    </td>\n  </tr>\n</table>\n\n##### Returns\n\n<table>\n  <tr>\n    <td><i>{?Object}</i></td>\n    <td>A node.</td>\n  </tr>\n</table>\n\n##### Examples\n\n```js\nlet node = parseTree.last();\nnode.content = 'panda';\n```\n\n```js\nlet node = parseTree.last('multilineComment');\nnode.content = 'panda';\n```\n\n### parseTree.length\n\n##### Returns\n\n<table>\n  <tr>\n    <td><i>{number}</i></td>\n    <td>Number of child nodes.</td>\n  </tr>\n</table>\n\n### parseTree.removeChild(index)\n\n##### Description\n\nRemoves a child node at a given position.\n\n##### Parameters\n\n<table>\n  <tr>\n    <td><i>{number}</i></td>\n    <td>index</td>\n    <td>Index of a child node we need to remove.</td>\n  </tr>\n</table>\n\n##### Returns\n\n<table>\n  <tr>\n    <td><i>{Object}</i></td>\n    <td>Removed node.</td>\n  </tr>\n</table>\n##### Examples\n\n```js\n// Swap nodes.\nvar node = parseTree.removeChild(1);\nparseTree.insert(0, node);\n```\n\n### parseTree.start\n\n##### Returns\n\n<table>\n  <tr>\n    <td><i>{Object}</i></td>\n    <td>\n      Start position of the node. Contains following info:\n      <ul>\n        <li>\n          <code>{number} line</code> — first symbol's line number\n          (1-based index);\n        </li>\n        <li>\n          <code>{number} column</code> — first symbol's column number\n          (1-based index).\n        </li>\n      </ul>\n    </td>\n  </tr>\n</table>\n\n\n### parseTree.syntax\n\n##### Returns\n\n<table>\n  <tr>\n    <td><i>{string}</i></td>\n    <td>Syntax of original parsed string.</td>\n  </tr>\n</table>\n\n### parseTree.toJson()\n\n##### Description\n\nConverts parse tree to JSON. Useful for printing.\n\n##### Returns\n\n<table>\n  <tr>\n    <td><i>{Object}</i></td>\n    <td>Parse tree in JSON</td>\n  </tr>\n</table>\n\n### parseTree.toString()\n\n##### Description\n\nConverts parse tree back to string according to original syntax.\n\n##### Returns\n\n<table>\n  <tr>\n    <td><i>{string}</i></td>\n    <td>A compiled string.</td>\n  </tr>\n</table>\n\n##### Examples\n\n```js\nlet css = parseTree.toString();\n```\n\n### parseTree.traverse(callback)\n\n##### Description\n\nCalls the function for every node in a tree including `parseTree` itself.\n\n##### Parameters\n\n<table>\n  <tr>\n    <td><i>{Function}</i></td>\n    <td>callback</td>\n    <td>\n      Function to apply to every node. Accepts following parameters:\n      <ul>\n        <li><code>{Object}</code> — a node to which we apply callback;</li>\n        <li><code>{number}</code> — node's index number inside its parent;</li>\n        <li><code>{Object}</code> — a node's parent;</li>\n        <li>\n          <code>{number}</code> — node's nesting level relative to its parent.\n        </li>\n      </ul>\n    </td>\n  </tr>\n</table>\n\n##### Examples\n\n```js\nparseTree.traverse(function(node, index, parent) {\n  if (node.is('multilineComment')) {\n    parent.removeChild(index);\n  } else if (node.is('space')) {\n    node.content = ' ';\n  }\n});\n```\n\n### parseTree.traverseByType(type, callback)\n\n##### Description\n\nThis method should be called for a root node, because calling it for a child\nwill be more time consuming.    \nCalls the function for every node of a given type. This means not just child\nnodes, but grandchilds and so on.\n\n##### Parameters\n\n<table>\n  <tr>\n    <td><i>{string}</i></td>\n    <td>type</td>\n    <td>\n      Node type. For a list of available values please see\n      <a href=\"docs/node-types.md\">\"Node types\"</a>.\n    </td>\n  </tr>\n  <tr>\n    <td><i>{Function}</i></td>\n    <td>callback</td>\n    <td>\n      Function to apply to every node of a given type.\n      Accepts following parameters:\n      <ul>\n        <li><code>{Object}</code> — a node to which we apply callback;</li>\n        <li><code>{number}</code> — node's index number inside its parent;</li>\n        <li><code>{Object}</code> — a node's parent.</li>\n      </ul>\n    </td>\n  </tr>\n</table>\n\n##### Examples\n\n```js\n// Remove all comments.\nparseTree.traverseByType('multilineComment', function(node, index, parent) {\n  parent.removeChild(index);\n});\n```\n\n### parseTree.traverseByTypes(types, callback)\n\n##### Description\n\nThis method should be called for a root node, because calling it for a child\nwill be more time consuming.    \nCalls the function for every node of given types. This means not just child\nnodes, but grandchilds and so on.\n\n##### Parameters\n\n<table>\n  <tr>\n    <td><i>{Array.string}</i></td>\n    <td>types</td>\n    <td>\n      List of node types. For a list of available values please see\n      <a href=\"docs/node-types.md\">\"Node types\"</a>.\n    </td>\n  </tr>\n  <tr>\n    <td><i>{Function}</i></td>\n    <td>callback</td>\n    <td>\n      Function to apply to every node of given types.\n      Accepts following parameters:\n      <ul>\n        <li><code>{Object}</code> — a node to which we apply callback;</li>\n        <li><code>{number}</code> — node's index number inside its parent;</li>\n        <li><code>{Object}</code> — a node's parent.</li>\n      </ul>\n    </td>\n  </tr>\n</table>\n\n##### Examples\n\n```js\n// Remove all comments and spaces.\nlet types = ['multilineComment', 'space'];\nparseTree.traverseByTypes(types, function(node, index, parent) {\n  parent.removeChild(index);\n});\n```\n\n### parseTree.type\n\n##### Returns\n\n<table>\n  <tr>\n    <td><i>{string}</i></td>\n    <td>\n      Node type. For a list of available values see\n      <a href=\"docs/node-types.md\">\"Node types\"</a>.\n    </td>\n  </tr>\n</table>\n\n\n## Test\n\nTo run tests:\n\n    npm test\n\nThis command will build library files from sources and run tests on all files\nin syntax directories.\n\nEvery test has 3 files: source stylesheet, expected parse tree and expected\nstring compiled back from parse tree to css.\n\nIf some tests fail, you can find information in test logs:\n\n- `log/test.log` contains all information from stdout;\n- `log/expected.txt` contains only expected text;\n- `log/result.txt` contains only result text.\n\nThe last two are made for your convenience: you can use any diff app to see\nthe defference between them.\n\nIf you want to test one specific string or get a general idea of how Gonzales\nworks, you can use `test/ast.js` file.    \nSimply change the first two strings (`css` and `syntax` vars) and run:\n\n    node test/single-test.js\n\n## Report\n\nIf you find a bug or want to add a feature, welcome to [Issues](https://github.com/tonyganch/gonzales-pe/issues).\n\nIf you are shy but have a question, feel free to [drop me a\nline](mailto:tonyganch+gonzales@gmail.com).\n","publish_time":1381670228382,"_cnpm_publish_time":1381670228382,"dist-tags":{"dev":"3.2.2","latest":"4.3.0","tg":"3.2.5-dev2"}}