Skip to content
This repository has been archived by the owner on Feb 3, 2022. It is now read-only.

Commit

Permalink
feat(double): supported relaxed mode for double parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
mbroadst committed Apr 1, 2018
1 parent 974db37 commit 0ee5016
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions lib/bson/double.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
'use strict';

function toExtendedJSON(obj, options) {
if (options.relaxed && isFinite(obj.value)) return obj.value;
if (options && options.relaxed && isFinite(obj.value)) return obj.value;
return { $numberDouble: obj.value.toString() };
}

function fromExtendedJSON(BSON, doc) {
return new BSON.Double(parseFloat(doc.$numberDouble));
function fromExtendedJSON(BSON, doc, options) {
return options && options.relaxed
? parseFloat(doc.$numberDouble)
: new BSON.Double(parseFloat(doc.$numberDouble));
}

module.exports = {
Expand Down

0 comments on commit 0ee5016

Please sign in to comment.