https://github.com/fibo/not-defined
checks if foo is not defined, i.e. undefined, null, an empty string, array, object or NaN
https://github.com/fibo/not-defined
Last synced: 9 months ago
JSON representation
checks if foo is not defined, i.e. undefined, null, an empty string, array, object or NaN
- Host: GitHub
- URL: https://github.com/fibo/not-defined
- Owner: fibo
- License: mit
- Created: 2016-02-05T09:03:11.000Z (about 10 years ago)
- Default Branch: main
- Last Pushed: 2024-05-26T10:52:07.000Z (almost 2 years ago)
- Last Synced: 2025-05-16T03:38:59.538Z (11 months ago)
- Language: JavaScript
- Homepage:
- Size: 23.4 KB
- Stars: 5
- Watchers: 2
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-micro-npm-packages-zh - not-defined - 检查 输出 是否未定义,即undefined, null, 空的 string, array or object. (模块 / 其他)
- awesome-micro-npm-packages - not-defined - Checks if foo is not defined, i.e. undefined, null, an empty string, array or object. (Modules / Other)
- fucking-awesome-micro-npm-packages - not-defined - Checks if foo is not defined, i.e. undefined, null, an empty string, array or object. (Modules / Other)
- awesome-micro-npm-packages - not-defined - Checks if foo is not defined, i.e. undefined, null, an empty string, array or object. (Modules / Other)
README
# not-defined
> checks if foo is not defined, i.e. undefined, null, an empty string, array, object or NaN
## Installation
```bash
npm install not-defined
```
## Pros
* Type less.
* Better readability (even your boss will understand your code ^:).
* Can save bytes in your builds.
* Easier to autocomplete in editors (for instance easier than `typeof foo === 'undefined'`).
## Usage
This snippet of code
```javascript
import notDefined from 'not-defined'
if (notDefined(foo)) {
// do something, usually throw a TypeError
}
```
is equivalent to the following pseudocode
```
if (foo is not defined, i.e. is null, undefined, NaN, an empty string, array or object) {
// do something, usually throw a TypeError
}
```
You can also use a shorter but still semantic form like
```javascript
import no from 'not-defined'
if (no(foo)) {
// do something, usually throw a TypeError
}
```
Follows a list of [tested examples](https://github.com/fibo/not-defined/blob/master/test.js)
```javascript
no() // true
no(undefined) // true
no(null) // true
no('') // true
no([]) // true
no({}) // true
no(NaN) // true
no(0) // false
no(true) // false
no(false) // false
no('string') // false
no(['foo']) // false
no({ foo: true }) // false
no(42) // false
no(Infinity) // false
no(function () { return 1 }) // false
```
## License
[MIT](http://g14n.info/mit-license)