diff --git a/objectid.js b/objectid.js index 3e9f8b8..5f6d49d 100644 --- a/objectid.js +++ b/objectid.js @@ -313,3 +313,6 @@ var inspect = (Symbol && Symbol.for && Symbol.for('nodejs.util.inspect.custom')) ObjectID.prototype[inspect] = function() { return "ObjectID("+this+")" }; ObjectID.prototype.toJSON = ObjectID.prototype.toHexString; ObjectID.prototype.toString = ObjectID.prototype.toHexString; +Object.defineProperty(ObjectID.prototype, "str", { + get: ObjectID.prototype.toHexString +}); diff --git a/test/test.js b/test/test.js index 3ec6720..64ed322 100644 --- a/test/test.js +++ b/test/test.js @@ -123,6 +123,12 @@ describe("ObjectIDs", function() { o.toString().should.eql("54495ad94c934721ede76d90"); }); + it("should convert to a hex string for ObjectID.str", function() { + var hexString = "54495ad94c934721ede76d90"; + var o = new ObjectID(hexString); + o.str.should.eql("54495ad94c934721ede76d90"); + }); + it("should throw and error if constructing with an invalid string", function() { (function(){ var o = new ObjectID("tttttttttttttttttttttttt");