Skip to content

uccu/node-traverse

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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;

About

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

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published