Module: util/format

Format helpers.

Methods


<static> clean(text)

Remove multiple white-spaces, tab, form feed and line feed from a text.
Parameters:
Name Type Description
text string Text to clean.
Example
var format = mbot.load('util/format');
format.clean(' a  b\t\t\nc\n d   \n\ne  ');
// 'a b c d e'

<static> list(ii)

Format a list with prefix, header and trailer.
Parameters:
Name Type Description
ii Input Information
Properties
Name Type Argument Description
prefix string <optional>
Records prefix (default '> ')
header string <optional>
Header text
list Array.<string> Text array
footer string <optional>
Footer text
Example
var format = mbot.load('util/format');
format.list({
    header: 'result:',
    list: ['first', 'record #2'],
    footer: '(2 results)'
});
// result:
// > first
// > record #2
// (2 results)

<static> string(str, args)

Format string placeholders with sequential arguments.
Parameters:
Name Type Description
str string Template string.
args Array.<Object>
Example
var format = mbot.load('util/format');
format.string('foo {0}: {1}', 'bar', 42);
// foo bar: 42