{"_id":"esrefactor","_rev":"87258","name":"esrefactor","description":"ECMAScript refactoring helper","dist-tags":{"latest":"0.1.0"},"maintainers":[{"name":"ariya","email":""}],"time":{"modified":"2021-06-03T10:28:22.000Z","created":"2013-04-25T04:27:38.689Z","0.1.0":"2013-04-25T04:27:38.689Z"},"users":{"darlanalves":true},"repository":{"type":"git","url":"http://github.com/ariya/esrefactor.git"},"versions":{"0.1.0":{"name":"esrefactor","description":"ECMAScript refactoring helper","main":"lib/esrefactor.js","version":"0.1.0","engines":{"node":">=0.4.0"},"maintainers":[{"name":"ariya","email":""}],"repository":{"type":"git","url":"http://github.com/ariya/esrefactor.git"},"licenses":[{"type":"BSD","url":"http://github.com/ariya/esrefactor/raw/master/LICENSE.BSD"}],"dependencies":{"esprima":"~1.0.2","estraverse":"~0.0.4","escope":"~0.0.13"},"devDependencies":{"istanbul":"~0.1.33"},"scripts":{"test":"node test/run.js && npm run-script coverage","coverage":"npm run-script analyze-coverage && npm run-script check-coverage","analyze-coverage":"node node_modules/istanbul/lib/cli.js cover test/run.js","check-coverage":"node node_modules/istanbul/lib/cli.js check-coverage --statement -2 --branch -4 --function 100"},"_id":"esrefactor@0.1.0","dist":{"shasum":"d142795a282339ab81e936b5b7a21b11bf197b13","size":8080,"noattachment":false,"key":"/esrefactor/-/esrefactor-0.1.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/esrefactor/download/esrefactor-0.1.0.tgz"},"_npmVersion":"1.1.61","_npmUser":{"name":"ariya","email":"ariya.hidayat@gmail.com"},"directories":{},"publish_time":1366864058689,"_cnpm_publish_time":1366864058689,"_hasShrinkwrap":false}},"readme":"**esrefactor** (BSD licensed) is a little helper library for ECMAScript refactoring.\n\n## Usage\n\nWith Node.js:\n\n```bash\nnpm install esrefactor\n```\n\nIn a browser, include first all the dependents:\n\n```\n<!-- esrefactor depends on these libraries -->\n<script src=\"esprima.js\"></src>\n<script src=\"estraverse.js\"></src>\n<script src=\"escope.js\"></src>\n\n<script src=\"esrefactor.js\"></src>\n```\n## API\n\nBefore using the API, a context needs to be created:\n\n```javascript\nvar ctx = new esrefactor.Context(code);\n```\n\nwhere `code` is the source code.\n\n### Identification\n\nAn identifier, whether it is a variable, a function name, or a function\nparameter, can be identified using `identify()`. Example:\n\n```javascript\nvar ctx = new esrefactor.Context('var x = 42; y = x * 2; z = x / 2');\nvar id = ctx.identify(4);\n```\n\nThe only argument to `identify` is the zero-based position index.\n\nThe return object has 3 (three) properties:\n\n* `identifier`: the syntax node associated with the position\n* `declaration`: the declaration syntax node for the identifier\n* `references`: an array of all identical references\n\nIf there is no declaration for the identifier (e.g. `x = 42`, global\nleak), then `declaration` will be _null_.\n\nThe resolution of the declaration syntax node and the references array\ntake into account the identifier scope as defined in the official\nECMAScript 5.1 Specification (ECMA-262).\n\nNote that if there is no identifier in the given position index,\n`identify()` will return _undefined_.\n\n### Renaming\n\nAn identifier can be renamed using `rename()`. All other identical references\nassociated with that identifier will be renamed as well, again taking into\naccount the proper identifier scope. Renaming works for variable declaration,\nfunction name, and function parameter.\n\nFor `rename()` to work, it needs to have the identification result\n(via `identify`) and the new name for the identifier.\n\n```javascript\nvar ctx = new esrefactor.Context('var x; x = 42');\nvar id = ctx.identify(4);\nvar code = ctx.rename(id, 'answer');\n```\nIn the above example, `code` is `var answer; answer = 42`.\n\n","_attachments":{}}