As I know, CouchDB allows to use some integrated Erlang functions like a sort (and something else).
Doing text trimming in JS again, I thought: what if Couch already built this feature in? Maybe trim also integrated? And how much functions are ready to use?
If they are already done in Erlang, why I must use slow JS-versions?
So, that's my question: where I can find full list of available from JS functions for Couch?
Conclusion: it only a few of functions available and there's no trim. You can test your luck by writing your own functions at couch_query_server.erl and then rebuilding Couch from source.