Skip to content
Permalink
Browse files

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: nodejs/node#18415
  • Loading branch information...
joyeecheung authored and jdalton committed Mar 23, 2018
1 parent 6e4cdc0 commit 363fef0efcf3270ab254fddd0deff12579ce7a26
Showing with 21 additions and 15 deletions.
  1. +9 −3 .internal/{nodeUtil.js → nodeTypes.js}
  2. +2 −2 isArrayBuffer.js
  3. +2 −2 isDate.js
  4. +2 −2 isMap.js
  5. +2 −2 isRegExp.js
  6. +2 −2 isSet.js
  7. +2 −2 isTypedArray.js
@@ -13,10 +13,16 @@ const moduleExports = freeModule && freeModule.exports === freeExports
const freeProcess = moduleExports && freeGlobal.process

/** Used to access faster Node.js helpers. */
const nodeUtil = ((() => {
const nodeTypes = ((() => {
try {
return freeProcess && freeProcess.binding && freeProcess.binding('util')
/* 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 nodeUtil
export default nodeTypes
@@ -1,9 +1,9 @@
import baseGetTag from './.internal/baseGetTag.js'
import isObjectLike from './isObjectLike.js'
import nodeUtil from './.internal/nodeUtil.js'
import nodeTypes from './.internal/nodeTypes.js'

/* Node.js helper references. */
const nodeIsArrayBuffer = nodeUtil && nodeUtil.isArrayBuffer
const nodeIsArrayBuffer = nodeTypes && nodeTypes.isArrayBuffer

/**
* Checks if `value` is classified as an `ArrayBuffer` object.
@@ -1,9 +1,9 @@
import baseGetTag from './.internal/baseGetTag.js'
import isObjectLike from './isObjectLike.js'
import nodeUtil from './.internal/nodeUtil.js'
import nodeTypes from './.internal/nodeTypes.js'

/* Node.js helper references. */
const nodeIsDate = nodeUtil && nodeUtil.isDate
const nodeIsDate = nodeTypes && nodeTypes.isDate

/**
* Checks if `value` is classified as a `Date` object.
@@ -1,9 +1,9 @@
import getTag from './.internal/getTag.js'
import isObjectLike from './isObjectLike.js'
import nodeUtil from './.internal/nodeUtil.js'
import nodeTypes from './.internal/nodeTypes.js'

/* Node.js helper references. */
const nodeIsMap = nodeUtil && nodeUtil.isMap
const nodeIsMap = nodeTypes && nodeTypes.isMap

/**
* Checks if `value` is classified as a `Map` object.
@@ -1,9 +1,9 @@
import baseGetTag from './.internal/baseGetTag.js'
import isObjectLike from './isObjectLike.js'
import nodeUtil from './.internal/nodeUtil.js'
import nodeTypes from './.internal/nodeTypes.js'

/* Node.js helper references. */
const nodeIsRegExp = nodeUtil && nodeUtil.isRegExp
const nodeIsRegExp = nodeTypes && nodeTypes.isRegExp

/**
* Checks if `value` is classified as a `RegExp` object.
@@ -1,9 +1,9 @@
import getTag from './.internal/getTag.js'
import nodeUtil from './.internal/nodeUtil.js'
import nodeTypes from './.internal/nodeTypes.js'
import isObjectLike from './isObjectLike'

/* Node.js helper references. */
const nodeIsSet = nodeUtil && nodeUtil.isSet
const nodeIsSet = nodeTypes && nodeTypes.isSet

/**
* Checks if `value` is classified as a `Set` object.
@@ -1,12 +1,12 @@
import getTag from './.internal/getTag.js'
import nodeUtil from './.internal/nodeUtil.js'
import nodeTypes from './.internal/nodeTypes.js'
import isObjectLike from './isObjectLike'

/** Used to match `toStringTag` values of typed arrays. */
const reTypedTag = /^\[object (?:Float(?:32|64)|(?:Int|Uint)(?:8|16|32)|Uint8Clamped)\]$/

/* Node.js helper references. */
const nodeIsTypedArray = nodeUtil && nodeUtil.isTypedArray
const nodeIsTypedArray = nodeTypes && nodeTypes.isTypedArray

/**
* Checks if `value` is classified as a typed array.

0 comments on commit 363fef0

Please sign in to comment.
You can’t perform that action at this time.