Skip to content

Commit e2c8857

Browse files
committed
Return empty string for undefined value in templateFormatString
1 parent 385b44b commit e2c8857

File tree

1 file changed

+9
-16
lines changed

1 file changed

+9
-16
lines changed

src/lib/index.js

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1182,26 +1182,19 @@ function templateFormatString(string, labels, d3locale) {
11821182
}
11831183
}
11841184

1185-
// Apply mult/div operation (if applicable)
1186-
if (value !== undefined) {
1187-
if (parsedOp === '*') value *= parsedNumber;
1188-
if (parsedOp === '/') value /= parsedNumber;
1189-
}
1190-
1191-
if (value === undefined && opts) {
1192-
if (opts.count < opts.max) {
1193-
lib.warn("Variable '" + key + "' in " + opts.name + ' could not be found!');
1194-
value = match;
1195-
}
1196-
1197-
if (opts.count === opts.max) {
1198-
lib.warn('Too many ' + opts.name + ' warnings - additional warnings will be suppressed');
1199-
}
1185+
if (value === undefined) {
1186+
const { count, max, name } = opts;
1187+
if (count < max) lib.warn(`Variable '${key}' in ${name} could not be found!`);
1188+
if (count === max) lib.warn(`Too many '${name}' warnings - additional warnings will be suppressed`);
12001189
opts.count++;
12011190

1202-
return match;
1191+
// TODO: Make return valuable configurable with a reasonable default (like 'N/A')
1192+
return '';
12031193
}
12041194

1195+
if (parsedOp === '*') value *= parsedNumber;
1196+
if (parsedOp === '/') value /= parsedNumber;
1197+
12051198
if (format) {
12061199
var fmt;
12071200
if (format[0] === ':') {

0 commit comments

Comments
 (0)