isBuffer.js 1.3 KB
Newer Older
1
import root from './root.js';
徐立's avatar
徐立 committed
2 3 4

/** Detect free variable `exports`. */
/** 检测自由变量“导出” */
5
const freeExports = typeof exports === 'object' && exports !== null && !exports.nodeType && exports;
徐立's avatar
徐立 committed
6 7 8

/** Detect free variable `module`. */
/** 检测自由变量“模块”。 */
9 10
const freeModule =
	freeExports && typeof module === 'object' && module !== null && !module.nodeType && module;
徐立's avatar
徐立 committed
11 12 13

/** Detect the popular CommonJS extension `module.exports`. */
/** 检测流行的CommonJS扩展“module.exports”。 */
14
const moduleExports = freeModule && freeModule.exports === freeExports;
徐立's avatar
徐立 committed
15 16 17

/** Built-in value references. */
/** 内置参考价值。 */
18
const Buffer = moduleExports ? root.Buffer : undefined;
徐立's avatar
徐立 committed
19 20 21

/* Built-in method references for those with the same name as other `lodash` methods. */
/* 内置的方法引用与其他“lodash”方法同名。 */
22
const nativeIsBuffer = Buffer ? Buffer.isBuffer : undefined;
徐立's avatar
徐立 committed
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38

/**
 * Checks if `value` is a buffer.
 * 检查' value '是否为缓冲区。
 * @since 4.3.0
 * @category Lang
 * @param {*} value 要检查的值。
 * @returns {boolean} 如果' value '是一个缓冲区,则返回' true ',否则返回' false '。
 * @example
 *
 * isBuffer(new Buffer(2))
 * // => true
 *
 * isBuffer(new Uint8Array(2))
 * // => false
 */
39
const isBuffer = nativeIsBuffer || (() => false);
徐立's avatar
徐立 committed
40

41
export default isBuffer;