Giter Site home page Giter Site logo

requireindex's Introduction

Description

Write minimal node index.js files that require and export siblings by file basename

Latest Version

1.0.1

Installation

npm install requireindex

or in package.json

{
  ...
  "dependencies": {
    "requireindex": "1.0.x"
  }
}

Usage

Check the test directory for example usage. The test/lib looks like:

lib/
  index.js
  Foo.js
  bar/
    index.js
    f.js
    fing.js
    fed/
      again.js
      ignored.js
      index.js
      somemore.js
  bam.js
  _private.js

The index.js files in test/lib/ and test/lib/bar/ contain:

module.exports = require('requireindex')(__dirname);

and the index.js file in test/lib/bar/fed/ contains:

module.exports = require('requireindex')(__dirname, ['again', 'somemore']);

The optional second argument allows you to explicitly specify the required files using their basename. In this example test/lib/bar/fed/ignored.js is not included as a public module. The other way to make a module/file private without the need for explicitly naming all the other included files is to prefix the filename with an underscore, as demonstrated by test/lib/_private.js which is not exported.

So, with these index.js files, the result of

require('lib');

is:

{
  bam: {
    m: [Function],
    n: [Function]
  },
  bar: {
    f: [Function],
    fed: {
      again: [Function],
      somemore: [Function]
    },
    fing: [Function]
  },
  Foo: {
    l: [Function],
    ls: [Function]
  }
}

#Build status build status

requireindex's People

Contributors

stephenhandley avatar salmanm avatar eulalie367 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.