-
-
Notifications
You must be signed in to change notification settings - Fork 129
StringUtils
brackets.getModule("utils/StringUtils")
Utilities functions related to string manipulation
-
utils/StringUtils
-
.format(str, Arguments) ⇒
string
-
.getLines(text) ⇒
Array.<string>
-
.offsetToLineNum(textOrLines, offset) ⇒
number
-
.startsWith(str, prefix) ⇒
Boolean
- .endsWith(str, suffix)
-
.breakableUrl(url) ⇒
string
-
.prettyPrintBytes(bytes, precision) ⇒
string
-
.truncate(str, len) ⇒
string
-
.hashCode(str) ⇒
number
-
.randomString(stringLength, [prefix]) ⇒
string
-
.format(str, Arguments) ⇒
Format a string by replacing placeholder symbols with passed in arguments.
Example: var formatted = StringUtils.format("Hello {0}", "World");
Kind: inner method of utils/StringUtils
Returns: string
- Formatted string
Param | Type | Description |
---|---|---|
str | string |
The base string |
Arguments | rest |
to be substituted into the string |
Splits the text by new line characters and returns an array of lines
Kind: inner method of utils/StringUtils
Returns: Array.<string>
- lines
Param | Type |
---|---|
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.
Kind: inner method of utils/StringUtils
Returns: number
- line number
Param | Type | Description |
---|---|---|
textOrLines |
string | Array.<string>
|
string or array of lines from which to compute the line number from the offset |
offset | number |
Returns true if the given string starts with the given prefix.
Kind: inner method of utils/StringUtils
Param | Type |
---|---|
str | String |
prefix | String |
Returns true if the given string ends with the given suffix.
Kind: inner method of utils/StringUtils
Param | Type |
---|---|
str | string |
suffix | string |
Return an escaped path or URL string that can be broken near path separators.
Kind: inner method of utils/StringUtils
Returns: string
- the formatted path or URL
Param | Type | Description |
---|---|---|
url | string |
the path or URL to format |
Converts number of bytes into human readable format. If param bytes is negative it returns the number without any changes.
Kind: inner method of utils/StringUtils
Param | Type | Description |
---|---|---|
bytes | number |
Number of bytes to convert |
precision | number |
Number of digits after the decimal separator |
Truncate text to specified length.
Kind: inner method of utils/StringUtils
Returns: string
- Returns truncated text only if it was changed
Param | Type | Description |
---|---|---|
str | string |
Text to be truncated. |
len | number |
Length to which text should be truncated |
Computes a 32bit hash from the given string Taken from http://stackoverflow.com/questions/7616461/generate-a-hash-from-string-in-javascript-jquery
Kind: inner method of utils/StringUtils
Returns: number
- The 32-bit hash
Cc: wiki attribution: esmiralha
Param | Type | Description |
---|---|---|
str | string |
The string for which hash is to be computed |
Generates a random nonce string of the specified length.
!!!Should not be used for crypto secure workflows.!!!
Kind: inner method of utils/StringUtils
Returns: string
- - The randomly generated nonce.
Param | Type | Default | Description |
---|---|---|---|
stringLength | number |
10 |
The length of the nonce in bytes. default 10. |
[prefix] | string |
optional prefix |