_.isBuffer(value)
132
_.isBuffer(value)
_.isBuffer判断一个值是否是一个buffer对象
参数
value (*): 需要检查的值
返回值
(boolean): 如果是buffer对象返回true,否则false
例子
_.isBuffer(new Buffer(2)); // => true _.isBuffer(new Uint8Array(2)); // => false
源代码
import root from './.internal/root.js' /** Detect free variable `exports`. */ //探测exports对象 const freeExports = typeof exports == 'object' && exports !== null && !exports.nodeType && exports /** Detect free variable `module`. */ //探测module对象 const freeModule = freeExports && typeof module == 'object' && module !== null && !module.nodeType && module /** Detect the popular CommonJS extension `module.exports`. */ //探测module.exports对象 const moduleExports = freeModule && freeModule.exports === freeExports /** Built-in value references. */ //内置的Buffer对象引用 const Buffer = moduleExports ? root.Buffer : undefined /* Built-in method references for those with the same name as other `lodash` methods. */ //内置方法引用,引用原生的Buffer.isBuffer方法 const nativeIsBuffer = Buffer ? Buffer.isBuffer : undefined /** * Checks if `value` is a buffer. * * @since 4.3.0 * @category Lang * @param {*} value The value to check. * @returns {boolean} Returns `true` if `value` is a buffer, else `false`. * @example * * isBuffer(new Buffer(2)) * // => true * * isBuffer(new Uint8Array(2)) * // => false */ //判断一个值是否是一个buffer对象 const isBuffer = nativeIsBuffer || (() => false) export default isBuffer