Class: StringUtil

StringUtil

Utilities for working with strings.

Constructor

new StringUtil()

Methods

(static) camelCase(str) → {string}

Returns a string in camelCase.
Parameters:
Name Type
str string
Returns:
Type
string

(static) cutStr(str, maxLength, ellipsis) → {string}

Returns a string cut to the specified length. If the character at the cut location is a not a letter/number, it is trimmed.
Parameters:
Name Type
str string
maxLength number
ellipsis boolean
Returns:
Type
string

(static) cutStrAtWords(str, maxLength, ellipsis) → {string}

Returns a string cut to the specified length, but adjusted accordingly to never split a word. If the character at the cut location is a not a letter/number, it is trimmed.
Parameters:
Name Type
str string
maxLength number
ellipsis boolean
Returns:
Type
string

(static) cutStrAtWordsReverse(str, maxLength, ellipsis) → {string}

Returns a string cut to the specified length from its end to its beginning, but adjusted accordingly to never split a word. If the character at the cut location is not a letter/number, it is trimmed.
Parameters:
Name Type
str string
maxLength number
ellipsis boolean
Returns:
Type
string

(static) cutStrReverse(str, maxLength, ellipsis) → {string}

Returns a string cut to the specified length from its end to its beginning. If the character at the cut location is not a letter/number, it is trimmed.
Parameters:
Name Type
str string
maxLength number
ellipsis boolean
Returns:
Type
string

(static) firstLettersUpper(str) → {string}

Returns a string where every word's first letter is uppercase.
Parameters:
Name Type
str string
Returns:
Type
string

(static) firstLetterUpper(str) → {string}

Returns a string where the first letter is uppercase.
Parameters:
Name Type
str string
Returns:
Type
string

(static) htmlEntitiesToUnicode(str) → {string}

Returns a string with HTML entities converted to uncode. HTML <= 4 entities are supported (http://en.wikipedia.org/wiki/List_of_XML_and_HTML_character_entity_references).
Parameters:
Name Type
str string
Returns:
Type
string

(static) kebabCase(str) → {string}

Returns a string in kebab-case.
Parameters:
Name Type
str string
Returns:
Type
string

(static) numberTense(num) → {string}

Returns a string with your number and it's tense added (i.e. 1st, 2nd, 3rd).
Parameters:
Name Type
num number
Throws:
The 'numberTense' method expects a number.
Type
Error
Returns:
Type
string

(static) parseMath(str) → {number}

Parses string as mathematical equation. Supports addition, subtraction, division, and multiplication. Parentheses and exponents are not supported.
Parameters:
Name Type
str string
Throws:
  • The 'parseMath' method does not accept parentheses, spaces, or letters.
    Type
    Error
  • Your 'parseMath' argument has two consecutive signs.
    Type
    Error
Returns:
Type
number

(static) pascalCase(str) → {string}

Returns a string in PascalCase.
Parameters:
Name Type
str string
Returns:
Type
string

(static) readableNumber(num) → {string}

Converts a number to a readable string (by adding commas). A NaN value is returned as 0. Thanks to stackoverflow.com for the initial regex.
Parameters:
Name Type
num string
Throws:
The 'readableNumber' method expects a number.
Type
Error
Returns:
Type
string

(static) snakeCase(str) → {string}

Returns a string in snake_case.
Parameters:
Name Type
str string
Returns:
Type
string

(static) trim(str) → {string}

Returns a string where trailing white space at the beginning and end is removed.
Parameters:
Name Type
str string
Returns:
Type
string

(static) trimLeft(str) → {string}

Returns a string where trailing white space at the beginning is removed.
Parameters:
Name Type
str string
Returns:
Type
string

(static) trimRight(str) → {string}

Returns a string where trailing white space at the end is removed.
Parameters:
Name Type
str string
Returns:
Type
string

(static) wordCount(str) → {number}

Returns the number of words in a string.
Parameters:
Name Type
str string
Returns:
Type
number