bootstrap-vue
Version:
BootstrapVue, with over 40 plugins and more than 80 custom components, provides one of the most comprehensive implementations of Bootstrap v4 components and grid system for Vue.js. With extensive and automated WAI-ARIA accessibility markup.
27 lines (25 loc) • 855 B
JavaScript
/**
* Converts a string, including strings in camelCase or snake_case, into Start Case (a variant
* of Title Case where all words start with a capital letter), it keeps original single quote
* and hyphen in the word.
*
* Copyright (c) 2017 Compass (MIT)
* https://github.com/UrbanCompass/to-start-case
* @author Zhuoyuan Zhang <https://github.com/drawyan>
* @author Wei Wang <https://github.com/onlywei>
*
*
* 'management_companies' to 'Management Companies'
* 'managementCompanies' to 'Management Companies'
* `hell's kitchen` to `Hell's Kitchen`
* `co-op` to `Co-op`
*
* @param {String} str
* @returns {String}
*/
const startCase = str =>
str
.replace(/_/g, ' ')
.replace(/([a-z])([A-Z])/g, (str, $1, $2) => $1 + ' ' + $2)
.replace(/(\s|^)(\w)/g, (str, $1, $2) => $1 + $2.toUpperCase())
export default startCase