Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

babel-plugin-transform-object-hasown

niksy15.9kMIT1.1.0

Babel plugin for transforming Object.hasOwn.

babel, plugin, transform, object, hasown, object.hasown, hasownproperty

readme

babel-plugin-transform-object-hasown

Build Status

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ć

changelog

Changelog

Unreleased

1.1.0 - 2021-06-05

Changed

  • Make consistent with official polyfill

1.0.0 - 2021-05-26

Added

  • Initial implementation