update toSnakeCase.md
This commit is contained in:
@ -6,7 +6,12 @@ Use `replace()` to add underscores before capital letters, convert `toLowerCase(
|
||||
|
||||
```js
|
||||
const toSnakeCase = str =>
|
||||
str.replace(/(\w)([A-Z])/g, '$1_$2').replace(/[\s-_]+/g, '_').toLowerCase();
|
||||
let regex = rx = /[A-Z]{2,}(?=[A-Z][a-z]+[0-9]*|\b)|[A-Z]?[a-z]+[0-9]*|[A-Z]|[0-9]+/g;
|
||||
let arr = str.match(regex);
|
||||
arr = arr.forEach(x =>{
|
||||
return s.toLowerCase();
|
||||
});
|
||||
return arr.join('_')
|
||||
// toSnakeCase("camelCase") -> 'camel_case'
|
||||
// toSnakeCase("some text") -> 'some_text'
|
||||
// toSnakeCase("some-javascript-property") -> 'some_javascript_property'
|
||||
|
||||
Reference in New Issue
Block a user