@@ -45,40 +45,40 @@ function convertToHex(bytes) {
45
45
/**
46
46
* A class representation of the BSON ObjectId type.
47
47
*/
48
- class ObjectID {
48
+ class ObjectId {
49
49
/**
50
50
* Create an ObjectId type
51
51
*
52
52
* @param {(string|number) } id Can be a 24 byte hex string, 12 byte binary string or a Number.
53
53
* @property {number } generationTime The generation time of this ObjectId instance
54
- * @return {ObjectID } instance of ObjectID .
54
+ * @return {ObjectId } instance of ObjectId .
55
55
*/
56
56
constructor ( id ) {
57
57
// Duck-typing to support ObjectId from different npm packages
58
- if ( id instanceof ObjectID ) return id ;
58
+ if ( id instanceof ObjectId ) return id ;
59
59
60
60
// The most common usecase (blank id, new objectId instance)
61
61
if ( id == null || typeof id === 'number' ) {
62
62
// Generate a new id
63
63
this . id = this . generate ( id ) ;
64
64
// If we are caching the hex string
65
- if ( ObjectID . cacheHexString ) this . __id = this . toString ( 'hex' ) ;
65
+ if ( ObjectId . cacheHexString ) this . __id = this . toString ( 'hex' ) ;
66
66
// Return the object
67
67
return ;
68
68
}
69
69
70
70
// Check if the passed in id is valid
71
- const valid = ObjectID . isValid ( id ) ;
71
+ const valid = ObjectId . isValid ( id ) ;
72
72
73
73
// Throw an error if it's not a valid setup
74
74
if ( ! valid && id != null ) {
75
75
throw new TypeError (
76
76
'Argument passed in must be a single String of 12 bytes or a string of 24 hex characters'
77
77
) ;
78
78
} else if ( valid && typeof id === 'string' && id . length === 24 && hasBufferType ) {
79
- return new ObjectID ( new Buffer ( id , 'hex' ) ) ;
79
+ return new ObjectId ( new Buffer ( id , 'hex' ) ) ;
80
80
} else if ( valid && typeof id === 'string' && id . length === 24 ) {
81
- return ObjectID . createFromHexString ( id ) ;
81
+ return ObjectId . createFromHexString ( id ) ;
82
82
} else if ( id != null && id . length === 12 ) {
83
83
// assume 12 byte string
84
84
this . id = id ;
@@ -91,17 +91,17 @@ class ObjectID {
91
91
) ;
92
92
}
93
93
94
- if ( ObjectID . cacheHexString ) this . __id = this . toString ( 'hex' ) ;
94
+ if ( ObjectId . cacheHexString ) this . __id = this . toString ( 'hex' ) ;
95
95
}
96
96
97
97
/**
98
- * Return the ObjectID id as a 24 byte hex string representation
98
+ * Return the ObjectId id as a 24 byte hex string representation
99
99
*
100
100
* @method
101
101
* @return {string } return the 24 byte hex string representation.
102
102
*/
103
103
toHexString ( ) {
104
- if ( ObjectID . cacheHexString && this . __id ) return this . __id ;
104
+ if ( ObjectId . cacheHexString && this . __id ) return this . __id ;
105
105
106
106
let hexString = '' ;
107
107
if ( ! this . id || ! this . id . length ) {
@@ -114,31 +114,31 @@ class ObjectID {
114
114
115
115
if ( this . id instanceof _Buffer ) {
116
116
hexString = convertToHex ( this . id ) ;
117
- if ( ObjectID . cacheHexString ) this . __id = hexString ;
117
+ if ( ObjectId . cacheHexString ) this . __id = hexString ;
118
118
return hexString ;
119
119
}
120
120
121
121
for ( let i = 0 ; i < this . id . length ; i ++ ) {
122
122
hexString += hexTable [ this . id . charCodeAt ( i ) ] ;
123
123
}
124
124
125
- if ( ObjectID . cacheHexString ) this . __id = hexString ;
125
+ if ( ObjectId . cacheHexString ) this . __id = hexString ;
126
126
return hexString ;
127
127
}
128
128
129
129
/**
130
- * Update the ObjectID index used in generating new ObjectID 's on the driver
130
+ * Update the ObjectId index used in generating new ObjectId 's on the driver
131
131
*
132
132
* @method
133
133
* @return {number } returns next index value.
134
134
* @ignore
135
135
*/
136
136
get_inc ( ) {
137
- return ( ObjectID . index = ( ObjectID . index + 1 ) % 0xffffff ) ;
137
+ return ( ObjectId . index = ( ObjectId . index + 1 ) % 0xffffff ) ;
138
138
}
139
139
140
140
/**
141
- * Update the ObjectID index used in generating new ObjectID 's on the driver
141
+ * Update the ObjectId index used in generating new ObjectId 's on the driver
142
142
*
143
143
* @method
144
144
* @return {number } returns next index value.
@@ -149,7 +149,7 @@ class ObjectID {
149
149
}
150
150
151
151
/**
152
- * Generate a 12 byte id buffer used in ObjectID 's
152
+ * Generate a 12 byte id buffer used in ObjectId 's
153
153
*
154
154
* @method
155
155
* @param {number } [time] optional parameter allowing to pass in a second based timestamp.
@@ -215,35 +215,35 @@ class ObjectID {
215
215
}
216
216
217
217
/**
218
- * Compares the equality of this ObjectID with `otherID`.
218
+ * Compares the equality of this ObjectId with `otherID`.
219
219
*
220
220
* @method
221
- * @param {object } otherID ObjectID instance to compare against.
222
- * @return {boolean } the result of comparing two ObjectID 's
221
+ * @param {object } otherID ObjectId instance to compare against.
222
+ * @return {boolean } the result of comparing two ObjectId 's
223
223
*/
224
224
equals ( otherId ) {
225
- if ( otherId instanceof ObjectID ) {
225
+ if ( otherId instanceof ObjectId ) {
226
226
return this . toString ( ) === otherId . toString ( ) ;
227
227
}
228
228
229
229
if (
230
230
typeof otherId === 'string' &&
231
- ObjectID . isValid ( otherId ) &&
231
+ ObjectId . isValid ( otherId ) &&
232
232
otherId . length === 12 &&
233
233
this . id instanceof _Buffer
234
234
) {
235
235
return otherId === this . id . toString ( 'binary' ) ;
236
236
}
237
237
238
- if ( typeof otherId === 'string' && ObjectID . isValid ( otherId ) && otherId . length === 24 ) {
238
+ if ( typeof otherId === 'string' && ObjectId . isValid ( otherId ) && otherId . length === 24 ) {
239
239
return otherId . toLowerCase ( ) === this . toHexString ( ) ;
240
240
}
241
241
242
- if ( typeof otherId === 'string' && ObjectID . isValid ( otherId ) && otherId . length === 12 ) {
242
+ if ( typeof otherId === 'string' && ObjectId . isValid ( otherId ) && otherId . length === 12 ) {
243
243
return otherId === this . id ;
244
244
}
245
245
246
- if ( otherId != null && ( otherId instanceof ObjectID || otherId . toHexString ) ) {
246
+ if ( otherId != null && ( otherId instanceof ObjectId || otherId . toHexString ) ) {
247
247
return otherId . toHexString ( ) === this . toHexString ( ) ;
248
248
}
249
249
@@ -267,15 +267,15 @@ class ObjectID {
267
267
* @ignore
268
268
*/
269
269
static createPk ( ) {
270
- return new ObjectID ( ) ;
270
+ return new ObjectId ( ) ;
271
271
}
272
272
273
273
/**
274
- * Creates an ObjectID from a second based number, with the rest of the ObjectID zeroed out. Used for comparisons or sorting the ObjectID .
274
+ * Creates an ObjectId from a second based number, with the rest of the ObjectId zeroed out. Used for comparisons or sorting the ObjectId .
275
275
*
276
276
* @method
277
277
* @param {number } time an integer number representing a number of seconds.
278
- * @return {ObjectID } return the created ObjectID
278
+ * @return {ObjectId } return the created ObjectId
279
279
*/
280
280
static createFromTime ( time ) {
281
281
const buffer = new Buffer ( [ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ] ) ;
@@ -285,15 +285,15 @@ class ObjectID {
285
285
buffer [ 1 ] = ( time >> 16 ) & 0xff ;
286
286
buffer [ 0 ] = ( time >> 24 ) & 0xff ;
287
287
// Return the new objectId
288
- return new ObjectID ( buffer ) ;
288
+ return new ObjectId ( buffer ) ;
289
289
}
290
290
291
291
/**
292
- * Creates an ObjectID from a hex string representation of an ObjectID .
292
+ * Creates an ObjectId from a hex string representation of an ObjectId .
293
293
*
294
294
* @method
295
- * @param {string } hexString create a ObjectID from a passed in 24 byte hexstring.
296
- * @return {ObjectID } return the created ObjectID
295
+ * @param {string } hexString create a ObjectId from a passed in 24 byte hexstring.
296
+ * @return {ObjectId } return the created ObjectId
297
297
*/
298
298
static createFromHexString ( string ) {
299
299
// Throw an error if it's not a valid setup
@@ -304,7 +304,7 @@ class ObjectID {
304
304
}
305
305
306
306
// Use Buffer.from method if available
307
- if ( hasBufferType ) return new ObjectID ( new Buffer ( string , 'hex' ) ) ;
307
+ if ( hasBufferType ) return new ObjectId ( new Buffer ( string , 'hex' ) ) ;
308
308
309
309
// Calculate lengths
310
310
const array = new _Buffer ( 12 ) ;
@@ -316,7 +316,7 @@ class ObjectID {
316
316
( decodeLookup [ string . charCodeAt ( i ++ ) ] << 4 ) | decodeLookup [ string . charCodeAt ( i ++ ) ] ;
317
317
}
318
318
319
- return new ObjectID ( array ) ;
319
+ return new ObjectId ( array ) ;
320
320
}
321
321
322
322
/**
@@ -336,7 +336,7 @@ class ObjectID {
336
336
return id . length === 12 || ( id . length === 24 && checkForHexRegExp . test ( id ) ) ;
337
337
}
338
338
339
- if ( id instanceof ObjectID ) {
339
+ if ( id instanceof ObjectId ) {
340
340
return true ;
341
341
}
342
342
@@ -356,7 +356,7 @@ class ObjectID {
356
356
/**
357
357
* @ignore
358
358
*/
359
- Object . defineProperty ( ObjectID . prototype , 'generationTime' , {
359
+ Object . defineProperty ( ObjectId . prototype , 'generationTime' , {
360
360
enumerable : true ,
361
361
get : function ( ) {
362
362
return this . id [ 3 ] | ( this . id [ 2 ] << 8 ) | ( this . id [ 1 ] << 16 ) | ( this . id [ 0 ] << 24 ) ;
@@ -376,12 +376,12 @@ Object.defineProperty(ObjectID.prototype, 'generationTime', {
376
376
* @return {String } return the 24 byte hex string representation.
377
377
* @ignore
378
378
*/
379
- ObjectID . prototype . inspect = ObjectID . prototype . toString ;
379
+ ObjectId . prototype . inspect = ObjectId . prototype . toString ;
380
380
381
381
/**
382
382
* @ignore
383
383
*/
384
- ObjectID . index = ~ ~ ( Math . random ( ) * 0xffffff ) ;
384
+ ObjectId . index = ~ ~ ( Math . random ( ) * 0xffffff ) ;
385
385
386
- Object . defineProperty ( ObjectID . prototype , '_bsontype' , { value : 'ObjectID ' } ) ;
387
- module . exports = ObjectID ;
386
+ Object . defineProperty ( ObjectId . prototype , '_bsontype' , { value : 'ObjectId ' } ) ;
387
+ module . exports = ObjectId ;
0 commit comments