Skip to content

Commit

Permalink
Adding BigInt support - #23
Browse files Browse the repository at this point in the history
  • Loading branch information
vitaly-t committed Oct 7, 2019
1 parent 3db85df commit 2285627
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ const monitor = {
if (e.params) {
let p = e.params;
if (typeof p !== 'string') {
p = JSON.stringify(p);
p = toJson(p);
}
print(e, event, timeGap + cct.paramTitle('params: ') + cct.value(p), true);
}
Expand Down Expand Up @@ -191,11 +191,11 @@ const monitor = {
});
q = tmp;
}
q = JSON.stringify(q);
q = toJson(q);
}
if (e.cn) {
// a connection issue;
print(e, event, timeGap + cct.paramTitle('connection: ') + cct.value(JSON.stringify(e.cn)), true);
print(e, event, timeGap + cct.paramTitle('connection: ') + cct.value(toJson(e.cn)), true);
} else {
if (q !== undefined) {
const d = (detailed === undefined) ? monitor.detailed : !!detailed;
Expand All @@ -213,7 +213,7 @@ const monitor = {
}
}
if (e.params) {
print(e, event, timeGap + cct.paramTitle('params: ') + cct.value(JSON.stringify(e.params)), true);
print(e, event, timeGap + cct.paramTitle('params: ') + cct.value(toJson(e.params)), true);
}
},

Expand Down Expand Up @@ -528,6 +528,16 @@ function isNull(value) {
return value === null || value === undefined;
}

///////////////////////////////////////////////////////////////
// Adds support for BigInt, to be rendered like in JavaScript,
// as an open value, with 'n' in the end.
function toJson(data) {
if (data !== undefined) {
return JSON.stringify(data, (_, v) => typeof v === 'bigint' ? `${v}#bigint` : v)
.replace(/"(-?\d+)#bigint"/g, (_, a) => a + 'n');
}
}

// reusable error messages;
const errors = {
redirectParams(event) {
Expand Down

0 comments on commit 2285627

Please sign in to comment.