Can we create a mapper template in Javascript?

helped a fellow member out today with this JS template for a name:

        name: >
          [[[var moon = states['sensor.moon'].state;
          if (moon == 'new_moon') return 'Luna Nuova';
          if (moon == 'waning_crescent') return 'Gibbosa crescente';
          if (moon == 'waxing_crescent') return 'Mezzaluna crescente';
          if (moon == 'first_quarter')  return 'Primo Quarto';
          if (moon == 'waxing_gibbous') return 'Gibbosa crescente';
          if (moon == 'full_moon') return 'Luna Piena';
          if (moon == 'waning_gibbous')  return 'Gibbosa calante';
          return 'Ultimo Quarto';]]]

in Jinja, I would have suggested creating a mapper, but in JS I dont think I ve seen that being used before, though it must be possible.
Could anyone check and see if we can do something like this in JS:

{% set mapper = 
  {'new_moon':'Luna Nuova',
   'waning_crescent':'Gibbosa crescente',
   'waxing_crescent':'Mezzaluna crescente',
   'first_quarter':'Primo Quarto',
   'waxing_gibbous':'Gibbosa crescente',
   'full_moon':'Luna Piena',
   'waning_gibbous':'Gibbosa calante'} %}

{% set state = states('sensor.moon') %}
{% set moon = mapper[state] if state in mapper else 'Ultimo Quarto' %}

answering myself for reference:

with help from @RomRider: yes we can :wink:

      - type: custom:button-card
        template: button_body
        entity: sensor.mooon
        size: 70%
        show_name: true
        show_entity_picture: true
        name: >
          [[[var moon = states['sensor.moon'].state;
             var mapper = {
               new_moon:'Luna Nuova',
               waning_crescent:'Gibbosa crescente',
               waxing_crescent:'Mezzaluna crescente',
               first_quarter:'Primo Quarto',
               waxing_gibbous:'Gibbosa crescente',
               full_moon:'Luna Piena',
               waning_gibbous:'Gibbosa calante'}
             return mapper[moon] ? mapper[moon] : 'Ultimo Quarto';]]]
        entity_picture: >
          [[[ return states['sensor.moon_phases'].attributes.entity_picture;]]]