DuAEF.DuJS.String

JavaScript String related methods

Methods

static endsWith(str, suffix) → {bool}

Checks if a string ends with a given suffix
Parameters:
Name Type Description
str string The string to check
suffix string The suffix
Returns:
bool - Wether the string ends with the given suffix or not

static fullTrim(str) → {String}

Returns a copy of the string without leading and trailing white spaces, and without any new line, leaving only standard spaces.
Parameters:
Name Type Description
str string The string to trim
Returns:
String - The trimmed string

static generateUnique(newString, stringList, incrementopt) → {string}

Generates a new unique string (numbered)
Parameters:
Name Type Attributes Default Description
newString string The wanted new string
stringList Array.<string> The list of strings where the new one must be generateUnique
increment boolean <optional>
true true to automatically increment the new name if it already ends with a digit
Returns:
string - The unique string, with a new number at the end if needed.

static leftTrim(str) → {String}

Returns a copy of the string without leading white spaces.
Parameters:
Name Type Description
str string The string to trim
Returns:
String - The trimmed string

static parseBool(string, caseSensitiveopt) → {boolean}

Parses the string as a boolean.
The following strings are falsy:
'false', '0', '', 'null', 'undefined', 'NaN'.
Note that any string consisiting only in any number of 0 will be falsy.
Parameters:
Name Type Attributes Default Description
string string The string to parse
caseSensitive boolean <optional>
true When false, 'FALSE', 'nan', 'UNdefined'... for example will be falsy too.
Returns:
boolean - The resulting boolean

static pathJoin(partsopt, sepopt) → {String}

Join multiple paths togetther.
Parameters:
Name Type Attributes Default Description
parts Array.<string> <optional>
The parts to join togehter
sep String <optional>
/ The separator to use. If not defined, will look for the first sep in the path.
Returns:
String - The final path

static replace(string, find, replace, caseSensitiveopt) → {string}

Replaces all occurences of a substring by another and returns the new string.
Parameters:
Name Type Attributes Default Description
string string The original string
find string The substring to replace
replace string The new substring to insert
caseSensitive boolean <optional>
true Optionnal. Do a case sensitive search of substring.
Returns:
string - The new string

static rightTrim(str) → {String}

Returns a copy of the string without trailing white spaces.
Parameters:
Name Type Description
str string The string to trim
Returns:
String - The trimmed string

static trim(str) → {String}

Returns a copy of the string without leading and trailing white spaces.
Parameters:
Name Type Description
str string The string to trim
Returns:
String - The trimmed string