dep/node-buffalo/lib/objectid.js
function ObjectId(bytes) {
    if (Buffer.isBuffer(bytes)) {
        if (bytes.length != 12) throw new Error("Buffer-based ObjectId must be 12 bytes")
        this.bytes = bytes
    } else if (typeof bytes == 'string') {
        if (bytes.length != 24) throw new Error("String-based ObjectId must be 24 bytes")
        if (!/^[0-9a-f]{24}$/i.test(bytes)) throw new Error("String-based ObjectId must in hex-format:" + bytes)
        this.bytes = fromHex(bytes)
    } else if (typeof bytes !== 'undefined') {
        throw new Error("Unrecognized type: "+bytes)
    } else {
        var timestamp = (Date.now() / 1000) & 0xFFFFFFFF
        inc = ~~inc+1 // keep as integer
        this.bytes = new Buffer([
            timestamp>>24,
            timestamp>>16,
            timestamp>>8,
            timestamp,
            machineAndPid[0],
            machineAndPid[1],
            machineAndPid[2],
            machineAndPid[3],
            machineAndPid[4],
            inc>>16,
            inc>>8,
            inc
        ])
    }
}
function ObjectId(bytes) {
    if (Buffer.isBuffer(bytes)) {
        if (bytes.length != 12) throw new Error("Buffer-based ObjectId must be 12 bytes")
        this.bytes = bytes
    } else if (typeof bytes == 'string') {
        if (bytes.length != 24) throw new Error("String-based ObjectId must be 24 bytes")
        if (!/^[0-9a-f]{24}$/i.test(bytes)) throw new Error("String-based ObjectId must in hex-format:" + bytes)
        this.bytes = fromHex(bytes)
    } else if (typeof bytes !== 'undefined') {
        throw new Error("Unrecognized type: "+bytes)
    } else {
        var timestamp = (Date.now() / 1000) & 0xFFFFFFFF
        inc = ~~inc+1 // keep as integer
        this.bytes = new Buffer([
            timestamp>>24,
            timestamp>>16,
            timestamp>>8,
            timestamp,
            machineAndPid[0],
            machineAndPid[1],
            machineAndPid[2],
            machineAndPid[3],
            machineAndPid[4],
            inc>>16,
            inc>>8,
            inc
        ])
    }
}
function ObjectId ( bytes ) { if ( Buffer . isBuffer ( bytes ) ) { if ( bytes . length != 12 ) throw new Error ( "Buffer-based ObjectId must be 12 bytes" ) this . bytes = bytes } else if ( typeof bytes == 'string' ) { if ( bytes . length != 24 ) throw new Error ( "String-based ObjectId must be 24 bytes" ) if ( ! / ^[0-9a-f]{24}$ / i . test ( bytes ) ) throw new Error ( "String-based ObjectId must in hex-format:" + bytes ) this . bytes = fromHex ( bytes ) } else if ( typeof bytes !== 'undefined' ) { throw new Error ( "Unrecognized type: " + bytes ) } else { var timestamp = ( Date . now ( ) / 1000 ) & 0xFFFFFFFF inc = ~ ~ inc + 1 // keep as integer this . bytes = new Buffer ( [ timestamp >> 24 , timestamp >> 16 , timestamp >> 8 , timestamp , machineAndPid [ 0 ] , machineAndPid [ 1 ] , machineAndPid [ 2 ] , machineAndPid [ 3 ] , machineAndPid [ 4 ] , inc >> 16 , inc >> 8 , inc ] ) } }
32 bit time 24 bit machine id 16 bit pid 24 bit increment
32 bit time 24 bit machine id 16 bit pid 24 bit increment