분류
javascript
Javascript 30초 Snippet - String : toKebabCase
본문
문자열을 케밥 케이스로 변환합니다.
https://github.com/30-seconds/30-seconds-of-code#bytesize
문자열을 단어로 나누고 정규 표현식을 사용하여 구분 기호로 추가하여 결합하십시오.
const toKebabCase = str => str && str .match(/[A-Z]{2,}(?=[A-Z][a-z]+[0-9]*|\b)|[A-Z]?[a-z]+[0-9]*|[A-Z]|[0-9]+/g) .map(x => x.toLowerCase()) .join('-');
ex)
toKebabCase('camelCase'); // 'camel-case' toKebabCase('some text'); // 'some-text' toKebabCase('some-mixed_string With spaces_underscores-and-hyphens'); // 'some-mixed-string-with-spaces-underscores-and-hyphens' toKebabCase('AllThe-small Things'); // "all-the-small-things" toKebabCase('IAmListeningToFMWhileLoadingDifferentURLOnMyBrowserAndAlsoEditingSomeXMLAndHTML'); // "i-am-listening-to-fm-while-loading-different-url-on-my-browser-and-also-editing-xml-and-html"
- 이전글Javascript 30초 Snippet - String : toSnakeCase 19.11.25
- 다음글Javascript 30초 Snippet - String : toCamelCase 19.11.25