Skip to content

Commit f23c34f

Browse files
authored
feat: match legacy toString output for NumberDecimal type (#17)
1 parent 82967a8 commit f23c34f

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

snippets/mongocompat/mongotypes.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,11 @@ if (typeof NumberDecimal !== 'undefined') {
444444
NumberDecimal.prototype = {};
445445
}
446446

447+
NumberDecimal.prototype.nativeToString = NumberDecimal.prototype.toString
448+
NumberDecimal.prototype.toString = function() {
449+
return `NumberDecimal("${this.nativeToString()}")`;
450+
};
451+
447452
NumberDecimal.prototype.tojson = function() {
448453
return this.toString();
449454
};

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(), 'NumberDecimal("1.1")');

0 commit comments

Comments
 (0)