Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions lib/tabula.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,8 @@ function tabulaFormat(items, options) {
assert.optionalArrayOfString(options.validFields, 'options.validFields');
assert.optionalBool(options.dottedLookup, 'options.dottedLookup');
assert.optionalBool(options.noAnsi, 'options.noAnsi');
assert.optionalBool(options.caseInsensitiveLookup,
'options.caseInsensitiveLookup');

if (!options.columns && items.length === 0) {
return '';
Expand Down Expand Up @@ -287,7 +289,10 @@ function tabulaFormat(items, options) {
if (options.dottedLookup) {
try {
cell = dottedLookup(o, col.lookup);
} catch (e) {}
} catch (e) {
if (options.caseInsensitiveLookup)
throw e;
}
} else {
cell = o[col.lookup];
}
Expand Down Expand Up @@ -403,8 +408,14 @@ function dottedLookup(obj, str, c) {
for (var i = 0; i < dots.length; i++) {
var dot = dots[i];
s.push(dot);
if (!o.hasOwnProperty(dot))
throw new Error('no property ' + s.join(c) + ' found');
if (!o.hasOwnProperty(dot)) {
var msg = 'no property ' + s.join(c) + ' found' + '\n';
msg += 'The following properties are supported :' + '\n\n';
Object.keys(o).forEach(function (k) {
msg += k + '\n';
});
throw new Error(msg);
}
o = o[dot];
}
return o;
Expand Down