StringUtils
Import :
const StringUtils = brackets.getModule("utils/StringUtils")
utils/StringUtils
Utilities functions related to string manipulation
- utils/StringUtils
- .format(str, Arguments) ⇒
string
- .regexEscape(str) ⇒
string
- .jQueryIdEscape(str) ⇒
string
- .getLines(text) ⇒
Array.<string>
- .offsetToLineNum(textOrLines, offset) ⇒
number
- .startsWith(str, prefix) ⇒
Boolean
- .endsWith(str, suffix)
- .urlSort(a, b) ⇒
number
- .breakableUrl(url) ⇒
string
- .prettyPrintBytes(bytes, precision) ⇒
string
- .truncate(str, len) ⇒
string
- .hashCode(str) ⇒
number
- .randomString(stringLength, [prefix]) ⇒
string
- .isNumber(value) ⇒
boolean
- .format(str, Arguments) ⇒
utils/StringUtils.format(str, Arguments) ⇒ string
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 |
utils/StringUtils.regexEscape(str) ⇒ string
Regex escape
Kind: inner method of utils/StringUtils
Param | Type |
---|---|
str | string |
utils/StringUtils.jQueryIdEscape(str) ⇒ string
Periods (aka "dots") are allowed in HTML identifiers, but jQuery interprets them as the start of a class selector, so they need to be escaped
Kind: inner method of utils/StringUtils
Param | Type |
---|---|
str | string |
utils/StringUtils.getLines(text) ⇒ Array.<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 |
utils/StringUtils.offsetToLineNum(textOrLines, offset) ⇒ number
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 |
utils/StringUtils.startsWith(str, prefix) ⇒ Boolean
Returns true if the given string starts with the given prefix.
Kind: inner method of utils/StringUtils
Param | Type |
---|---|
str | String |
prefix | String |
utils/StringUtils.endsWith(str, suffix)
Returns true if the given string ends with the given suffix.
Kind: inner method of utils/StringUtils
Param | Type |
---|---|
str | string |
suffix | string |
utils/StringUtils.urlSort(a, b) ⇒ number
sort two urls alphabetically ensure folders appear before files on windows
Kind: inner method of utils/StringUtils
Param | Type |
---|---|
a | string |
b | string |
utils/StringUtils.breakableUrl(url) ⇒ 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 |
utils/StringUtils.prettyPrintBytes(bytes, precision) ⇒ string
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 |
utils/StringUtils.truncate(str, len) ⇒ string
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 |
utils/StringUtils.hashCode(str) ⇒ number
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 |
utils/StringUtils.randomString(stringLength, [prefix]) ⇒ string
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 |
utils/StringUtils.isNumber(value) ⇒ boolean
Check if value is a valid number
Kind: inner method of utils/StringUtils
Returns: boolean
- true if value is valid number, else false
Param | Type |
---|---|
value | string |