javascripthandlebars.jsmustacheassemble

How can I capitalize and remove spaces from a sentence/string?


I need this "get my first job" turn into this "GetMyFirstJob"

I am working with assemble http://assemble.io/helpers/helpers-strings.html but I don't see something like that in the docs.


Solution

  • Create a helper function and add the below code.

    Handlebars.registerHelper('toPascalCase', function(value) {
        return value.match(/[a-z]+/gi).map(function (word) {
          return word.charAt(0).toUpperCase() + word.substr(1).toLowerCase()
        }).join('');
    });
    

    Call like

    {{toPascalCase 'get my first job'}}