(descending: boolean, timestamp?: number)
| 26 | } |
| 27 | |
| 28 | export function create(descending: boolean, timestamp?: number): string { |
| 29 | const currentTimestamp = timestamp ?? Date.now() |
| 30 | |
| 31 | if (currentTimestamp !== lastTimestamp) { |
| 32 | lastTimestamp = currentTimestamp |
| 33 | counter = 0 |
| 34 | } |
| 35 | counter++ |
| 36 | |
| 37 | let now = BigInt(currentTimestamp) * BigInt(0x1000) + BigInt(counter) |
| 38 | |
| 39 | now = descending ? ~now : now |
| 40 | |
| 41 | const timeBytes = Buffer.alloc(6) |
| 42 | for (let i = 0; i < 6; i++) { |
| 43 | timeBytes[i] = Number((now >> BigInt(40 - 8 * i)) & BigInt(0xff)) |
| 44 | } |
| 45 | |
| 46 | return timeBytes.toString("hex") + randomBase62(LENGTH - 12) |
| 47 | } |
| 48 | } |
no test coverage detected