Git Product home page Git Product logo

req2's Introduction

req2

req2 is an enhanced replacement for 'require' in Node.js. It's also really handy in CoffeeScript.

Why?

I always wanted to be able to require multiple modules via destructuring assignment so as to keep things smaller and tidyer. I also figured that require should be able to read in the text from a file too. That bit is synchronous right now, but later on I may have it detect pairs of files and callbacks.

Installation

$ npm install req2

Features

  • Works as normal.

      //JavaScript
      var module = require('req2')('module');
    
      #CoffeeScript:
      module = require('req2')('module')
      #or
      module = require('req2') 'module'
    
  • Require multiple modules (as either mutiple arguments or as an array), returned in an array.

      //JavaScript
      var modules = require('req2')('module0','module1');
      var module0 = modules[0];
      var module1 = modules[1];
      //or
      var modules = require('req2')(['module0','module1']);
      var module0 = modules[0];
      var module1 = modules[1];
      
      #CoffeeScript
      [module0,module1] = require('req2') 'module0','module1'
      #or
      [module0,module1] = require('req2') ['module0','module1']
    
  • Open files (with fs.readFileSync).

      //JavaScript
      var file = require('req2')('./file.txt');
      
      #CoffeeScript:
      file = require('req2') './file.txt'
    

Future Stuff

  • Async file reads.
  • HTTP
  • Automatically installing packages via npm? (Not sure if I want to do this one.)

License

See LICENSE.txt

req2's People

Contributors

bengl avatar

Stargazers

 avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.