3.1.0-cjser.2 • Published 1 month ago
@cjser/has-own-prop
Licence
MIT
Version
3.1.0-cjser.2
Deps
0
Size
5 kB
Vulns
0
Weekly
0
has-own-prop
A safer
.hasOwnProperty()
Shortcut for Object.prototype.hasOwnProperty.call(object, property). Also comes with a type guard for TypeScript users.
You shouldn't use .hasOwnProperty() as it won't exist on objects created with Object.create(null) or it can have been overridden.
Install
npm install has-own-prop
Usage
import hasOwnProperty from 'has-own-prop';
const object = Object.create(null);
object.unicorn = true;
object.hasOwnProperty('unicorn');
//=> 'TypeError: undefined is not a function'
hasOwnProperty(object, 'unicorn');
//=> true
cjser
This package is a CommonJS-compatible build generated by cjser for projects that still need require() support. The source version matches the original npm package version, with a cjser prerelease suffix for this generated build.
Original repository: https://github.com/sindresorhus/has-own-prop