README.md
1 ## Escodegen 2 [](http://badge.fury.io/js/escodegen) 3 [](http://travis-ci.org/estools/escodegen) 4 [](https://david-dm.org/estools/escodegen) 5 [](https://david-dm.org/estools/escodegen#info=devDependencies) 6 7 Escodegen ([escodegen](http://github.com/estools/escodegen)) is an 8 [ECMAScript](http://www.ecma-international.org/publications/standards/Ecma-262.htm) 9 (also popularly known as [JavaScript](http://en.wikipedia.org/wiki/JavaScript)) 10 code generator from [Mozilla's Parser API](https://developer.mozilla.org/en/SpiderMonkey/Parser_API) 11 AST. See the [online generator](https://estools.github.io/escodegen/demo/index.html) 12 for a demo. 13 14 15 ### Install 16 17 Escodegen can be used in a web browser: 18 19 <script src="escodegen.browser.js"></script> 20 21 escodegen.browser.js can be found in tagged revisions on GitHub. 22 23 Or in a Node.js application via npm: 24 25 npm install escodegen 26 27 ### Usage 28 29 A simple example: the program 30 31 escodegen.generate({ 32 type: 'BinaryExpression', 33 operator: '+', 34 left: { type: 'Literal', value: 40 }, 35 right: { type: 'Literal', value: 2 } 36 }); 37 38 produces the string `'40 + 2'`. 39 40 See the [API page](https://github.com/estools/escodegen/wiki/API) for 41 options. To run the tests, execute `npm test` in the root directory. 42 43 ### Building browser bundle / minified browser bundle 44 45 At first, execute `npm install` to install the all dev dependencies. 46 After that, 47 48 npm run-script build 49 50 will generate `escodegen.browser.js`, which can be used in browser environments. 51 52 And, 53 54 npm run-script build-min 55 56 will generate the minified file `escodegen.browser.min.js`. 57 58 ### License 59 60 #### Escodegen 61 62 Copyright (C) 2012 [Yusuke Suzuki](http://github.com/Constellation) 63 (twitter: [@Constellation](http://twitter.com/Constellation)) and other contributors. 64 65 Redistribution and use in source and binary forms, with or without 66 modification, are permitted provided that the following conditions are met: 67 68 * Redistributions of source code must retain the above copyright 69 notice, this list of conditions and the following disclaimer. 70 71 * Redistributions in binary form must reproduce the above copyright 72 notice, this list of conditions and the following disclaimer in the 73 documentation and/or other materials provided with the distribution. 74 75 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 76 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 77 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 78 ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY 79 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 80 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 81 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 82 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 83 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 84 THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.