Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/niksy/babel-plugin-transform-object-hasown
Babel plugin for transforming `Object.hasOwn`.
https://github.com/niksy/babel-plugin-transform-object-hasown
Last synced: 7 days ago
JSON representation
Babel plugin for transforming `Object.hasOwn`.
- Host: GitHub
- URL: https://github.com/niksy/babel-plugin-transform-object-hasown
- Owner: niksy
- License: mit
- Created: 2021-05-26T10:51:04.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2021-06-05T20:43:22.000Z (over 3 years ago)
- Last Synced: 2024-10-18T04:06:01.809Z (28 days ago)
- Language: JavaScript
- Size: 9.77 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.md
Awesome Lists containing this project
README
# babel-plugin-transform-object-hasown
[![Build Status][ci-img]][ci]
Babel plugin for transforming
[`Object.hasOwn`](https://github.com/tc39/proposal-accessible-object-hasownproperty).## Install
```sh
npm install babel-plugin-transform-object-hasown --save-dev
```## Usage
Use it via available [plugin activation options][babel-plugins].
For `.babelrc` file:
```json
{
"plugins": ["babel-plugin-transform-object-hasown"]
}
```Then, in your code:
```js
const object = {};if (Object.hasOwn(object, 'becky')) {
console.log('has property becky');
}
```After transformation:
```js
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](test/fixtures/all.js) and
[expected](test/fixtures/all.expected.js)) for more examples.## Caveats
Will only work with code of the form `Object.hasOwn` or `Object['hasOwn']`.
## License
MIT © [Ivan Nikolić](http://ivannikolic.com)
[ci]: https://travis-ci.com/niksy/babel-plugin-transform-object-hasown
[ci-img]: https://travis-ci.com/niksy/babel-plugin-transform-object-hasown.svg?branch=master
[babel-plugins]: http://babeljs.io/docs/plugins/