Add some useful handelbars helpers

This commit is contained in:
2023-07-18 13:24:18 +01:00
parent 1ce6548849
commit d69a89a761
2 changed files with 35 additions and 0 deletions

View File

@@ -0,0 +1,25 @@
/**
* This file contains extra helper functions for Handlebars.js.
*
* @see http://handlebarsjs.com/#helpers
*/
function ucwords (str) {
return (str + '').replace(/^([a-z])|\s+([a-z])/g, function ($1) {
return $1.toUpperCase();
});
}
/**
* Uppercase words
*/
Handlebars.registerHelper('ucwords', function (str) {
return ucwords(str);
});
/**
* Split snake case into words
*/
Handlebars.registerHelper('splitSnakeCase', function (str) {
return str.replace(/_/g, ' ');
});