Are we able to use lodash in transformations? I s...
# support
t
Are we able to use lodash in transformations? I see the concept of Libraries but there are only a few limit default there.
m
Hey There! 👋 Your message has been received by the RudderStack team. We will forward this request to your Technical Account Manager, and they will get back to you shortly. Please use the thread for any additional comments.
Hi Trevin, unfortunately this is not supported, however - If the functionality you are looking for is available within the standard libraries, you can use them - You can create an endpoint that performs the necessary Lodash function and returns the respective object `export async function transformEvent(event, metadata) { if (condition) { // Your endpoint to perform the Lodash action const res = await fetch("" + event.properties); event.context.some_property = res; } return event; }`⁣
t
@shy-kite-21035 what does this mean when you say "If the functionality you are looking for is available within the standard libraries, you can use them"?
Transformations would be so much more powerful if Rudderstack supported popular libraries like lodash as it's methods are often so good for working on objects and arrays.
m
If the functionality you are looking for is available within the standard libraries, you can use them"
RudderStack's libraries provide standard features such as hashing, encryption, parsing etc. However, another workaround that you can use is to use the vanilla code of Lodash and add it as a library. Then you can fetch the methods from this library and use it.
Transformations would be so much more powerful if Rudderstack supported popular libraries like lodash as it's methods are often so good for working on objects and arrays.
I agree with this but the way RudderStack is currently setup it does not support importing these external libraries.
Also, I was going through the Lodash code and found that since most of the functions are defined within the runInContext function, I am not sure how you will expose functions such as map, uniq, tail, times can be exposed. The functions outside the runInContext, can be exposed by removing the top self-invoking function and adding the export keyword next to the function. Eg:-
Copy code
export function strictLastIndexOf(array, value, fromIndex)
t
sounds too error prone unfortunately
m
Yes. As I mentioned earlier unfortunately there is no good way of doing it currently. However, can you elaborate more on your use case (How you are using Lodash in the user transformation).
t
@shy-kite-21035 bringing this convo back up. one specific use case for lodash is trying to duplicate events. With code like this:
Copy code
let modifiedEvent = JSON.parse(JSON.stringify(event));
This doesn't work quite well in all cases for keys, for example if undefined. Lodash has built in functions for deep copying which handles this seamlessly.
m
Hi Trevin I understand the need to be able to load external packages to your transformation but unfortunately the way the transformations are currently built does not support this. Also the work required to change this is substantial and hence has not gotten prioritized. Another related feature is to refer to one library from another and this is not supported either.