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.

50 lines
1.8 KiB

  1. # get-proto <sup>[![Version Badge][npm-version-svg]][package-url]</sup>
  2. [![github actions][actions-image]][actions-url]
  3. [![coverage][codecov-image]][codecov-url]
  4. [![License][license-image]][license-url]
  5. [![Downloads][downloads-image]][downloads-url]
  6. [![npm badge][npm-badge-png]][package-url]
  7. Robustly get the [[Prototype]] of an object. Uses the best available method.
  8. ## Getting started
  9. ```sh
  10. npm install --save get-proto
  11. ```
  12. ## Usage/Examples
  13. ```js
  14. const assert = require('assert');
  15. const getProto = require('get-proto');
  16. const a = { a: 1, b: 2, [Symbol.toStringTag]: 'foo' };
  17. const b = { c: 3, __proto__: a };
  18. assert.equal(getProto(b), a);
  19. assert.equal(getProto(a), Object.prototype);
  20. assert.equal(getProto({ __proto__: null }), null);
  21. ```
  22. ## Tests
  23. Clone the repo, `npm install`, and run `npm test`
  24. [package-url]: https://npmjs.org/package/get-proto
  25. [npm-version-svg]: https://versionbadg.es/ljharb/get-proto.svg
  26. [deps-svg]: https://david-dm.org/ljharb/get-proto.svg
  27. [deps-url]: https://david-dm.org/ljharb/get-proto
  28. [dev-deps-svg]: https://david-dm.org/ljharb/get-proto/dev-status.svg
  29. [dev-deps-url]: https://david-dm.org/ljharb/get-proto#info=devDependencies
  30. [npm-badge-png]: https://nodei.co/npm/get-proto.png?downloads=true&stars=true
  31. [license-image]: https://img.shields.io/npm/l/get-proto.svg
  32. [license-url]: LICENSE
  33. [downloads-image]: https://img.shields.io/npm/dm/get-proto.svg
  34. [downloads-url]: https://npm-stat.com/charts.html?package=get-proto
  35. [codecov-image]: https://codecov.io/gh/ljharb/get-proto/branch/main/graphs/badge.svg
  36. [codecov-url]: https://app.codecov.io/gh/ljharb/get-proto/
  37. [actions-image]: https://img.shields.io/endpoint?url=https://github-actions-badge-u3jn4tfpocch.runkit.sh/ljharb/get-proto
  38. [actions-url]: https://github.com/ljharb/get-proto/actions