new BasicFormatterManager(formatterMap)
Basic Formatter Manager that looks for strings in { } and uses the value inside the
{ } as a key to look for both a formatter and a value in the valuesMap when formatting.
This object will call the formmatter defined by the value in the { }, and take the formatted
results and place them where the { } was.
Parameters:
Name | Type | Description |
---|---|---|
formatterMap |
Object.<string, Formatter> | Map of formatters where the key is the id of the formatter (what will match in the { }) and the value is the Formatter object that implements .format(value) and returns a string |
- Implements:
- Source:
Example
var string = "Hello {user}, how are you?";
var bfm = new BasicFormmatterManager(new DefaultFormmatter());
var output = bfm.format(string, { user : "Haebin"} );
// output: "Hello Haebin, how are you?"
Methods
addFormatters(formatterMap)
Adds formatters (any object that has .format(string) and returns a string)
Parameters:
Name | Type | Description |
---|---|---|
formatterMap |
Object.<string, Formatter> | Map of formatters where the key is the id of the formatter (what will match in the { }) and the value is the Formatter object that implements .format(value) and returns a string |
- Implements:
- Source:
format(string, valuesMap) → {String}
Formats everything in the passed in string.
This does so by looking for any {id} in the string, where id is some text, and matching
the id to an id the formatterMap map and valuesMap.
The formatter found by the id is called using the value found in the valuesMap
Parameters:
Name | Type | Description |
---|---|---|
string |
String | The string to format that contatins N number of {someString} |
valuesMap |
Object.<string, Object> | The map that contains values where the key is equal to someString |
- Implements:
- Source:
Returns:
A new string with all the values formatted and replaced
- Type
- String
getFormatter(formatterId) → {Formatter}
Returns the formatter stored under the formatterId
Parameters:
Name | Type | Description |
---|---|---|
formatterId |
String | The Id of the formatter to return |
- Implements:
- Source:
Returns:
The formatter, null if not found;
- Type
- Formatter