Last active
October 31, 2022 02:01
-
-
Save codeBelt/0dbdc2e0e53c1ca35e161c946795c37e to your computer and use it in GitHub Desktop.
For Medium Article: https://medium.com/@robertsavian/javascript-case-converters-using-lodash-4f2f964091cc
This file contains hidden or 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 {camelCase, upperCase, startCase, lowerCase, kebabCase, upperFirst, snakeCase} from 'lodash'; | |
| export default class StringUtility { | |
| static toCamelCase(str) { | |
| return camelCase(str); | |
| } | |
| static toTitleCase(str) { | |
| return startCase(camelCase(str)); | |
| } | |
| static toPascalCase(str) { | |
| return startCase(camelCase(str)).replace(/ /g, ''); | |
| } | |
| static toConstantCase(str) { | |
| return upperCase(str).replace(/ /g, '_'); | |
| } | |
| static toDotCase(str) { | |
| return lowerCase(str).replace(/ /g, '.'); | |
| } | |
| static toKebabCase(str) { | |
| return kebabCase(str); | |
| } | |
| static toLowerCase(str) { | |
| return lowerCase(str).replace(/ /g, ''); | |
| } | |
| static toPathCase(str) { | |
| return lowerCase(str).replace(/ /g, '/'); | |
| } | |
| static toSnakeCase(str) { | |
| return snakeCase(str); | |
| } | |
| static toSentenceCase(str) { | |
| return upperFirst(lowerCase(str)); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment