Properties:
Name | Type | Description | ||||||
---|---|---|---|---|---|---|---|---|
aidsIn |
function | The String class Properties
|
Methods
(static) levenshtein(str1, str2) → {number}
Finds the Levenshtein distance between a string and another string.
Parameters:
Name | Type | Description |
---|---|---|
str1 |
string | The first string to find the distance between. |
str2 |
string | The second string. |
Returns:
The Levenshtein distance.
- Type
- number
repeat(times) → {string}
An extension of the native repeat, this one takes decimals as a parameter, and splits the string accordingly.
Parameters:
Name | Type | Description |
---|---|---|
times |
number | How many times to repeat the string. Splits string if it is a decimal. |
Returns:
The repeated string.
- Type
- string
Examples
// returns 'my catmy cat'
let str = 'my cat';
str.repeat(2);
// returns 'my catmy '
let str = 'my cat';
str.repeat(1.5);
reverse() → {string}
Reverses a string
Returns:
The reversed string.
- Type
- string
sort(sortFunctionopt) → {string}
Sorts a string by character.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
sortFunction |
CallBack |
<optional> |
(str1,str2)=>{return str1.charCodeAt(0) - str2.charCodeAt(0)} | The function to sort it with. By default, it sorts by character code. |
Returns:
The sorted string.
- Type
- string
TO_CONSTANT_CASE() → {string}
Converts the string to CONSTANT_CASE.
Returns:
The CONSTANT_CASE form of the string.
- Type
- string
Example
// returns 'my_cat'
let str = 'my cat';
str.to_snake_case();
to_seperated_case(seperatoropt) → {string}
Converts the string to a seperated case, where the seperator is defined by the user.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
seperator |
string |
<optional> |
"-" | The seperator to seperate the string with. |
Returns:
The resulting seperated form of the string.
- Type
- string
Examples
// returns 'my-cat'
let str = 'my cat';
str.to-seperated-case();
// returns 'my|cat'
let str = 'my cat';
str.to-seperated-case('|');
to_snake_case() → {string}
Converts the string to snake_case.
Returns:
The snake_case form of the string.
- Type
- string
Example
// returns 'my_cat'
let str = 'my cat';
str.to_snake_case();
toCamelCase() → {string}
Converts the string to camelCase.
Returns:
The camelCase form of the string.
- Type
- string
Example
// returns 'myCat'
let str = 'my cat';
str.toCamelCase();
ToPascalCase() → {string}
Converts the string to PascalCase.
Returns:
The PascalCase form of the string.
- Type
- string
Example
// returns 'MyCat'
let str = 'my cat';
str.ToPascalCase();
ToTitleCase() → {string}
Converts the string to a seperated case, where the seperator is defined by the user.
Returns:
The resulting Title Case form of the string.
- Type
- string
Example
// returns 'My Cat'
let str = 'my cat';
str.ToTitleCase();
words() → {Array.<string>}
Finds the words in a string, per the following regex:
javascript
/((?:^_*)?(?:[A-Z][-_A-Z]*|[^-\s_A-Z]+)(?:_*$)?)/gi
.
Returns:
The words.
- Type
- Array.<string>
Type Definitions
CallBack(str) → {*}
Parameters:
Name | Type | Description |
---|---|---|
str |
string | The string being passed |
Returns:
- Type
- *