New:Microsoft Teams Notifications Are Now Available in Socket.Learn more →
Get Started

noader

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

noader

NodeJS module automatic on-demand lazy loader

Source
npmnpm
Version
2.1.0
Version published
Weekly downloads
17
21.43%
Maintainers
1
Weekly downloads
 
Created
Source

noader

NodeJS module automatic on-demand lazy loader(NodeJS模块自动按需懒加载器)

Install

npm install noader

Usage

/*
  module a
  /app/module/a.js
*/
module.exports = {
  name: 'test',
  fun: function(str){
    return str;
  },
  cls: class {
    constructor(str) {
      this.str = str;
    }
    fun() {
      return this.str;
    }
  }
}

/*
  module b
  /app/b.js
*/
module.exports = class {
  constructor(str) {
    this.str = str;
  }
  fun() {
    return this.str;
  }
}

/*
  module test
  /test.js
*/

const noader = require('noader');

const loader = noader();
console.log(loader.app.module.a.name); // test
console.log(loader.app.module.a.fun('test1')); // test1
console.log(new loader.app.module.a.cls('test2').fun()); // test2

//if the module is a class, the loader will auto new a instance
console.log(loader.app.b); // class function
console.log(loader.app.b.fun()); // undefined

//the args will be used at new
const loader2 = noader(__dirname, 'test3');
console.log(loader2.app.b.fun()); // test3

console.log(loader2.app.b.$class); // true
console.log(loader2.app.b.$instance); // class instance
console.log(loader2.app.b.$path); // /workspace/test/app/b/

License

MIT

Keywords

nodejs

FAQs

Package last updated on 17 Nov 2019

Related posts