Julien Le Coupanec
Julien Le Coupanec

Reputation: 7996

Meteor: Where should we put common functions?

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

Answers (3)

Peppe L-G
Peppe L-G

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

zakir2k
zakir2k

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

Joseph
Joseph

Reputation: 119847

Call them "helper" functions, not necessarily handlebars helpers.

This unofficial FAQ should give you an idea where to place what.

Upvotes: 3

Related Questions