example.js 592 B

123456789101112131415161718
  1. var extractOpts = require('./').extractOpts;
  2. // fs.readFile(filename, [options], callback)
  3. var readFile = function(filename, opts, callback){
  4. // Extract options and callback
  5. var args = extractOpts(opts, callback);
  6. opts = args[0];
  7. callback = args[1];
  8. // Forward for simplicities sake
  9. require('fs').readFile(filename, opts, callback);
  10. };
  11. // Test it
  12. var next = console.log.bind(console);
  13. readFile('package.json', next); // works with no options
  14. readFile('package.json', null, next); // works with null options
  15. readFile('package.json', {next:next}); // works with just options