Skip to main content

StringUtils

Import :

const StringUtils = brackets.getModule("utils/StringUtils")

utils/StringUtils

Utilities functions related to string manipulation

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

ParamTypeDescription
strstringThe base string
Argumentsrestto be substituted into the string

utils/StringUtils.regexEscape(str) ⇒ string

Regex escape

Kind: inner method of utils/StringUtils

ParamType
strstring

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

ParamType
strstring

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

ParamType
textstring

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

ParamTypeDescription
textOrLinesstring | Array.<string>string or array of lines from which to compute the line number from the offset
offsetnumber

utils/StringUtils.startsWith(str, prefix) ⇒ Boolean

Returns true if the given string starts with the given prefix.

Kind: inner method of utils/StringUtils

ParamType
strString
prefixString

utils/StringUtils.endsWith(str, suffix)

Returns true if the given string ends with the given suffix.

Kind: inner method of utils/StringUtils

ParamType
strstring
suffixstring

utils/StringUtils.urlSort(a, b) ⇒ number

sort two urls alphabetically ensure folders appear before files on windows

Kind: inner method of utils/StringUtils

ParamType
astring
bstring

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

ParamTypeDescription
urlstringthe 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

ParamTypeDescription
bytesnumberNumber of bytes to convert
precisionnumberNumber 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

ParamTypeDescription
strstringText to be truncated.
lennumberLength 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

ParamTypeDescription
strstringThe 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.

ParamTypeDefaultDescription
stringLengthnumber10The length of the nonce in bytes. default 10.
[prefix]stringoptional 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

ParamType
valuestring