Class Index | File Index

## Classes

- _global_
- comb
- comb.array
- comb.characters
- comb.collections
- comb.collections.AnderssonTree
- comb.collections.AVLTree
- comb.collections.BinaryTree
- comb.collections.Collection
- comb.collections.HashTable
- comb.collections.Heap
- comb.collections.Iterable
- comb.collections.MaxHeap
- comb.collections.MinHeap
- comb.collections.Pool
- comb.collections.PriorityQueue
- comb.collections.Queue
- comb.collections.RedBlackTree
- comb.collections.Stack
- comb.collections.Tree
- comb.date
- comb.logging
- comb.logging.appenders
- comb.logging.appenders.Appender
- comb.logging.appenders.ConsoleAppender
- comb.logging.appenders.FileAppender
- comb.logging.appenders.JSONAppender
- comb.logging.appenders.RollingFileAppender
- comb.logging.BasicConfigurator
- comb.logging.Level
- comb.logging.Logger
- comb.logging.PropertyConfigurator
- comb.number
- comb.plugins
- comb.plugins.Broadcaster
- comb.plugins.Middleware
- comb.Promise
- comb.PromiseList
- comb.regexp
- comb.string

# Namespace comb.string

String utilities
Defined in: string.js.

Namespace Summary
Constructor Attributes | Constructor Name and Description
--- | ---
| comb.string

Method Summary
Method Attributes | Method Name and Description
--- | ---
<static> | comb.string.format(str, obj) Formats a string with the specified format
<static> | comb.string.multiply(str, times) Returns a string duplicated n times;
<static> | comb.string.pad(string, length, ch, end) Pads a string
<static> | comb.string.style(str, styles) Styles a string according to the specified styles.
<static> | comb.string.toArray(str, delimeter) Converts a string to an array
<static> | comb.string.truncate(string, length, end) Truncates a string to the specified length.

Namespace Detail
comb.string
Method Detail
<static> {String} comb.string.format(str, obj)
Formats a string with the specified format

     var format = comb.string.format;

     format("%s, %s", ["Hello", "World"]) => "Hello, World";
     format("%[ 10]s, %[- 10]s", ["Hello", "World"])
         => "     Hello, World     ";
     format("%-!10s, %#10s, %10s and %-10s",
                             "apple", "orange", "bananas", "watermelons")
         => "apple!!!!!, ####orange,    bananas and watermelon"
     format("%+d, %+d, %10d, %-10d, %-+#10d, %10d",
                             1,-2, 1, 2, 3, 100000000000)
         => "+1, -2, 0000000001, 2000000000, +3########, 1000000000"
     format("%[h:mm a]D", [date]) => 7:32 PM - local -
     format("%[h:mm a]Z", [date]) => 12:32 PM - UTC
     //When using object formats they must be in an array otherwise
     //format will try to interpolate the properties into the string.
     format("%j", [{a : "b"}])
         => '{"a":"b"}'
     format("%1j, %4j", [{a : "b"}, {a : "b"}])
         => '{\n "a": "b"\n},\n{\n    "a": "b"\n}'
     format("{hello}, {world}", {hello : "Hello", world : "World")
         => "Hello, World";
     format({[-s10]apple}, {[%#10]orange}, {[10]banana} and {[-10]watermelons}",
                         {
                             apple : "apple",
                             orange : "orange",
                             banana : "bananas",
                             watermelons : "watermelons"
           });
         => applesssss, ####orange,    bananas and watermelon

Parameters:
{String} str
  the string to format, if you want to use a spacing character as padding (other than \\s) then put your format in brackets.
  1. String Formats %[options]s
  - - : left justified
  - Char : padding character Excludes d,j,s
  - Number : width
  2. Number Formats %[options]d
  - - : left justified
  - + : signed number
  - Char : padding character Excludes d,j,s
  - Number : width
  3. Object Formats %[options]j
  - Number : spacing for object properties.
{Object|Array|Arguments...} obj
  the parameters to replace in the string if an array is passed then the array is used sequentially if an object is passed then the object keys are used if a variable number of args are passed then they are used like an array

Returns:
  {String} the formatted string

<static> comb.string.multiply(str, times)
Returns a string duplicated n times;

    comb.string.multiply("HELLO", 5) => "HELLOHELLOHELLOHELLOHELLO"

Parameters:
str
times

<static> {String} comb.string.pad(string, length, ch, end)
Pads a string

    comb.string.pad("STR", 5, " ", true) => "STR  "
    comb.string.pad("STR", 5, "$") => "$$STR"

Parameters:
{String} string
  the string to pad
{Number} length
  the length of the string when padded
{String} ch Optional, Default: " "
  character to pad the string with
{Boolean} end Optional, Default: false
  if true then the padding is added to the end

Returns:
  {String} the padded string

<static> comb.string.style(str, styles)
Styles a string according to the specified styles.

    //style a string red
    comb.string.style('myStr', 'red');
    //style a string red and bold
    comb.string.style('myStr', ['red', bold]);

Parameters:
{String} str
  The string to style.
{String|Array} styles
  the style or styles to apply to a string. options include :
  - bold
  - bright
  - italic
  - underline
  - inverse
  - crossedOut
  - blink
  - red
  - green
  - yellow
  - blue
  - magenta
  - cyan
  - white
  - redBackground
  - greenBackground
  - yellowBackground
  - blueBackground
  - magentaBackground
  - cyanBackground
  - whiteBackground
  - grey
  - black

<static> comb.string.toArray(str, delimeter)
Converts a string to an array

    comb.string.toArray("a|b|c|d", "|") => ["a","b","c","d"]
    comb.string.toArray("a", "|") => ["a"]
    comb.string.toArray("", "|") => []

Parameters:
{String} str
  the string to parse
{String} delimeter
  the delimeter to use

<static> {String} comb.string.truncate(string, length, end)
Truncates a string to the specified length.

    //from the beginning
    comb.string.truncate("abcdefg", 3) => "abc";
    //from the end
    comb.string.truncate("abcdefg", 3,true) => "efg"
    //omit the length
    comb.string.truncate("abcdefg") => "abcdefg"

Parameters:
{String} string
  the string to truncate
{Number} length Optional, Default: -1
  the max length of the string, if the string is shorter than the length then the string is returned.
{Boolean} end Optional, Default: false
  truncate starting at the end of the string

Returns:
  {String} the truncated string.

Documentation generated by JsDoc Toolkit 2.4.0 on Tue Oct 25 2011 13:20:07 GMT-0500 (CDT)