{"_id":"replace-method","_rev":"4-4b80fe7293baf35a71350324e2d2cec0","name":"replace-method","description":"JavaScript post-processing step to replace specific function/method calls with other bits of JavaScript","dist-tags":{"latest":"0.0.0"},"versions":{"0.0.0":{"name":"replace-method","description":"JavaScript post-processing step to replace specific function/method calls with other bits of JavaScript","version":"0.0.0","main":"index.js","browser":"index.js","dependencies":{"recast":"~0.5.7"},"devDependencies":{"faucet":"0.0.0"},"scripts":{"test":"faucet test.js"},"author":{"name":"Hugh Kennedy","email":"hughskennedy@gmail.com","url":"http://hughsk.io/"},"license":"MIT","repository":{"type":"git","url":"git://github.com/hughsk/replace-method"},"bugs":{"url":"https://github.com/hughsk/replace-method/issues"},"homepage":"https://github.com/hughsk/replace-method","keywords":["replace","method","call","post-processing","language","macro","transform","meta","inline","inlining","brfs"],"_id":"replace-method@0.0.0","dist":{"shasum":"3704d10711c2d461db0291355061053cee83faf9","tarball":"https://registry.npmjs.org/replace-method/-/replace-method-0.0.0.tgz","integrity":"sha512-EnFmtCN4d1HxEbZOcT3QcHqS1jWX19hr8bAh62liHBEBnl8X+3/X6mw8NsZYFQcuXKHpt2+JtZMDPcbfobT8+g==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIDvOJ/agKwpUrvMNtKdx1NvmEbvYyELs0K1XqgG6d/SFAiEA/Xgl6FbaxkZGGPdivl1XzPfSICxbFvmKL1j5FtPo5bU="}]},"_from":".","_npmVersion":"1.3.25","_npmUser":{"name":"hughsk","email":"hughskennedy@gmail.com"},"maintainers":[{"name":"hughsk","email":"hughskennedy@gmail.com"}]}},"readme":"# replace-method [![Flattr this!](https://api.flattr.com/button/flattr-badge-large.png)](https://flattr.com/submit/auto?user_id=hughskennedy&url=http://github.com/hughsk/replace-method&title=replace-method&description=hughsk/replace-method%20on%20GitHub&language=en_GB&tags=flattr,github,javascript&category=software)[![experimental](http://hughsk.github.io/stability-badges/dist/experimental.svg)](http://github.com/hughsk/stability-badges) #\n\nJavaScript post-processing step to replace specific function/method calls with\nother bits of JavaScript. It doesn't take scope into account, but is otherwise\na good starting point for writing your own inlinifying transform modules like\n[`brfs`](http://github.com/substack/brfs).\n\n## Usage ##\n\n[![replace-method](https://nodei.co/npm/replace-method.png?mini=true)](https://nodei.co/npm/replace-method)\n\n### `replace = require('replace-method')(ast)` ###\n\nReturns a function you can use to replace methods with other things.\n\nWhere `ast` is either a string of source code, or an AST object such as one\ngenerated by [esprima](http://github.com/ariya/esprima/).\n\n### `replace(method, found)` ###\n\nWhere `method` is an array of variable names, such that:\n\n* `['__filename']` will match `__filename`.\n* `['fs', 'readFileSync']` will match `fs.readFileSync`.\n* `['a', 'nested', 'property']` will match `a.nested.property`.\n\n`found` is then called once per every node in the AST found – if you return\nnothing or `undefined`, nothing will change. However, if you return an AST\nobject that content will be replaced, e.g.:\n\n``` javascript\nreturn {\n  type: 'Literal',\n  value: 'hello world'\n}\n```\n\nWill replace the matched variable with the string `\"hello world\"`.\n\n### `replace.code()` ###\n\nReturns the updated version of your code after having made the transformations\nyou needed. Note that the supplied `ast` object you provided will be modified\ndirectly so you can convert it to JavaScript yourself or hand it off to other\nprocessing steps if need be.\n\n## Example ##\n\n``` javascript\nvar replaceMethod  = require('replace-method')\nvar evaluate       = require('static-eval')\nvar escodegen      = require('escodegen')\nvar esprima        = require('esprima')\nvar fs             = require('fs')\n\nvar src = replaceMethod(\n  fs.readFileSync(__filename, 'utf8')\n)\n\nsrc.replace(['fs', 'readFileSync'], function(node) {\n  if (!node.arguments.length) return\n\n  var filename = evaluate(node.arguments[0], {\n      __filename: __filename\n    , __dirname:  __dirname\n  })\n\n  if (filename) return {\n      type: 'Literal'\n    , value: fs.readFileSync(filename, 'utf8')\n  }\n})\n\nconsole.log(src.code())\n```\n\n## License ##\n\nMIT. See [LICENSE.md](http://github.com/hughsk/replace-method/blob/master/LICENSE.md) for details.\n","maintainers":[{"name":"hughsk","email":"hughskennedy@gmail.com"}],"time":{"modified":"2022-06-26T11:20:20.476Z","created":"2014-02-05T04:02:03.794Z","0.0.0":"2014-02-05T04:02:03.794Z"},"readmeFilename":"README.md"}