1. requireindex
Write minimal node index.js files that require and export siblings by file basename
requireindex
Package: requireindex
Created by: stephenhandley
Last modified: Sun, 26 Jun 2022 11:42:26 GMT
Version: 1.2.0
License: MIT
Downloads: 21,250,592
Repository: https://github.com/stephenhandley/requireindex

Install

npm install requireindex
yarn add requireindex

Description

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

Latest Version

1.2.0

Installation

npm install requireindex

or in package.json

 {
  ...
  "dependencies": {
    "requireindex": "1.1.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

Dependencies

RELATED POST

10 Must-Know Windows Shortcuts That Will Save You Time

10 Must-Know Windows Shortcuts That Will Save You Time

Arrays vs Linked Lists: Which is Better for Memory Management in Data Structures?

Arrays vs Linked Lists: Which is Better for Memory Management in Data Structures?

Navigating AWS Networking: Essential Hacks for Smooth Operation

Navigating AWS Networking: Essential Hacks for Smooth Operation

Achieving Stunning Visuals with Unity's Global Illumination

Achieving Stunning Visuals with Unity's Global Illumination

Nim's Hidden Gems: Lesser-known Features for Writing Efficient Code

Nim's Hidden Gems: Lesser-known Features for Writing Efficient Code