javascript - NodeJS - Export multiple functions -


i trying build first nodejs module. doing:

var text = function(){     this.padright = function(width, string, padding){         return (width <= string.length) ? string : this.padright(width, string + padding, padding);     };     this.cleantext = function(text){         if (typeof text !== 'undefined') {             return text.replace(/(\r\n|\n|\r)/gm,"");         }         return null;     };     this.printout = function(outputobj){         var module = this,             output = "";          outputobj.foreach(function(obj){             switch(obj.type){                 case "date" :                     var date = obj.contents;                     if(typeof date != "undefined") output += date.tostring().substring(4, 25) + "\t";                     break;                 case "string":                     var string = obj.contents;                     if(typeof string != "undefined"){                         string = module.cleantext(string);                         if(typeof obj.substring != "undefined" && obj.substring != 0) {                             string = string.substring(0, obj.substring);                         }                         if(typeof obj.padright != "undefined" && obj.padright != 0) {                             string = module.padright(15, string, " ");                         }                         output += string + "\t";                     }                     break;             }         });         console.log(output);     }; };  module.exports.text = text; 

i trying have different kind of helpers, want able call module this:

require("helpers");     helpers.text.printout(); 

but getting error.

how export different functions in same module , call them individually?

thanks

the problem text function in itself, looks me want exporting instance of text rather function i.e.

module.exports.text = new text(); 

Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -