From f59259db0de6ece79e02d03b5800614a3e32cd0d Mon Sep 17 00:00:00 2001 From: Travis CI Date: Sat, 23 Dec 2017 19:13:32 +0000 Subject: [PATCH] Travis build: 209 --- README.md | 40 ++++++++++++++++++++++++++++++++++++++++ docs/index.html | 27 +++++++++++++++++++++++++++ tag_database | 2 ++ 3 files changed, 69 insertions(+) diff --git a/README.md b/README.md index 0caf638f1..1a47e933c 100644 --- a/README.md +++ b/README.md @@ -167,6 +167,10 @@ * [`UUIDGenerator`](#uuidgenerator) * [`validateNumber`](#validatenumber) +### _Uncategorized_ +* [`repeatString`](#repeatstring) +* [`toKebabCase`](#tokebabcase) + ## Adapter ### call @@ -2289,6 +2293,42 @@ const validateNumber = n => !isNaN(parseFloat(n)) && isFinite(n) && Number(n) == // validateNumber('10') -> true ``` +[⬆ back to top](#table-of-contents) +## _Uncategorized_ + +### repeatString + +Repeats a string n times using `String.repeat()` + +If no string is provided the default is `""` and the default number of times is 2. + +```js +const repeatString = (str="",num=2) => { + return num >= 0 ? str.repeat(num) : str; +} +// repeatString("abc",3) -> 'abcabcabc' +// repeatString("abc") -> 'abcabc' +``` + +[⬆ back to top](#table-of-contents) + +### toKebabCase + +Converts a string to [kebab case](https://en.wikipedia.org/wiki/Letter_case#Special_case_styles). +Use `replace()` to add spaces before capital letters, convert `toLowerCase()`, then `replace()` underscores and spaces with hyphens. +Also check if a string starts with a hyphen and remove it if yes. + +```js +const toKebabCase = str => { + str = str.replace(/([A-Z])/g," $1").toLowerCase().replace(/_/g,' ').replace(/-/g,' ').replace(/\s\s+/g, ' ').replace(/\s/g,'-'); + return str.startsWith('-') ? str.slice(1,str.length) : str; +} +// toKebabCase("camelCase") -> 'camel-case' +// toKebabCase("some text") -> 'some-text' +// 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" +``` + [⬆ back to top](#table-of-contents) ## Credits diff --git a/docs/index.html b/docs/index.html index ee176bf7d..9e3aebd82 100644 --- a/docs/index.html +++ b/docs/index.html @@ -206,6 +206,10 @@ UUIDGenerator validateNumber +

Uncategorized +

repeatString +toKebabCase +
 

Adapter

call

Given a key and a set of arguments, call them when given a context. Primarily useful in composition.

@@ -1403,6 +1407,29 @@ Use Number() to check if the coercion holds.

const validateNumber = n => !isNaN(parseFloat(n)) && isFinite(n) && Number(n) == n;
 // validateNumber('10') -> true
 
+

Uncategorized

+

repeatString

+

Repeats a string n times using String.repeat()

+

If no string is provided the default is "" and the default number of times is 2.

+
const repeatString = (str="",num=2) => {
+    return num >= 0 ? str.repeat(num) : str;
+}
+// repeatString("abc",3) -> 'abcabcabc'
+// repeatString("abc") -> 'abcabc'
+
+

toKebabCase

+

Converts a string to kebab case. +Use replace() to add spaces before capital letters, convert toLowerCase(), then replace() underscores and spaces with hyphens. +Also check if a string starts with a hyphen and remove it if yes.

+
const toKebabCase = str => {
+    str = str.replace(/([A-Z])/g," $1").toLowerCase().replace(/_/g,' ').replace(/-/g,' ').replace(/\s\s+/g, ' ').replace(/\s/g,'-');
+    return str.startsWith('-') ? str.slice(1,str.length) : str;
+}
+// toKebabCase("camelCase") -> 'camel-case'
+// toKebabCase("some text") -> 'some-text'
+// 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"
+