{"_id":"monkeypatch","_rev":"3-d6709033d19440ba96bde0eee40d0b2d","name":"monkeypatch","description":"Slightly easier monkeypatching","dist-tags":{"latest":"1.0.0"},"versions":{"1.0.0":{"name":"monkeypatch","version":"1.0.0","description":"Slightly easier monkeypatching","main":"index.js","scripts":{"test":"mocha -R spec --bail test.js"},"author":{"name":"Robert Klep","email":"robert@klep.name"},"repository":{"type":"git","url":"https://github.com/robertklep/node-monkeypatch"},"license":"MIT","devDependencies":{"chai":"^2.3.0","mocha":"^2.2.5","mocha-sinon":"^1.1.4","sinon":"^1.14.1"},"gitHead":"91add32e776bcd742616d9991d41c775bb7a7daf","bugs":{"url":"https://github.com/robertklep/node-monkeypatch/issues"},"homepage":"https://github.com/robertklep/node-monkeypatch","_id":"monkeypatch@1.0.0","_shasum":"a7baaeaebf2e01ee6c8a585615cc4a2663dea145","_from":".","_npmVersion":"2.7.4","_nodeVersion":"0.12.2","_npmUser":{"name":"robertklep","email":"robert.klep@gmail.com"},"maintainers":[{"name":"robertklep","email":"robert.klep@gmail.com"}],"dist":{"shasum":"a7baaeaebf2e01ee6c8a585615cc4a2663dea145","tarball":"https://registry.npmjs.org/monkeypatch/-/monkeypatch-1.0.0.tgz","integrity":"sha512-6tG0IrCUUIBuAspnbdmOAd+D/AptB/ya9JLujp88NIAuFuTGdGvCKtDkc6pwNOcIJ6nKLm3FjJlaCdx8vr3r2w==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDSMFSuLzbGh2MTNjHVU4c7kQ6TbMe77x5JlzxaUYq7MwIgWEBDr/N8V1vbCQSUHu9RphEIGSq6VVXeDmZi2FUHVmo="}]}}},"readme":"## node-monkeypatch\n\nSlightly easier monkeypatching.\n\n### Installation\n\n```\nnpm install monkeypatch\n```\n\n### Usage\n\n```javascript\nmonkeypatch(target : Object, method : String, handler : Function) : Function\n```\n\nMonkeypatching a method/function on a target object replaces the method with a newly supplied handler function which will get called instead of the original.\n\nThe original method will be returned by `monkeypatch()`, and will also be passed as the first argument to the new handler function. See examples.\n\n### Examples\n\n##### Patching a function\n\n```javascript\nvar monkeypatch = require('monkeypatch');\n\n// Monkeypatch Date.now()\nmonkeypatch(Date, 'now', function(original) {\n  // Round to 15-minute interval.\n  var ts = original();\n  return ts - (ts % 900000);\n});\n\nvar timestamp = Date.now(); // returns a rounded timestamp\n...\n```\n\n##### Patching an instance method\n\n```javascript\nvar monkeypatch = require('monkeypatch');\n\n// Monkeypatch Date#getTime()\nmonkeypatch(Date.prototype, 'getTime', function(original) {\n  // Round to 15-minute interval.\n  var ts = original();\n  return ts - (ts % 900000);\n});\n\nvar date      = new Date();\nvar timestamp = date.getTime(); // returns a rounded timestamp\n...\n```\n\n##### Argument handling\n\n```javascript\nvar monkeypatch = require('monkeypatch');\n\n// Monkeypatch Date#setTime()\nmonkeypatch(Date.prototype, 'setTime', function(original, ts) {\n  // Round to 15-minute interval.\n  ts = ts - (ts % 900000);\n  // Call the original.\n  return original(ts);\n});\n\nvar date = new Date();\ndate.setTime(date.getTime()); // set to a rounded timestamp\n...\n```\n\n##### Unpatching\n\n```javascript\nvar monkeypatch = require('monkeypatch');\n\n// Monkeypatch Date.now()\nmonkeypatch(Date, 'now', function() { return 143942400000; });\n\nconsole.log(Date.now()); // logs 143942400000\n\nDate.now.unpatch();\n\nconsole.log(Date.now()); // logs current time\n```\n","maintainers":[{"name":"robertklep","email":"robert.klep@gmail.com"}],"time":{"modified":"2022-06-20T08:34:10.276Z","created":"2015-05-18T09:12:51.863Z","1.0.0":"2015-05-18T09:12:51.863Z"},"homepage":"https://github.com/robertklep/node-monkeypatch","repository":{"type":"git","url":"https://github.com/robertklep/node-monkeypatch"},"author":{"name":"Robert Klep","email":"robert@klep.name"},"bugs":{"url":"https://github.com/robertklep/node-monkeypatch/issues"},"license":"MIT","readmeFilename":"README.md"}