UNPKG

uid-pool

Version:

High-performance UUID and unique ID pooling for Node.js. Pre-generate IDs in background worker threads for O(1) synchronous acquisition. Drop-in replacement for uuid.v4() and nanoid() with 10-100x better performance under load.

38 lines 1.18 kB
/** * Auto-detects the runtime environment and imports the appropriate IdPool implementation. */ // Detect if we're in a Node.js environment with worker_threads support function detectRuntime() { // Check for Node.js-specific globals if (typeof global !== "undefined" && typeof process !== "undefined" && process.versions && process.versions.node) { return "node"; } // Default to edge runtime return "edge"; } /** * Create a new IdPool instance that is ready for use. * Automatically detects the runtime and uses the appropriate implementation. */ export async function create(options) { const runtime = detectRuntime(); // Dynamically import and create the appropriate implementation if (runtime === "node") { const { IdPool: NodePool } = await import("../node/index.js"); return NodePool.create(options); } else { const { IdPool: EdgePool } = await import("../edge/index.js"); return EdgePool.create(options); } } /** * IdPool factory for creating ID pools with runtime auto-detection. */ export const IdPool = { create, }; //# sourceMappingURL=index.js.map