import { toLength } from '../../../../deps'
import { isObj } from '../../../obj'
import { isFunction } from '../../../function'
import { isNumber } from '../../../primitive/number'
/**
* @desc isBuffer, global Buffer
* @since 5.0.0-beta.1
*
* @memberOf is
* @param {Buffer | *} x value to check if Buffer
* @return {boolean} x is Buffer
*
* If you need to support Safari 5-7 (8-10 yr-old browser),
*
* @see https://nodejs.org/api/util.html#util_util_isbuffer_object
* @see https://github.com/feross/is-buffer
*
* @example
*
* isBuffer({}) //=> false
* isBuffer(new Buffer('eh')) //=> true
*
*/
export default function isBuffer(x: any): x is ArrayBufferLike | Buffer {
if (!x || isObj(x) || toLength(x)) return false
else if (!isFunction(x.copy) || isFunction(x.slice)) return false
else if (toLength(x) > 0 && isNumber(x[0])) return false
else return true
}
// another way to write it
// module.exports = function isBuffer(val) {
// var c = val.constructor
// return c &&
// typeof c.isBuffer === 'function' &&
// c.isBuffer(val)
// }