Class WrapperParser
A parser that wraps another parser, adding functionality through uses custom functions.
When formatting, first the wrapped parser formats the data, then the formatFunction is invoked to post-process it, receiving the already formatted value and the original value as arguments.
When parsing, first the parseFunction is invoked to pre-process the value, then the wrapped parser parses it.
Example
var addTag = function(value, originalValue) {
var color;
if (originalValue != null && originalValue < 0) {
color = "red";
} else {
color = "blue";
}
return "" + value + "";
}
var removeTag = function(value) {
var array = /<\w[^>]+>([\w\,\.]+)<\/\w[^>]+>/i.exec(value);
if (!array) {
return null;
}
return array[1];
}
var numberParser = new NumberParser(2);
var parser = new WrapperParser(numberParser, addTag, removeTag);
alert(parser.format(-1.67)); //Result is -1,67
alert(parser.format(123.237)); //Result is 123,24
alert(parser.parse("1.234.567,89
")); //Result is 1234567.89
Constructor Arguments
Name |
Type |
Default |
Description |
wrappedParser |
Parser |
|
The internal parser |
formatFunction |
Function |
|
The function called to post-process data the wrapped parser will format. The received arguments are the already formatted data by the wrapped parser and the original data |
parseFunction |
Function |
|
The function called to pre-process data the wrapped parser will parse. The data is passed as function argument |
Properties
formatFunction |
The function called to post-process data the wrapped parser will format |
parseFunction |
The function called to pre-process data the wrapped parser will parse |
wrappedParser |
The internal parser |
Properties
|
formatFunction
The function called to post-process data the wrapped parser will format. The received arguments are the already formatted data by the wrapped parser and the original data |
|
parseFunction
The function called to pre-process data the wrapped parser will parse. The data is passed as function argument |
|
wrappedParser
The internal parser |