Skip to content

Commit ae7c47e

Browse files
committed
feat: match legacy toString output for NumberDecimal type
1 parent 82967a8 commit ae7c47e

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

snippets/mongocompat/mongotypes.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -443,9 +443,14 @@ if (typeof NumberDecimal !== 'undefined') {
443443
if (!NumberDecimal.prototype) {
444444
NumberDecimal.prototype = {};
445445
}
446+
NumberDecimal.prototype.nativeToString = NumberDecimal.prototype.toString
446447

447448
NumberDecimal.prototype.tojson = function() {
448-
return this.toString();
449+
return this.nativeToString();
450+
};
451+
452+
NumberDecimal.prototype.toString = function() {
453+
return `NumberDecimal("${this.nativeToString()}")`;
449454
};
450455
}
451456

snippets/mongocompat/test.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,6 @@ assert.strictEqual(minLong.bottom, 0);
2222
assert.strictEqual(minLong.exactValueString, "-9223372036854775808");
2323
const nl2 = NumberLong("200");
2424
assert.strictEqual(maxLong.compare(nl2), 1);
25+
const decimal = NumberDecimal("1.1");
26+
assert.strictEqual(decimal.toString(), 'NumberDecimal("1.1")');
27+
assert.strictEqual(decimal.tojson(), '1.1');

0 commit comments

Comments
 (0)