s-declare
v1.7.0
Published
Node modules declaration
Downloads
18
Readme
s-declare
An easy way to create named modules within the application.
installation for Node.js
npm i s-declare --save
installation for Browser
bower i s-declare --save
Declaration of module
Arguments it's a modules which be applied to function for creating module. Of course, we can use the standard way.
var declare = require('s-declare');
// write like node module and declaration module
module.exports = declare('test', function ( path, http, url ) {
require('path') == path; // => true
// code of module
return {}; // stored like a module 'test' it can be any
});
// got it
declare.require('test'); // => stored module 'test'
More complicated
When we create a separate module, create a declaration of files related to this module.
var declare = require('s-declare');
// then create module
module.exports = declare('myModule', ['path', 'http', 'url', './test/test.lib.js',
function ( path, http, url, test ) {
// code of module
return {}; // stored like a module
}]);
if(
declare.require('myModule') == module.exports
&& declare.require('myModule') == require('./path/to/file')
) {
console.log( 'Completely usability victory !!!' );
} else {
console.log( 'Completely fail ...' );
};
No store
When we create a module for NPM no need stored parts of module in declarator.This is not just pointless and even harmful. We can only use the declarator for file management. To create a user-friendly module supplier.
var declare = require('s-declare');
// with name null, a declarator isn't stored module
module.exports = declare(null, [
'http',
'./lib/part-1.js',
'./lib/part-2.js',
'./lib/part-3.js',
'./lib/part-4.js',
function ( http, part1, part2 ,part3, part4 ) {
return {
util: util,
part1: part1,
readOnly: function () {
return Object.assign({}, part3, part4);
}
};
}]);