import { isNil } from '../../../types/primitive/nil'
const isPrototypeOf = Object.prototype.isPrototypeOf
/**
* check if arg 1 is prototype of arg 2
*
* @TODO curry2
* @memberOf is
* @name isPrototypeOf
* @since 3.0.0
*
* @param haystack check needle against
* @param needle is prototype of haystack
* @return needle isPrototypeOf haystack
*
* {@link https://tc39.github.io/ecma262/#sec-object.prototype.isprototypeof emca-is-prototype-of}
* {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/isPrototypeOf mozilla-obj-isprototypeof}
* @see {@link mozilla-obj-isprototypeof}
* @see {@link emca-is-prototype-of}
*
* @example
*
* class Eh extends Function {}
* class Canada extends Eh {}
* isPrototypeOf(Eh, Function) //=> true
* isPrototypeOf(Canada, Function) //=> true
* isPrototypeOf(Eh, Date) //=> false
*
* isPrototypeOf({}, Object) //=> true
* isPrototypeOf({}, Array) //=> false
*
*/
export default <Haystack = any, Needle extends keyof Haystack = any>(
haystack: Haystack,
needle: Needle
) => !isNil(haystack) && isPrototypeOf.call(haystack, needle)