babel-plugin-transform-object-hasown

1.1.0 • Public • Published

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ć

Package Sidebar

Install

npm i babel-plugin-transform-object-hasown

Weekly Downloads

3,169

Version

1.1.0

License

MIT

Unpacked Size

15 kB

Total Files

10

Last publish

Collaborators

  • niksy