Basic sprintf support (#1965)

Implement optional format strings for valueMetadata which allows
developers to use c-style sprintf formatters as desired. Fixes #1562
This commit is contained in:
Pete Richards
2018-06-29 15:52:15 -07:00
committed by Andrew Henry
parent 29de11167f
commit 013eba744d
6 changed files with 20 additions and 4 deletions

View File

@ -21,9 +21,11 @@
*****************************************************************************/
define([
'lodash'
'lodash',
'printj'
], function (
_
_,
printj
) {
// TODO: needs reference to formatService;
@ -71,6 +73,14 @@ define([
return Number(string);
}.bind(this);
}
// Check for formatString support once instead of per format call.
if (valueMetadata.formatString) {
var baseFormat = this.formatter.format;
var formatString = valueMetadata.formatString;
this.formatter.format = function (value) {
return printj.sprintf(formatString, baseFormat.call(this, value));
};
}
}
TelemetryValueFormatter.prototype.parse = function (datum) {