1 | # Khali (Khāli; meaning, Empty)
|
2 |
|
3 | [![npm version](https://img.shields.io/npm/v/khali.svg?label=version)](https://www.npmjs.org/package/khali)
|
4 | [![install size](https://packagephobia.now.sh/badge?p=khali)](https://packagephobia.now.sh/result?p=khali)
|
5 | [![npm downloads](https://img.shields.io/npm/dm/khali.svg)](http://npm-stat.com/charts.html?package=khali)
|
6 | [![GitHub issues](https://img.shields.io/github/issues/zanvent/khali)](https://github.com/zanvent/khali/issues)
|
7 | [![GitHub forks](https://img.shields.io/github/forks/zanvent/khali)](https://github.com/zanvent/khali/network)
|
8 | [![GitHub stars](https://img.shields.io/github/stars/zanvent/khali)](https://github.com/zanvent/khali/stargazers)
|
9 | [![GitHub license](https://img.shields.io/github/license/zanvent/khali)](https://github.com/zanvent/khali/blob/master/LICENSE)
|
10 | [![Twitter](https://img.shields.io/twitter/url?label=Share&style=social&url=https%3A%2F%2Fgithub.com%2Fzanvent%2Fkhali)](https://twitter.com/intent/tweet?text=Wow:&url=https%3A%2F%2Fgithub.com%2Fzanvent%2Fkhali)
|
11 |
|
12 | Simply check if your array, object, nested stuff, string, number, etc are empty or not.
|
13 |
|
14 | ## Installation
|
15 |
|
16 | - with npm
|
17 | `npm install khali`
|
18 | - with yarn
|
19 | `yarn add khali`
|
20 | - with pnpm
|
21 | `pnpm install khali`
|
22 | - with bun
|
23 | `bun add khali`
|
24 |
|
25 | ## Usage examples
|
26 |
|
27 | ```js
|
28 | import isEmpty from "khali";
|
29 |
|
30 | // Regular stuff
|
31 | isEmpty([]); // true
|
32 | isEmpty({}); // true
|
33 | isEmpty(""); // true
|
34 | isEmpty(0); // true
|
35 |
|
36 | const arr = ["Dhaka", ["Uttara", [1, 2]]];
|
37 | const obj = {
|
38 | city: "Dhaka",
|
39 | location: {
|
40 | latitude: "23.809473999508782",
|
41 | longitude: "90.4151957081839",
|
42 | },
|
43 | };
|
44 |
|
45 | // It works with array or, object
|
46 | isEmpty(arr[10]); // true
|
47 | isEmpty(obj["capital"]); // true
|
48 |
|
49 | isEmpty(arr); // false
|
50 | isEmpty(obj); // false
|
51 |
|
52 | // And of course it works with nested values
|
53 | isEmpty(arr[0][100]); // true
|
54 | isEmpty(obj["location"]["area"]); // true
|
55 |
|
56 | isEmpty(arr[0][0]); // false
|
57 | isEmpty(obj.city); // false
|
58 | ```
|
59 |
|
60 | ## API
|
61 |
|
62 | ### isEmpty(value)
|
63 |
|
64 | - Returns `boolean`
|
65 | - Returns `true` if the `value` is empty else `false`.
|