mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2025-10-16 12:05:41 +00:00
`ObjectID().generate()` returns a `Buffer`, not a `string` @horiuchi @CaselIT See https://github.com/mongodb/js-bson/blob/master/lib/bson/objectid.js#L149 for the source code of bson, excerpted here: ``` /** * Generate a 12 byte id buffer used in ObjectID's * * @method * @param {number} [time] optional parameter allowing to pass in a second based timestamp. * @return {Buffer} return the 12 byte id buffer string. */ ObjectID.prototype.generate = function(time) { if ('number' !== typeof time) { time = ~~(Date.now() / 1000); } // Use pid var pid = (typeof process === 'undefined' || process.pid === 1 ? Math.floor(Math.random() * 100000) : process.pid) % 0xffff; var inc = this.get_inc(); // Buffer used var buffer = new Buffer(12); // Encode time buffer[3] = time & 0xff; buffer[2] = (time >> 8) & 0xff; buffer[1] = (time >> 16) & 0xff; buffer[0] = (time >> 24) & 0xff; // Encode machine buffer[6] = MACHINE_ID & 0xff; buffer[5] = (MACHINE_ID >> 8) & 0xff; buffer[4] = (MACHINE_ID >> 16) & 0xff; // Encode pid buffer[8] = pid & 0xff; buffer[7] = (pid >> 8) & 0xff; // Encode index buffer[11] = inc & 0xff; buffer[10] = (inc >> 8) & 0xff; buffer[9] = (inc >> 16) & 0xff; // Return the buffer return buffer; }; ``` |
||
|---|---|---|
| .. | ||
| bson-tests.ts | ||
| index.d.ts | ||
| tsconfig.json | ||
| tslint.json | ||