Travis build: 215

This commit is contained in:
Travis CI
2017-12-23 22:05:28 +00:00
parent 340f3d1f91
commit 33ab9be529
2 changed files with 29 additions and 0 deletions

View File

@ -147,6 +147,7 @@
* [`sortCharactersInString`](#sortcharactersinstring)
* [`toCamelCase`](#tocamelcase)
* [`toKebabCase`](#tokebabcase)
* [`toSnakeCase`](#tosnakecase)
* [`truncateString`](#truncatestring)
* [`words`](#words)
@ -2039,6 +2040,23 @@ const toKebabCase = str => {
[⬆ back to top](#table-of-contents)
### 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'
```
[⬆ back to top](#table-of-contents)
### truncateString
Truncates a string up to a specified length.