โ05-07-2019 08:06 PM
How can we convert the string in Camel Case in mapper ?
โ05-16-2019 01:04 PM
Sure, but in your example that is not really camel case. it should result in a string that looks like this:
โtestUpperCaseโ
Also, the camelCase method will be able to convert all sorts of strings into camel case. not just ones seperated by spaces. for example:
โfooโbarโ.camelCase() โ fooBar
โfoo**barโ.camelCase() ->fooBar
so if the use case is for special characters as well as spaces, Iโd use the camelCase method
โ05-17-2019 12:29 AM
Hi cjhoward18,
To achieve this you could extend your expression: โtest camel-case+&^%$#@!*to=upperโ.replace(/\b\w/g, chr => chr.toUpperCase()).replace(/[^a-zA-Z0-9]/g, โโ)
โ05-17-2019 06:26 AM
Even that expression and example results in a string/strings not quite in camel case. It should result in a string like this: โtestCamelCaseToUpperโ for your example. The first word of a camel case word should be ALL lower case letters.
So, simply uppercasing the first letter of the recognized word will not achieve correct camel case, and not preserve already existing camel Case words. For another case similar to your example โtest cAMEL-CASE+&^%$#@!*TO=UPPERโ.camelCase() the result should be:
โtestCAmelCaseToUpperโ however your expression would result in: โTestCAMELCASETOUPPERโ, so I would really recommend using the camelCase method given in 4.17 since designing an expression to do this for all cases will not be trivial.
You can use Lodash REPL:
https://lodash.com/docs/4.17.11#camelCase
to see how camelCasing should behave.