fixed issue described in pull request

checks if the uppercase charcater is preceded by another character
This commit is contained in:
Elder Henrique Souza
2017-12-22 15:55:58 -02:00
committed by GitHub
parent 3efb63fa9f
commit a35ffe7ec2

View File

@ -6,7 +6,7 @@ Use `replace()` to add underscores before capital letters, convert `toLowerCase(
```js
const toSnakeCase = str =>
str.replace(/[A-Z]/g, (match, p1, p2, offset) => '_' + match).toLowerCase().replace(/[\s-]+/g,'_');
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'