StringUtils API
Utilities functions related to string manipulation
Format a string by replacing placeholder symbols with passed in arguments.
Example: var formatted = StringUtils.format("Hello {0}", "World");
-
str
string The base string
Returns string Formatted string
Splits the text by new line characters and returns an array of lines
-
text
string
Returns a line number corresponding to an offset in some text. The text can be specified as a single string or as an array of strings that correspond to the lines of the string.
Specify the text in lines when repeatedly calling the function on the same text in a loop. Use getLines() to divide the text into lines, then repeatedly call this function to compute a line number from the offset.
-
textOrLines
(string | Array<string>) string or array of lines from which to compute the line number from the offset -
offset
number
Returns number line number
Returns true if the given string starts with the given prefix.
Returns Boolean
Returns true if the given string ends with the given suffix.
Return an escaped path or URL string that can be broken near path separators.
-
url
string the path or URL to format
Returns string the formatted path or URL
Converts number of bytes into human readable format. If param bytes is negative it returns the number without any changes.
-
bytes
number Number of bytes to convert -
precision
number Number of digits after the decimal separator
Returns string
Truncate text to specified length.
Returns string? Returns truncated text only if it was changed
Computes a 32bit hash from the given string Taken from http://stackoverflow.com/questions/7616461/generate-a-hash-from-string-in-javascript-jquery
-
str
string The string for which hash is to be computed
Returns number The 32-bit hash
Generates a random nonce string of the specified length.
!!!Should not be used for crypto secure workflows.!!!
-
stringLength
number The length of the nonce in bytes. default 10. (optional, default10
) -
prefix
string? optional prefix (optional, default""
)
Returns string The randomly generated nonce.