UNPKG

t-comm

Version:

专业、稳定、纯粹的工具库

19 lines (17 loc) 519 B
/** * 获取 Node.js 的 crypto 模块 * 这样可以避免在浏览器环境中直接导入 crypto 模块导致的错误 * @returns crypto 模块 * @example * ```ts * const crypto = getCrypto(); * const hash = crypto.createHash('md5').update('hello').digest('hex'); * ``` */ function getCrypto() { // 在浏览器环境中,这个函数不应该被调用 // 如果被调用,会抛出错误 // 在 Node.js 环境中,会正常返回 crypto 模块 return require('crypto'); } export { getCrypto };