@zimic/interceptor
Version:
Next-gen TypeScript-first HTTP intercepting and mocking
11 lines (8 loc) • 509 B
text/typescript
import createCachedDynamicImport from '@zimic/utils/import/createCachedDynamicImport';
export type IsomorphicCrypto = Crypto | typeof import('crypto');
export const importCrypto = createCachedDynamicImport<IsomorphicCrypto>(async () => {
const globalCrypto = globalThis.crypto as typeof globalThis.crypto | undefined;
/* istanbul ignore next -- @preserve
* Ignoring as Node.js >=20 provides a global crypto and the import fallback won't run. */
return globalCrypto ?? (await import('crypto'));
});