monkey-punch

0.0.10 • Public • Published

Graceful Monkey-patching.

UNDER HEAVY CONSTRUCTION

Monkey-patching is a way to override or extend the behaviour of a method without changing its original source code.

Override

var myMonkey = new Monkey({
  obj: patchTarget,
  method: 'sum',
  linesDelimiter: '\n',
  before: doItBefore,
  after: doItAfter,
  body: {
    regexps: {
      '/\)\n/g': addSemiQuoteFn, // add ';' after each ')'
      '/\{/g': ' ' // add space before each'{'
    },
    positions: {
      1: '// injection to line one',
      5: '// injection to line five',
      2: lineTwoInjectionFunc,
      '6,10': '// Injection to line 6 column 10',
      '2,3': lineTwoColumnThreeInjectionFunc
    }
  }
});
 
 
//...
myMonkey.restore();
// ...

References

Special thanks to Thai Pangsakulyanont and his article.

LICENSE

MIT: https://github.com/se-panfilov/monkey-punch/blob/master/LICENSE

Package Sidebar

Install

npm i monkey-punch

Weekly Downloads

1

Version

0.0.10

License

MIT

Last publish

Collaborators

  • se-panfilov