https://github.com/maxmellon/babel-plugin-transform-isnil
[DEPLECATED] RIP :blue_heart: Replace the comparing of null or undefined with isNil :b:
https://github.com/maxmellon/babel-plugin-transform-isnil
Last synced: 8 months ago
JSON representation
[DEPLECATED] RIP :blue_heart: Replace the comparing of null or undefined with isNil :b:
- Host: GitHub
- URL: https://github.com/maxmellon/babel-plugin-transform-isnil
- Owner: MaxMEllon
- License: mit
- Created: 2016-05-02T04:57:13.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2018-02-21T11:37:34.000Z (over 8 years ago)
- Last Synced: 2025-03-12T13:36:21.817Z (over 1 year ago)
- Language: JavaScript
- Homepage:
- Size: 38.1 KB
- Stars: 8
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# babel-plugin-transform-isNil is dead
Coming new syntax as [proposal-optional-chaining](https://github.com/tc39/proposal-optional-chaining) on [babel7](https://github.com/babel/babel/wiki/Babel-7)
**Which is only compatible with babel6**
Please use **[@babel/plugin-proposal-optional-chaining](https://github.com/babel/babel/tree/master/packages/babel-plugin-proposal-optional-chaining)**
## babel-plugin-transform-isNil
### About
I like Existential Operator in `CoffeeScript`.
CoffeeScript can be written as follows:
```coffee
hoge?
```
Become to `JavaScript`
```js
hoge == null
```
Same meaning
```
hoge === null || hoge === undefined
```
I want to do the same thing in `JavaScript`.
### Installation
```bash
$ npm install --save babel-plugin-transform-isnil
```
Example
---
**In**
```js
if (foo.isNil) {
console.log('foo is null or undefined');
}
```
**Out**
```js
if (foo === null || foo === undefined) {
console.log('foo is null or undefined');
}
```
**In**
```js
if (hoge.poge.isNil && foo.bar.isNil) {
console.log('hoge.poge and foo.bar is null or undefined');
}
```
**Out**
```js
if ((hoge.poge === null || hoge.poge === undefined) && (foo.bar === null || foo.bar === undefined)) {
console.log('hoge.poge and foo.bar is null or undefined');
}
```
**In**
```js
if (hoge.poge().isNil) {
console.log('returned value of hoge.poge() function is null or undefined');
}
```
**Out**
```js
if (hoge.poge() === null || hoge.poge() === undefined) {
console.log('returned value of hoge.poge() function is null or undefined');
}
```
**In**
```js
if (hoge.poge(hoge).isNil) {
console.log('returned value of hoge.poge() function is null or undefined');
}
```
**Out**
```js
if (hoge.poge(hoge) === null || hoge.poge(hoge) === undefined) {
console.log('returned value of hoge.poge() function is null or undefined');
}
```
### Usage
#### Via `.babelrc`
```json
{
"plugins": ["babel-plugin-transform-isnil"]
}
```
### Development
Requirement global
* Node v4 or above
```bash
$ git clone https://github.com/MaxMEllon/babel-plugin-transform-isNil
$ cd babel-plugin-transform-isNil
$ npm install
$ npm test
```
### Special Thanks
- [@shnhrrsn](https://github.com/shnhrrsn)
LICENSE
---
[MIT](./LICENSE.txt)