Reputation: 7996
I have some common functions (E.g. trimInput(), isEmail(), isFacebookPage()...) in my project that I often use on client side. I was wondering where would it be the best place to put them so as to avoid code duplication?
trimInput = function(value) {
return value.replace(/^\s*|\s*$/g, "");
};
Upvotes: 3
Views: 2211
Reputation: 8345
In addition to the server
and client
folders, I usually create a both
folder, containing all code that should be on both the client and the server. You basically get the same results as if you would name it lib
, but putting common code in a folder named lib
does not always make sense.
Upvotes: 1
Reputation: 57
If you use these functions on both the server side and client side.
I would declare it has a helper function within a common.js file inside a /lib folder.
Upvotes: 0
Reputation: 119847
Call them "helper" functions, not necessarily handlebars helpers.
This unofficial FAQ should give you an idea where to place what.
Upvotes: 3