1.1.0 • Published 3 years ago
babel-plugin-transform-object-hasown v1.1.0
babel-plugin-transform-object-hasown
Babel plugin for transforming
Object.hasOwn
.
Install
npm install babel-plugin-transform-object-hasown --save-dev
Usage
Use it via available plugin activation options.
For .babelrc
file:
{
"plugins": ["babel-plugin-transform-object-hasown"]
}
Then, in your code:
const object = {};
if (Object.hasOwn(object, 'becky')) {
console.log('has property becky');
}
After transformation:
var _objectHasOwn = function (object, property) {
if (typeof object === 'undefined' || object === null) {
throw new TypeError('Cannot convert undefined or null to object');
}
return Object.prototype.hasOwnProperty.call(Object(object), property);
};
const object = {};
if (_objectHasOwn(object, 'becky')) {
console.log('has property becky');
}
Check test fixtures (actual and expected) for more examples.
Caveats
Will only work with code of the form Object.hasOwn
or Object['hasOwn']
.
License
MIT © Ivan Nikolić