UNPKG

2.1 kBMarkdownView Raw
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
12Simply 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
28import isEmpty from "khali";
29
30// Regular stuff
31isEmpty([]); // true
32isEmpty({}); // true
33isEmpty(""); // true
34isEmpty(0); // true
35
36const arr = ["Dhaka", ["Uttara", [1, 2]]];
37const obj = {
38 city: "Dhaka",
39 location: {
40 latitude: "23.809473999508782",
41 longitude: "90.4151957081839",
42 },
43 };
44
45// It works with array or, object
46isEmpty(arr[10]); // true
47isEmpty(obj["capital"]); // true
48
49isEmpty(arr); // false
50isEmpty(obj); // false
51
52// And of course it works with nested values
53isEmpty(arr[0][100]); // true
54isEmpty(obj["location"]["area"]); // true
55
56isEmpty(arr[0][0]); // false
57isEmpty(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`.