Skip to content

Instantly share code, notes, and snippets.

@xerosai
Created December 3, 2017 04:22
Show Gist options
  • Save xerosai/f570ba82a3d0f6ee288c38e5be59ddad to your computer and use it in GitHub Desktop.
Save xerosai/f570ba82a3d0f6ee288c38e5be59ddad to your computer and use it in GitHub Desktop.
Starting point for title case text conversion filter for VueJS
import Vue from 'vue';
const SPACE_CHAR = ' ';
const TEXT_REQUIRED = 'Specify text to be converted to Title Case';
Vue.filter('convertToTitleCase', (value) => {
if (!value) return TEXT_REQUIRED;
return value.toString().split(SPACE_CHAR).map((word) => {
return word.charAt(0).toUpperCase() + word.slice(1);
}).join(SPACE_CHAR);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment