Skip to content

Instantly share code, notes, and snippets.

@JetLua
Last active January 9, 2023 03:04
Show Gist options
  • Save JetLua/c89b2b175ff2172cbcfd1ec9bfa55cd8 to your computer and use it in GitHub Desktop.
Save JetLua/c89b2b175ff2172cbcfd1ec9bfa55cd8 to your computer and use it in GitHub Desktop.
export function pureObject(o: unknown) {
if (!isObject(o)) return false
const ctor = o.constructor
if (ctor == null) return true
const prot = ctor.prototype
if (!isObject(prot)) return false
if (!Object.prototype.hasOwnProperty.call(prot, 'isPrototypeOf')) return false
return true
}
function isObject(o: unknown) {
return Object.prototype.toString.call(o) === '[object Object]'
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment