Created
December 3, 2017 04:22
-
-
Save xerosai/f570ba82a3d0f6ee288c38e5be59ddad to your computer and use it in GitHub Desktop.
Starting point for title case text conversion filter for VueJS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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