sigil88
10/26/2017 - 2:05 PM

JS - split camel case into normal text

  	// convert camelcase labels (from data) to normal

	function convertFromCamelCase(string) {
	    return string
        // insert a space between lower & upper
        .replace(/([a-z])([A-Z])/g, '$1 $2')
        // space before last upper in a sequence followed by lower
        .replace(/\b([A-Z]+)([A-Z])([a-z])/, '$1 $2$3')
        // uppercase the first character
        .replace(/^./, function(str){ return str.toUpperCase(); })
	}