Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

194
Visualizações
Wrap generic expressions into a function

I am part of n8n.io, an open source project, and we're looking for a way to help our users manipulate data.

Our tool allows users to get data from any source (database, http requests, queue services, etc), manipulate and do other stuff, such as send an email, create a lead on Hubspot, etc. It's a workflow automation tool.

We already provide ways for our users to map data from one place to another, such as get a username from a database and send it as the Lead's name to Hubspot. But users may want to manipulate this data before sending.

We want to add helper functions for this.

Our users can already use a template engine to make some interesting stuff, such as:

{{ username.toUpperCase() }}

Given that username in the example above is a string, and the toUpperCase() is the native string function.

We would like to extend this behavior. Add more functionality. For instance, something like {{ email.isEmail() ? email : '' }} where isEmail is a new function we would like to provide and email is simply a string.

One important note is that we would like these functions to be chainable instead of simply functions to avoid parenthesis hell.

I thought about extending the native prototypes, but this comes with a lot of side effects, especially because we also want to extend Object properties (with functions such as .hasField('username') or .removeField('name'). Extending prototypes ended up breaking a lot of stuff, so we cannot follow this path.

Also users can do math operations, such as {{ (age + 5) / 2 }}, so we need operations that work over numbers, strings, objects and arrays.

I would appreciate any ideas on how to achieve this: providing functions that can be chained to manipulate data.

We would like to avoid forcing our users to wrap their data in a helper function, like {{ _(name).firstName().toUpperCase() }}. In this case, we would implement the _ function as a helper and have all methods implemented inside of it, depending on the data type.

Is there a way to wrap any expression into a helper function, such as the above mentioned? A regular expression that is fail proof would be amazing.

Please bear in mind that expressions can be very arbitrary, such as:

{{ (5
+
2

).isPrime
() ? 'This is prime' : 42
}}

The above example is a perfectly valid expression, and my goal is to wrap the section (5+2) in our helper function so it the final result, before dispatching to our template engine, should look like this:

{{ _((5
+
2

)).isPrime
() ? 'This is prime' : 42
}}
about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda