市场夺宝奇兵
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

58 lines
1.2 KiB

  1. # is-plain-obj
  2. > Check if a value is a plain object
  3. An object is plain if it's created by either `{}`, `new Object()`, or `Object.create(null)`.
  4. ## Install
  5. ```
  6. $ npm install is-plain-obj
  7. ```
  8. ## Usage
  9. ```js
  10. import isPlainObject from 'is-plain-obj';
  11. import {runInNewContext} from 'node:vm';
  12. isPlainObject({foo: 'bar'});
  13. //=> true
  14. isPlainObject(new Object());
  15. //=> true
  16. isPlainObject(Object.create(null));
  17. //=> true
  18. // This works across realms
  19. isPlainObject(runInNewContext('({})'));
  20. //=> true
  21. isPlainObject([1, 2, 3]);
  22. //=> false
  23. class Unicorn {}
  24. isPlainObject(new Unicorn());
  25. //=> false
  26. isPlainObject(Math);
  27. //=> false
  28. ```
  29. ## Related
  30. - [is-obj](https://github.com/sindresorhus/is-obj) - Check if a value is an object
  31. - [is](https://github.com/sindresorhus/is) - Type check values
  32. ---
  33. <div align="center">
  34. <b>
  35. <a href="https://tidelift.com/subscription/pkg/npm-is-plain-obj?utm_source=npm-is-plain-obj&utm_medium=referral&utm_campaign=readme">Get professional support for this package with a Tidelift subscription</a>
  36. </b>
  37. <br>
  38. <sub>
  39. Tidelift helps make open source sustainable for maintainers while giving companies<br>assurances about security, maintenance, and licensing for their dependencies.
  40. </sub>
  41. </div>