Add global helper functions to bit.dev project

Viewed 19

I am pretty happy with bit.dev. But there is one point I am not getting to work. I need some global functions like formatting currency or saving same constants and enums, that I want to use from different components.

One way would be to add the code to every single component, but that would be just code duplication. The other way could be to create a component with just constants or helper functions, but I don't know whether bit is designed for that way.

Is there some best practice how I could solve that problem?

best regarts!

1 Answers

I work at Bit. In Bit, we solved it by having a scope for utilities functions, which we named toolbox.

Inside that scope, you can publish each of your functions as a nodeJS component. You can give it a look here to our Toolbox

Inside of it, we created several namespaces. We have one for strings, arrays, filesystem, and many others.

The principle is the same as you have been working so far: create your component, export it, and import it to any project you may need.

Let me know if that helped

Related