From 7dee2508302e80e8ed82816a27a4b44333382034 Mon Sep 17 00:00:00 2001
From: Travis CI
Date: Sat, 23 Dec 2017 22:05:28 +0000
Subject: [PATCH] Travis build: 215
---
README.md | 18 ++++++++++++++++++
docs/index.html | 11 +++++++++++
2 files changed, 29 insertions(+)
diff --git a/README.md b/README.md
index c8a3469be..6786ca4aa 100644
--- a/README.md
+++ b/README.md
@@ -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.
diff --git a/docs/index.html b/docs/index.html
index f4427854c..9b5808ae9 100644
--- a/docs/index.html
+++ b/docs/index.html
@@ -208,6 +208,7 @@
sortCharactersInString
toCamelCase
toKebabCase
+toSnakeCase
truncateString
words
@@ -1291,6 +1292,16 @@ Also check if a string starts with a hyphen and remove it if yes.
// 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"
+
toSnakeCase
+
Converts a string to snakecase.
+
Use replace() to add underscores before capital letters, convert toLowerCase(), then replace() hyphens and spaces with underscores.
+
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'
+
truncateString
Truncates a string up to a specified length.
Determine if the string's length is greater than num.