1.0.0 • Published 5 years ago

requirejs-helper v1.0.0

Weekly downloads
3
License
MIT
Repository
github
Last release
5 years ago

@jkinfeng/requirejs-helper

Autoload js file of Node.js

NPM version NPM Downloads MIT License

Installation

npm i requirejs-helper

API Reference

ParamTypeDefault ValueDescription
$optionsObject
$options.pathStringprocess.cwd()js file base path
$options.regularRegular expression/\.js$/js file match

Example
Basic usage:

const requireJs = require('requirejs-helper');

// returns an object, Null object if no jsfile is loaded.
const obj = requireJs({
  path: 'path',
  regular: /\.js$/
});

// Call mode
// obj.filename.doSomething
// filename: name of js file
// doSomething: object, function or both

// Suppose you load a js file that contains an object and a function
// myFunc.js
// ============================================
// module.exports = {a: 123, b: function(){return 'b'}}
// ============================================

// Object-Call: obj.myFunc.a
// Function-Call: obj.myFunc.b()

// Tips: the dots contained in the file name are replaced by underscores
// my.func.js => obj.my_func

Contributing

Please submit all issues and pull requests to the jkinfeng/requirejs-helper repository!

Support

If you have any problem or suggestion please open an issue here.

License

MIT