Merge pull request #321 from Chalarangelo/Chalarangelo-snakeCase
[FEATURE] Add toSnakeCase
This commit is contained in:
14
snippets/toSnakeCase.md
Normal file
14
snippets/toSnakeCase.md
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
### toSnakeCase
|
||||||
|
|
||||||
|
Converts a string to snakecase.
|
||||||
|
|
||||||
|
Use `replace()` to add underscores before capital letters, convert `toLowerCase()`, then `replace()` hyphens and spaces with underscores.
|
||||||
|
|
||||||
|
```js
|
||||||
|
const toSnakeCase = str =>
|
||||||
|
str.replace(/(\w)([A-Z])/g, '$1_$2').replace(/[\s-_]+/g, '_').toLowerCase();
|
||||||
|
// toSnakeCase("camelCase") -> 'camel_case'
|
||||||
|
// toSnakeCase("some text") -> 'some_text'
|
||||||
|
// toSnakeCase("some-javascript-property") -> 'some_javascript_property'
|
||||||
|
// toSnakeCase("some-mixed_string With spaces_underscores-and-hyphens") -> 'some_mixed_string_with_spaces_underscores_and_hyphens'
|
||||||
|
```
|
||||||
@@ -123,6 +123,7 @@ toDecimalMark:utility
|
|||||||
toEnglishDate:date
|
toEnglishDate:date
|
||||||
toKebabCase:string
|
toKebabCase:string
|
||||||
toOrdinalSuffix:utility
|
toOrdinalSuffix:utility
|
||||||
|
toSnakeCase:string
|
||||||
truncateString:string
|
truncateString:string
|
||||||
truthCheckCollection:object
|
truthCheckCollection:object
|
||||||
union:array
|
union:array
|
||||||
|
|||||||
Reference in New Issue
Block a user