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.escapeSpecialChars(str) [source]

  • Escape special characters from string. Including: \b \t \r \v \f
    Parameter Type Description
    str String string to escape
    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.stringWidth(text, font) [source]

  • Gets width of the text with a certain font. More performant than stringLength.
    Parameter Type Description
    text String text to measure
    font String font of the text, same as the CSS font.
    Returns:
    Number:
  • (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, font) [source]

  • Split text content by dom.
    Parameter Type Description
    content String content to split
    font String font of the text, same as the CSS font.
    Returns:
    Number|Array.<String>:
    • wrapWidth - width to wrap

  • (static) exports.replaceVariable(str, props) [source]

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

  • Generate text descriptors according to symbols
    Returns:
    Object: text descriptor
  • (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, rawSize : rawSize }