mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-01 23:57:49 +00:00
internal: use util.types to migrate DEP0103 in Node.js (#3704)
- Use require('util').types instead of using process.binding('util')
to get the type checking helpers
- Rename nodeUtil to nodeTypes since that is what it is for
Refs: https://github.com/nodejs/node/pull/18415
This commit is contained in:
committed by
John-David Dalton
parent
6e4cdc0c5e
commit
363fef0efc
28
.internal/nodeTypes.js
Normal file
28
.internal/nodeTypes.js
Normal file
@@ -0,0 +1,28 @@
|
||||
import freeGlobal from './freeGlobal.js'
|
||||
|
||||
/** Detect free variable `exports`. */
|
||||
const freeExports = typeof exports == 'object' && exports !== null && !exports.nodeType && exports
|
||||
|
||||
/** Detect free variable `module`. */
|
||||
const freeModule = freeExports && typeof module == 'object' && module !== null && !module.nodeType && module
|
||||
|
||||
/** Detect the popular CommonJS extension `module.exports`. */
|
||||
const moduleExports = freeModule && freeModule.exports === freeExports
|
||||
|
||||
/** Detect free variable `process` from Node.js. */
|
||||
const freeProcess = moduleExports && freeGlobal.process
|
||||
|
||||
/** Used to access faster Node.js helpers. */
|
||||
const nodeTypes = ((() => {
|
||||
try {
|
||||
/* Detect public `util.types` helpers for Node.js v10+. */
|
||||
/* Node.js deprecation code: DEP0103. */
|
||||
const typesHelper = freeModule && freeModule.require && freeModule.require('util').types
|
||||
return typesHelper
|
||||
? typesHelper
|
||||
/* Legacy process.binding('util') for Node.js earlier than v10. */
|
||||
: freeProcess && freeProcess.binding && freeProcess.binding('util')
|
||||
} catch (e) {}
|
||||
})())
|
||||
|
||||
export default nodeTypes
|
||||
Reference in New Issue
Block a user