monkey-punch

Graceful Monkey-patching. ------

Usage no npm install needed!

<script type="module">
  import monkeyPunch from 'https://cdn.skypack.dev/monkey-punch';
</script>

README

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