-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
106 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,11 @@ | ||
"use strict"; | ||
"use strict"; | ||
|
||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.id = id; | ||
let store = 0; | ||
function id() { | ||
store++; | ||
return store; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
'use strict'; | ||
|
||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.mongoid = mongoid; | ||
const MACHINE_ID = parseInt(Math.random() * 0xFFFFFF, 10); | ||
const PID = typeof process === 'undefined' || (typeof process.pid !== 'number' ? Math.floor(Math.random() * 100000) : process.pid) % 0xFFFF; | ||
let index = parseInt(Math.random() * 0xFFFFFF, 10); | ||
function toFixedHex(val, length) { | ||
if (typeof val === 'number') { | ||
return this.pad(val.toString(16).substring(0, length), length); | ||
} | ||
return this.pad(val.substring(0, length), length); | ||
} | ||
function mongoid() { | ||
let params = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0]; | ||
var _params$timestamp = params.timestamp; | ||
const timestamp = _params$timestamp === undefined ? Number(new Date()) : _params$timestamp; | ||
var _params$machine = params.machine; | ||
const machine = _params$machine === undefined ? MACHINE_ID : _params$machine; | ||
var _params$pid = params.pid; | ||
const pid = _params$pid === undefined ? PID : _params$pid; | ||
|
||
let result = ''; | ||
result += toFixedHex.call(this, Math.floor(timestamp / 1000), 8); | ||
result += toFixedHex.call(this, machine, 6); | ||
result += toFixedHex.call(this, pid, 4); | ||
result += toFixedHex.call(this, index, 6); | ||
index++; | ||
return result; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
let store = 0; | ||
export function id() { | ||
store++; | ||
return store; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
const MACHINE_ID = parseInt(Math.random() * 0xFFFFFF, 10); | ||
const PID = typeof process === 'undefined' || | ||
(typeof process.pid !== 'number' ? Math.floor(Math.random() * 100000) : process.pid) % 0xFFFF; | ||
let index = parseInt(Math.random() * 0xFFFFFF, 10); | ||
function toFixedHex(val, length) { | ||
if (typeof val === 'number') { | ||
return this.pad(val.toString(16).substring(0, length), length); | ||
} | ||
return this.pad(val.substring(0, length), length); | ||
} | ||
export function mongoid(params = {}) { | ||
const { timestamp = Number(new Date()), machine = MACHINE_ID, pid = PID } = params; | ||
let result = ''; | ||
result += toFixedHex.call(this, Math.floor(timestamp / 1000), 8); | ||
result += toFixedHex.call(this, machine, 6); | ||
result += toFixedHex.call(this, pid, 4); | ||
result += toFixedHex.call(this, index, 6); | ||
index++; | ||
return result; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters