Last active
March 7, 2019 14:07
-
-
Save tusbar/dafc8af4a074b04d00e7f2d90c3d42f2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const {ObjectId} = require('mongodb') | |
function parse(input) { | |
if (!input) { | |
return | |
} | |
if (input._id) { | |
input = input._id | |
} | |
if (input instanceof ObjectId) { | |
return input | |
} | |
if (typeof input === 'string' && ObjectId.isValid(input)) { | |
return new ObjectId(input) | |
} | |
} | |
function equals(left, right) { | |
const ol = parse(left) | |
const or = parse(right) | |
return Boolean(ol) && ol.equals(or) | |
} | |
exports.parse = parse | |
exports.equals = equals |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment