JSPM

babel-plugin-transform-object-hasown

1.1.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 4382
  • Score
    100M100P100Q139028F
  • License MIT

Babel plugin for transforming `Object.hasOwn`.

Package Exports

  • babel-plugin-transform-object-hasown
  • babel-plugin-transform-object-hasown/package.json

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ć