Skip to content

Commit 896f613

Browse files
committed
doc(*): fix screwed up formatting in objectid implementation
1 parent edc0592 commit 896f613

File tree

1 file changed

+82
-84
lines changed

1 file changed

+82
-84
lines changed

lib/bson/objectid.js

+82-84
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,23 @@ var MACHINE_ID = parseInt(Math.random() * 0xffffff, 10);
1111

1212
// Regular expression that checks for hex value
1313
var checkForHexRegExp = new RegExp('^[0-9a-fA-F]{24}$');
14+
var hasBufferType = false;
1415

1516
// Check if buffer exists
1617
try {
17-
if (Buffer && Buffer.from) var hasBufferType = true;
18+
if (Buffer && Buffer.from) hasBufferType = true;
1819
} catch (err) {
1920
hasBufferType = false;
2021
}
2122

2223
/**
23-
* Create a new ObjectID instance
24-
*
25-
* @class
26-
* @param {(string|number)} id Can be a 24 byte hex string, 12 byte binary string or a Number.
27-
* @property {number} generationTime The generation time of this ObjectId instance
28-
* @return {ObjectID} instance of ObjectID.
29-
*/
24+
* Create a new ObjectID instance
25+
*
26+
* @class
27+
* @param {(string|number)} id Can be a 24 byte hex string, 12 byte binary string or a Number.
28+
* @property {number} generationTime The generation time of this ObjectId instance
29+
* @return {ObjectID} instance of ObjectID.
30+
*/
3031
var ObjectID = function ObjectID(id) {
3132
// Duck-typing to support ObjectId from different npm packages
3233
if (id instanceof ObjectID) return id;
@@ -81,11 +82,11 @@ for (var i = 0; i < 256; i++) {
8182
}
8283

8384
/**
84-
* Return the ObjectID id as a 24 byte hex string representation
85-
*
86-
* @method
87-
* @return {string} return the 24 byte hex string representation.
88-
*/
85+
* Return the ObjectID id as a 24 byte hex string representation
86+
*
87+
* @method
88+
* @return {string} return the 24 byte hex string representation.
89+
*/
8990
ObjectID.prototype.toHexString = function() {
9091
if (ObjectID.cacheHexString && this.__id) return this.__id;
9192

@@ -113,34 +114,34 @@ ObjectID.prototype.toHexString = function() {
113114
};
114115

115116
/**
116-
* Update the ObjectID index used in generating new ObjectID's on the driver
117-
*
118-
* @method
119-
* @return {number} returns next index value.
120-
* @ignore
121-
*/
117+
* Update the ObjectID index used in generating new ObjectID's on the driver
118+
*
119+
* @method
120+
* @return {number} returns next index value.
121+
* @ignore
122+
*/
122123
ObjectID.prototype.get_inc = function() {
123124
return (ObjectID.index = (ObjectID.index + 1) % 0xffffff);
124125
};
125126

126127
/**
127-
* Update the ObjectID index used in generating new ObjectID's on the driver
128-
*
129-
* @method
130-
* @return {number} returns next index value.
131-
* @ignore
132-
*/
128+
* Update the ObjectID index used in generating new ObjectID's on the driver
129+
*
130+
* @method
131+
* @return {number} returns next index value.
132+
* @ignore
133+
*/
133134
ObjectID.prototype.getInc = function() {
134135
return this.get_inc();
135136
};
136137

137138
/**
138-
* Generate a 12 byte id buffer used in ObjectID's
139-
*
140-
* @method
141-
* @param {number} [time] optional parameter allowing to pass in a second based timestamp.
142-
* @return {Buffer} return the 12 byte id buffer string.
143-
*/
139+
* Generate a 12 byte id buffer used in ObjectID's
140+
*
141+
* @method
142+
* @param {number} [time] optional parameter allowing to pass in a second based timestamp.
143+
* @return {Buffer} return the 12 byte id buffer string.
144+
*/
144145
ObjectID.prototype.generate = function(time) {
145146
if ('number' !== typeof time) {
146147
time = ~~(Date.now() / 1000);
@@ -175,12 +176,12 @@ ObjectID.prototype.generate = function(time) {
175176
};
176177

177178
/**
178-
* Converts the id into a 24 byte hex string for printing
179-
*
180-
* @param {String} format The Buffer toString format parameter.
181-
* @return {String} return the 24 byte hex string representation.
182-
* @ignore
183-
*/
179+
* Converts the id into a 24 byte hex string for printing
180+
*
181+
* @param {String} format The Buffer toString format parameter.
182+
* @return {String} return the 24 byte hex string representation.
183+
* @ignore
184+
*/
184185
ObjectID.prototype.toString = function(format) {
185186
// Is the id a buffer then use the buffer toString method to return the format
186187
if (this.id && this.id.copy) {
@@ -192,33 +193,31 @@ ObjectID.prototype.toString = function(format) {
192193
};
193194

194195
/**
195-
* Converts to a string representation of this Id.
196-
*
197-
* @return {String} return the 24 byte hex string representation.
198-
* @ignore
199-
*/
196+
* Converts to a string representation of this Id.
197+
*
198+
* @return {String} return the 24 byte hex string representation.
199+
* @ignore
200+
*/
200201
ObjectID.prototype.inspect = ObjectID.prototype.toString;
201202

202203
/**
203-
* Converts to its JSON representation.
204-
*
205-
* @return {String} return the 24 byte hex string representation.
206-
* @ignore
207-
*/
204+
* Converts to its JSON representation.
205+
*
206+
* @return {String} return the 24 byte hex string representation.
207+
* @ignore
208+
*/
208209
ObjectID.prototype.toJSON = function() {
209210
return this.toHexString();
210211
};
211212

212213
/**
213-
* Compares the equality of this ObjectID with `otherID`.
214-
*
215-
* @method
216-
* @param {object} otherID ObjectID instance to compare against.
217-
* @return {boolean} the result of comparing two ObjectID's
218-
*/
214+
* Compares the equality of this ObjectID with `otherID`.
215+
*
216+
* @method
217+
* @param {object} otherID ObjectID instance to compare against.
218+
* @return {boolean} the result of comparing two ObjectID's
219+
*/
219220
ObjectID.prototype.equals = function equals(otherId) {
220-
// var id;
221-
222221
if (otherId instanceof ObjectID) {
223222
return this.toString() === otherId.toString();
224223
} else if (
@@ -240,11 +239,11 @@ ObjectID.prototype.equals = function equals(otherId) {
240239
};
241240

242241
/**
243-
* Returns the generation date (accurate up to the second) that this ID was generated.
244-
*
245-
* @method
246-
* @return {date} the generation date
247-
*/
242+
* Returns the generation date (accurate up to the second) that this ID was generated.
243+
*
244+
* @method
245+
* @return {date} the generation date
246+
*/
248247
ObjectID.prototype.getTimestamp = function() {
249248
var timestamp = new Date();
250249
var time = this.id[3] | (this.id[2] << 8) | (this.id[1] << 16) | (this.id[0] << 24);
@@ -253,24 +252,24 @@ ObjectID.prototype.getTimestamp = function() {
253252
};
254253

255254
/**
256-
* @ignore
257-
*/
255+
* @ignore
256+
*/
258257
ObjectID.index = ~~(Math.random() * 0xffffff);
259258

260259
/**
261-
* @ignore
262-
*/
260+
* @ignore
261+
*/
263262
ObjectID.createPk = function createPk() {
264263
return new ObjectID();
265264
};
266265

267266
/**
268-
* Creates an ObjectID from a second based number, with the rest of the ObjectID zeroed out. Used for comparisons or sorting the ObjectID.
269-
*
270-
* @method
271-
* @param {number} time an integer number representing a number of seconds.
272-
* @return {ObjectID} return the created ObjectID
273-
*/
267+
* Creates an ObjectID from a second based number, with the rest of the ObjectID zeroed out. Used for comparisons or sorting the ObjectID.
268+
*
269+
* @method
270+
* @param {number} time an integer number representing a number of seconds.
271+
* @return {ObjectID} return the created ObjectID
272+
*/
274273
ObjectID.createFromTime = function createFromTime(time) {
275274
var buffer = new Buffer([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]);
276275
// Encode time into first 4 bytes
@@ -283,7 +282,6 @@ ObjectID.createFromTime = function createFromTime(time) {
283282
};
284283

285284
// Lookup tables
286-
//var encodeLookup = '0123456789abcdef'.split('');
287285
var decodeLookup = [];
288286
i = 0;
289287
while (i < 10) decodeLookup[0x30 + i] = i++;
@@ -295,12 +293,12 @@ var convertToHex = function(bytes) {
295293
};
296294

297295
/**
298-
* Creates an ObjectID from a hex string representation of an ObjectID.
299-
*
300-
* @method
301-
* @param {string} hexString create a ObjectID from a passed in 24 byte hexstring.
302-
* @return {ObjectID} return the created ObjectID
303-
*/
296+
* Creates an ObjectID from a hex string representation of an ObjectID.
297+
*
298+
* @method
299+
* @param {string} hexString create a ObjectID from a passed in 24 byte hexstring.
300+
* @return {ObjectID} return the created ObjectID
301+
*/
304302
ObjectID.createFromHexString = function createFromHexString(string) {
305303
// Throw an error if it's not a valid setup
306304
if (typeof string === 'undefined' || (string != null && string.length !== 24)) {
@@ -325,11 +323,11 @@ ObjectID.createFromHexString = function createFromHexString(string) {
325323
};
326324

327325
/**
328-
* Checks if a value is a valid bson ObjectId
329-
*
330-
* @method
331-
* @return {boolean} return true if the value is a valid bson ObjectId, return false otherwise.
332-
*/
326+
* Checks if a value is a valid bson ObjectId
327+
*
328+
* @method
329+
* @return {boolean} return true if the value is a valid bson ObjectId, return false otherwise.
330+
*/
333331
ObjectID.isValid = function isValid(id) {
334332
if (id == null) return false;
335333

@@ -358,8 +356,8 @@ ObjectID.isValid = function isValid(id) {
358356
};
359357

360358
/**
361-
* @ignore
362-
*/
359+
* @ignore
360+
*/
363361
Object.defineProperty(ObjectID.prototype, 'generationTime', {
364362
enumerable: true,
365363
get: function() {

0 commit comments

Comments
 (0)