( options?: Version7Options, buf?: TBuf, offset?: number, )
| 20 | offset?: number, |
| 21 | ): TBuf; |
| 22 | function v7<TBuf extends Uint8Array = Uint8Array>( |
| 23 | options?: Version7Options, |
| 24 | buf?: TBuf, |
| 25 | offset?: number, |
| 26 | ): UUIDTypes<TBuf> { |
| 27 | let bytes: Uint8Array; |
| 28 | |
| 29 | if (options) { |
| 30 | // With options: Make UUID independent of internal state |
| 31 | bytes = v7Bytes( |
| 32 | options.random ?? options.rng?.() ?? rng(), |
| 33 | options.msecs, |
| 34 | options.seq, |
| 35 | buf, |
| 36 | offset, |
| 37 | ); |
| 38 | } else { |
| 39 | // No options: Use internal state |
| 40 | const now = Date.now(); |
| 41 | const rnds = rng(); |
| 42 | |
| 43 | updateV7State(_state, now, rnds); |
| 44 | |
| 45 | bytes = v7Bytes(rnds, _state.msecs, _state.seq, buf, offset); |
| 46 | } |
| 47 | |
| 48 | return buf ?? unsafeStringify(bytes); |
| 49 | } |
| 50 | |
| 51 | // (Private!) Do not use. This method is only exported for testing purposes |
| 52 | // and may change without notice. |
no test coverage detected