node-traverse
TypeScript icon, indicating that this package has built-in type declarations

1.0.7 • Public • Published

Build Status Maintainability codecov GitHub issues GitHub

LICENSE

MIT

GOAL

Bind a directory to an object and load the modules in the directory dynamically.

INSTALL

npm i node-traverse

HOW TO USE

#   game
#    ├ user
#    │  └ weapon.js -------- exports.id = 3;
#    ├ Fashion.js   -------- exports.getList = function(){ return 1; };
#    ├ Fashion
#    │  └ hair.js   -------- exports.id = 4;
#    ├ friend.js    -------- class A{constructor(n){this.n = n}};A.n=2;module.exports=A;
#    └ user.js      -------- exports.id = 2;
 
 
const Trav = require('node-traverse');
const trav = Trav.import('test/game', { baseDir: process.cwd() });
 
trav.Fashion.getList();   // 1
trav.Fashion.hair.id;     // 4
trav.user.id;             // 2
trav.user.weapon.id;      // 3
 
 
 
const trav = Trav.import('game', {
    baseDir: __dirname,
    importType: Trav.IMPORT_TYPE.CLASS_INSTANCE,
    instanceParams: ['hee'],
});
 
trav.friend.n;             // hee;
 
const trav = Trav.import('game', {
    baseDir: __dirname,
    importType: Trav.IMPORT_TYPE.CLASS_AUTO,
});
 
trav.friend.n;             // 2;
trav.friend('hee').n;      // hee;

Package Sidebar

Install

npm i node-traverse

Weekly Downloads

10

Version

1.0.7

License

MIT

Unpacked Size

18 kB

Total Files

11

Last publish

Collaborators

  • uccu