From 80776131a55d034ff460dfe36800913be0ee61b2 Mon Sep 17 00:00:00 2001 From: 30secondsofcode <30secondsofcode@gmail.com> Date: Thu, 31 Oct 2019 07:39:05 +0000 Subject: [PATCH] Travis build: 189 --- README.md | 6 ++++-- snippet_data/snippetList.json | 4 ++-- snippet_data/snippets.json | 6 +++--- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 7e817f8bf..3007c4a63 100644 --- a/README.md +++ b/README.md @@ -1761,13 +1761,15 @@ byte_size('Hello World') # 11 Converts a string to camelcase. -Break the string into words and combine them capitalizing the first letter of each word, using a regexp, `title()` and `lower`. +Use `re.sub()` to replace any `-`,`_` or ` ` (space) with a space, using the regexp `r"(_|-)+"`. +Use `title()` to capitalize the first letter of each word convert the rest to lowercase. +Finally, use `replace()` to remove spaces between words. ```py import re def camel(s): - s = re.sub(r"(\s|_|-)+", " ", s).title().replace(" ", "") + s = re.sub(r"(_|-)+", " ", s).title().replace(" ", "") return s[0].lower() + s[1:] ``` diff --git a/snippet_data/snippetList.json b/snippet_data/snippetList.json index 0866a8f60..8de1a215f 100644 --- a/snippet_data/snippetList.json +++ b/snippet_data/snippetList.json @@ -114,7 +114,7 @@ "type": "snippetListing", "title": "camel", "attributes": { - "text": "Converts a string to camelcase.\n\nBreak the string into words and combine them capitalizing the first letter of each word, using a regexp, `title()` and `lower`.\n\n", + "text": "Converts a string to camelcase.\n\nUse `re.sub()` to replace any `-`,`_` or ` ` (space) with a space, using the regexp `r\"(_|-)+\"`.\nUse `title()` to capitalize the first letter of each word convert the rest to lowercase.\nFinally, use `replace()` to remove spaces between words.\n\n", "tags": [ "string", "regexp", @@ -122,7 +122,7 @@ ] }, "meta": { - "hash": "60b308cb7f28b676fb122949d04ae07af0d4e0fcb96f037b3aa3c09be9b2e7ab" + "hash": "9df97be0166e2a4a90859e878f986c0adb539ac41b85aac9c05e4dd0999155b5" } }, { diff --git a/snippet_data/snippets.json b/snippet_data/snippets.json index 2d921339e..0a1ddebfe 100644 --- a/snippet_data/snippets.json +++ b/snippet_data/snippets.json @@ -150,9 +150,9 @@ "type": "snippet", "attributes": { "fileName": "camel.md", - "text": "Converts a string to camelcase.\n\nBreak the string into words and combine them capitalizing the first letter of each word, using a regexp, `title()` and `lower`.\n\n", + "text": "Converts a string to camelcase.\n\nUse `re.sub()` to replace any `-`,`_` or ` ` (space) with a space, using the regexp `r\"(_|-)+\"`.\nUse `title()` to capitalize the first letter of each word convert the rest to lowercase.\nFinally, use `replace()` to remove spaces between words.\n\n", "codeBlocks": { - "code": "import re\n\ndef camel(s):\n s = re.sub(r\"(\\s|_|-)+\", \" \", s).title().replace(\" \", \"\")\n return s[0].lower() + s[1:]", + "code": "import re\n\ndef camel(s):\n s = re.sub(r\"(_|-)+\", \" \", s).title().replace(\" \", \"\")\n return s[0].lower() + s[1:]", "example": "camel('some_database_field_name'); # 'someDatabaseFieldName'\ncamel('Some label that needs to be camelized'); # 'someLabelThatNeedsToBeCamelized'\ncamel('some-javascript-property'); # 'someJavascriptProperty'\ncamel('some-mixed_string with spaces_underscores-and-hyphens'); # 'someMixedStringWithSpacesUnderscoresAndHyphens'" }, "tags": [ @@ -162,7 +162,7 @@ ] }, "meta": { - "hash": "60b308cb7f28b676fb122949d04ae07af0d4e0fcb96f037b3aa3c09be9b2e7ab" + "hash": "9df97be0166e2a4a90859e878f986c0adb539ac41b85aac9c05e4dd0999155b5" } }, {