Namespace

DuString

DuString

JavaScript String related methods

View Source DuAEF_DuGR_api.jsxinc, line 6205

Methods

# static args(string, args) → {string}

Replaces all occurences of "{#}" in the string by the args.
Parameters:
Name Type Description
string string The original string
args Array.<string> | string The arguments

View Source DuAEF_DuGR_api.jsxinc, line 6264

The new string
string

# static capitalize(text) → {string}

Sets the first character of the text to be capital case if it's a letter.
Note that the string is left trimmed first: any leading white space is removed.
Parameters:
Name Type Description
text string The source text

View Source DuAEF_DuGR_api.jsxinc, line 6441

The new text
string

# static chunk(str, subStringLength) → {Array.<string>}

Splits the string into same-length substrings.
Parameters:
Name Type Description
str string The string to split
subStringLength int The length of the substrings

View Source DuAEF_DuGR_api.jsxinc, line 6498

The array of strings. The last one may be shorter than subStringLength if the original string length is not a multiple of it.
Array.<string>

# static contains(str, subStrs) → {boolean}

Checks if the string contains one of the substrings
Parameters:
Name Type Description
str string The string to check
subStrs string | Array.<string> | DuList.<string> The substrings to look for

View Source DuAEF_DuGR_api.jsxinc, line 6522

boolean

# 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

View Source DuAEF_DuGR_api.jsxinc, line 6285

Whether the string ends with the given suffix or not
bool

# static fromSize(size) → {string}

Converts a size in Bytes to a human-readable string with a fitting unit automatically chosen
Note that the conversion uses 1024 Bytes per kB.
Parameters:
Name Type Description
size int The size in Bytes

View Source DuAEF_DuGR_api.jsxinc, line 6412

The stringified size
string

# 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

View Source DuAEF_DuGR_api.jsxinc, line 6392

The trimmed string
String

# static generateUnique(newString, stringList, incrementopt, isFileopt) → {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
isFile boolean <optional>
false when generating name for files, setting this to true will add the increment before the extension

View Source DuAEF_DuGR_api.jsxinc, line 6308

The unique string, with a new number at the end if needed.
string

# static indentation(str) → {int}

Counts the spaces at the beginning of the line
Parameters:
Name Type Description
str string The string

View Source DuAEF_DuGR_api.jsxinc, line 6536

int

# static isFloat(str) → {boolean}

Checks if this string represents a float (strict, the string must include a ".")
Parameters:
Name Type Description
str string The string

View Source DuAEF_DuGR_api.jsxinc, line 6562

boolean

# static isIndented(str) → {bool}

Checks if the string is indented (starts with a space or tab)
Parameters:
Name Type Description
str string The string to test

View Source DuAEF_DuGR_api.jsxinc, line 6552

bool

# static isInt(str) → {boolean}

Checks if this string represents an integer
Parameters:
Name Type Description
str string The string

View Source DuAEF_DuGR_api.jsxinc, line 6572

boolean

# static isNumber(str) → {boolean}

Checks if this string represents a number (int or float)
Parameters:
Name Type Description
str string The string

View Source DuAEF_DuGR_api.jsxinc, line 6582

boolean

# static leftTrim(str) → {String}

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

View Source DuAEF_DuGR_api.jsxinc, line 6374

The trimmed string
String

# static match(item, query, caseSensitiveopt) → {float}

Caculates the score of a string against a query, using Duduf's fuzzy-search.jsxinc
Parameters:
Name Type Attributes Default Description
item string The string to test
query string The string to search
caseSensitive bool <optional>
false Whether to check the case or not

View Source DuAEF_DuGR_api.jsxinc, line 6471

The score, a positive value.
- 0: no match
- 1: perfect match
- >1: the lower the score, the better the match
float

# static occurences(string, item) → {int}

Counts the number of occurences of item in string
Parameters:
Name Type Description
string string The string where to count
item string the string to search

View Source DuAEF_DuGR_api.jsxinc, line 6214

the number of occurences
int

# 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.

View Source DuAEF_DuGR_api.jsxinc, line 6228

The resulting boolean
boolean

# 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.

View Source DuAEF_DuGR_api.jsxinc, line 6251

The new string
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

View Source DuAEF_DuGR_api.jsxinc, line 6383

The trimmed string
String

# static split(str, separators) → {Array.<string>}

Same as JS String.split except that it works with a list of separators too
Parameters:
Name Type Description
str string The string to split
separators string | Array.<string> | DuList.<string> The separator(s)

View Source DuAEF_DuGR_api.jsxinc, line 6481

The array of strings.
Array.<string>

# static startsWith(str, suffix) → {bool}

Checks if a string starts with a given prefix
Parameters:
Name Type Description
str string The string to check
suffix string The suffix

View Source DuAEF_DuGR_api.jsxinc, line 6296

Whether the string ends with the given suffix or not
bool

# static toCamelCase(text) → {string}

Generates a camel case text from a snake case or standard one
Parameters:
Name Type Description
text string The source text

View Source DuAEF_DuGR_api.jsxinc, line 6425

The camelCase version of the text
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

View Source DuAEF_DuGR_api.jsxinc, line 6364

The trimmed string
String

# static trimNumbers(str) → {String}

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

View Source DuAEF_DuGR_api.jsxinc, line 6402

The trimmed string
String

# static unCapitalize(text) → {string}

Sets the first character of the text to be lower case if it's a letter.
Note that the string is left trimmed first: any leading white space is removed.
Parameters:
Name Type Description
text string The source text

View Source DuAEF_DuGR_api.jsxinc, line 6454

The new text
string