JSPM

babel-plugin-transform-object-hasown

1.0.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 4382
  • Score
    100M100P100Q139038F
  • 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) {
    return Object.prototype.hasOwnProperty.call(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ć