Skip to content

Instantly share code, notes, and snippets.

@kkiernan
Last active December 6, 2021 12:34
Show Gist options
  • Save kkiernan/91298079d34f0f832054 to your computer and use it in GitHub Desktop.
Save kkiernan/91298079d34f0f832054 to your computer and use it in GitHub Desktop.
A Vue.js filter that converts snake case to title case.
/**
* Converts a snake case string to title case.
* Example: snake_case => Snake Case
*
* @param {String} str the string to convert
* @return {String}
*/
Vue.filter('snakeToTitle', function (str) {
return str.split('_').map(function (item) {
return item.charAt(0).toUpperCase() + item.substring(1);
}).join(' ');
});
@xkubow
Copy link

xkubow commented Aug 30, 2019

export function toPascalCase(stringInput) {
	return stringInput.split('_').map(_.capitalize).join('');
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment