项目作者: risan

项目描述 :
Check if a value is empty or not.
高级语言: JavaScript
项目地址: git://github.com/risan/is-empty.git
创建时间: 2018-11-24T19:28:05Z
项目社区:https://github.com/risan/is-empty

开源协议:MIT License

下载


Is Empty

Build Status
Test Covarage
@risan/is-empty"">Latest Version

Check if a value is empty or not.

Installation

  1. $ npm install @risan/is-empty

CDN

The library is available over a CDN:

  1. <script src="https://unpkg.com/@risan/is-empty@latest/dist/is-empty.umd.js"></script>
  2. <!-- Or the minified version -->
  3. <script src="https://unpkg.com/@risan/is-empty@latest/dist/is-empty.umd.min.js"></script>

Usage

  1. const isEmpty = require("@risan/is-empty");
  2. // The following statements will return TRUE:
  3. isEmpty(null);
  4. isEmpty(undefined);
  5. isEmpty(NaN);
  6. // An empty string is considered empty, return TRUE.
  7. isEmpty("");
  8. isEmpty(" ");
  9. isEmpty("\n\t");
  10. // An object with no properties is considered empty, return TRUE.
  11. isEmpty({});
  12. isEmpty(new Object());
  13. isEmpty(Object.create(null));
  14. // Array, Map, or Set with no items is considered empty, return TRUE.
  15. isEmpty([]);
  16. isEmpty(new Map());
  17. isEmpty(new Set());
  18. // The following statements will return FALSE:
  19. isEmpty(true);
  20. isEmpty(false);
  21. isEmpty(0);
  22. isEmpty(-123.5);
  23. isEmpty(Infinity);
  24. isEmpty([1, 2, 3]);
  25. isEmpty({ foo: "bar" });
  26. isEmpty(new Set([1, 2]));
  27. const myMap = new Map();
  28. myMap.set("foo", "bar");
  29. isEmpty(myMap);
  30. // Function will always return FALSE:
  31. const myFunction = () => "foo";
  32. isPlainObj(myFunction);
  33. isEmpty(parseInt);
  34. // Instance of class will always return FALSE:
  35. class Person {}
  36. isPlainObj(new Person());
  37. isEmpty(new Date());

If you load the library directly on the browser, it’s available under the isEmpty name.

  1. window.isEmpty(null); // TRUE
  2. window.isEmpty(" "); // TRUE
  3. window.isEmpty(false); // FALSE
  4. window.isEmpty(new Date()); // FALSE

License

MIT © Risan Bagja Pradana