Custom javascript library to reuse in Button Card

HI,

I’d like to create a library of custom javascript functions to be reused in Button Card.
I created a common_functions.js file in /config/www.
I added a resource to lovelace for the created file. (/local/common_functions.js)
I created a simple example function in file common_functions.js:

function test_function(input) {
   var value = input + 1;
   return value;
}

I created an example card:

type: custom:button-card
name: |
   [[[
     return test_function(10);
   ]]]

But button-card doesn’t see my custom function.

ButtonCardJSTemplateError: ReferenceError: test_function is not defined in 'return test_function(10);'

Any tips?

I’m trying to do the same. Have you found a solution for this?

unfortunately not

And now ? because i’m looking to that too :wink:

Custom button-card offers helpers object with functions prepared for formatting date/time values. Maybe thats the direction of considerations? Maybe it’s worth to take a look inside custom-button javascript code? If somebody has enough skills :slight_smile:

Is this suggestion or advice? Just curious because you are responding to a post from 9 months ago…

True. But I believe this is not a resolved issue and I’m very interested in getting a kick to some direction. My skills are not greate in javascript modules/resources, so I try to kick somebody else :slight_smile: