Class: StringUtil

StringUtil

Utilities methods for Strings used internally. It is static and should not be initiated.

Static Methods

  • (static) exports.trim(str) [source]

  • Trim the string
    Parameter Type Description
    str String
    Returns:
    String:
  • (static) exports.splitWords(chr) [source]

  • Split string by specified char
    Parameter Type Description
    chr String char to split
    Returns:
    Array.<String>:
  • (static) exports.stringLength(text, font) [source]

  • Gets size in pixel of the text with a certain font.
    Parameter Type Description
    text String text to measure
    font String font of the text, same as the CSS font.
    Returns:
    Size:
  • (static) exports.splitContent(content, textLength, wrapWidth) [source]

  • Split content by wrapLength 根据长度分割文本
    Parameter Type Description
    content String text to split
    textLength Number width of the text, provided to prevent expensive repeated text measuring
    wrapWidth Number width to wrap
    Returns:
    Array.<String>:
  • (static) exports.replaceVariable(str, props) [source]

  • Replace variables wrapped by square brackets ({foo}) with actual values in props.
    // will returns 'John is awesome'
        var actual = replaceVariable('{foo} is awesome', {'foo' : 'John'});
    Parameter Type Description
    str String string to replace
    props Object variable value properties
    Returns:
    String:
  • (static) exports.getAlignPoint(size, horizontalAlignment, verticalAlignment) [source]

  • Gets text's align point according to the horizontalAlignment and verticalAlignment
    Parameter Type Description
    size Size text size
    horizontalAlignment String horizontalAlignment: left/middle/right
    verticalAlignment String verticalAlignment: top/middle/bottom
    Returns:
    Point:
  • (static) exports.getFont(style) [source]

  • Returns CSS Font from a symbol with text styles.
    Parameter Type Description
    style Object symbol with text styles
    Returns:
    String: CSS Font String
  • (static) exports.splitTextToRow(text, style) [source]

  • Split a text to multiple rows according to the style.
    Parameter Type Description
    text String text to split
    style Object text style
    Returns:
    Array.<Object>: the object's structure: {rowNum: rowNum, textSize: textSize, rows: textRows}