I'm not entirely sure what you mean with portable between projects, but if you want to share a formula between projects, then I suggest creating a package. Then you can install it where needed, and maintain it in a single place. And other people can benefit from it as well ๐
Also, to get the width of an element, I suggest you use getBoundingClientRect().width rather than getComputedStyle as the computed style doesn't actually tell you the real width on the screen. It won't always take into account transforms and paddings. Also, you won't have to parse the value as it is already numerical.