diff --git a/README.md b/README.md index 1a47e933c..c8a3469be 100644 --- a/README.md +++ b/README.md @@ -142,9 +142,11 @@ * [`countVowels`](#countvowels) * [`escapeRegExp`](#escaperegexp) * [`fromCamelCase`](#fromcamelcase) +* [`repeatString`](#repeatstring) * [`reverseString`](#reversestring) * [`sortCharactersInString`](#sortcharactersinstring) * [`toCamelCase`](#tocamelcase) +* [`toKebabCase`](#tokebabcase) * [`truncateString`](#truncatestring) * [`words`](#words) @@ -167,10 +169,6 @@ * [`UUIDGenerator`](#uuidgenerator) * [`validateNumber`](#validatenumber) -### _Uncategorized_ -* [`repeatString`](#repeatstring) -* [`toKebabCase`](#tokebabcase) - ## Adapter ### call @@ -1961,6 +1959,22 @@ const fromCamelCase = (str, separator = '_') => [⬆ back to top](#table-of-contents) +### 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) + ### reverseString Reverses a string. @@ -2006,6 +2020,25 @@ const toCamelCase = str => [⬆ 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) + ### truncateString Truncates a string up to a specified length. @@ -2293,42 +2326,6 @@ 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 9e3aebd82..bcb9d5685 100644 --- a/docs/index.html +++ b/docs/index.html @@ -181,9 +181,11 @@ countVowels escapeRegExp fromCamelCase +repeatString reverseString sortCharactersInString toCamelCase +toKebabCase truncateString words @@ -206,10 +208,6 @@ 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.

@@ -1225,6 +1223,15 @@ Omit the second argument to use a default separator of _.

// fromCamelCase('someLabelThatNeedsToBeCamelized', '-') -> 'some-label-that-needs-to-be-camelized' // fromCamelCase('someJavascriptProperty', '_') -> 'some_javascript_property' +

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'
+

reverseString

Reverses a string.

Use split('') and Array.reverse() to reverse the order of the characters in the string. @@ -1249,6 +1256,19 @@ Combine characters to get a string using join('').

// toCamelCase("some-javascript-property") -> 'someJavascriptProperty' // toCamelCase("some-mixed_string with spaces_underscores-and-hyphens") -> 'someMixedStringWithSpacesUnderscoresAndHyphens' +

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"
+

truncateString

Truncates a string up to a specified length.

Determine if the string's length is greater than num. @@ -1407,29 +1427,6 @@ 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"
-