0.0.5 • Published 10 years ago

require-patch v0.0.5

Weekly downloads
4
License
MIT
Repository
github
Last release
10 years ago

require-patch

Patch the global nodejs require hook

Installation

npm install require-patch

Usage

Let's say you want to setup a function that copies files when they're required, you might want to use it like this

usage.js

var copied = require.copy('./myjsonfile.json');

Here's how you'd set that up in your main app file

main.js

extend = require('extend');
var patcher = require('require-patch');

patcher.patch(function(globalRequire) {
  globalRequire.copy = function(filepath) {
    return extend(true, {}, globalRequire(filepath));
  }
});

usage = require('./usage');

Note: Only works in native node environments that don't do static preprocessing of require()'s (Mocha, webpack, etc. don't work)

0.0.5

10 years ago

0.0.4

10 years ago

0.0.3

10 years ago

0.0.2

10 years ago

0.0.1

10 years ago

0.0.0

10 years ago