Skip to content

best way to capitalize a string in js, use a function #219

Answered by elchininet
Mariusthvdb asked this question in Q&A
Discussion options

You must be logged in to vote

would you think this is the best way to go

Yes, you are already doing it in the right way. There are many ways in which you can write such a function, this is just one of them (remember that you can include a partial inside another partial):

js_variables:
  trash: sensor.afvalwijzer_vandaag
  temperature: sensor.temperature
partials:
  utilities: |
    const capitalize = str => str[0].toUpperCase() + str.slice(1);
  data: |
    @partial utilities
    const afval = capitalize(states(trash));
order:
  - item: something
    name: |
      [[[
        @partial data
        return afval;
      ]]]
    info: |
      [[[
        @partial utilities
        return capitalize(states(temperature));

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@Mariusthvdb
Comment options

Answer selected by Mariusthvdb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants