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.

76 lines
2.1 KiB

  1. #object-keys <sup>[![Version Badge][2]][1]</sup>
  2. [![Build Status][3]][4]
  3. [![dependency status][5]][6]
  4. [![dev dependency status][7]][8]
  5. [![License][license-image]][license-url]
  6. [![Downloads][downloads-image]][downloads-url]
  7. [![npm badge][13]][1]
  8. [![browser support][9]][10]
  9. An Object.keys shim. Invoke its "shim" method to shim Object.keys if it is unavailable.
  10. Most common usage:
  11. ```js
  12. var keys = Object.keys || require('object-keys');
  13. ```
  14. ## Example
  15. ```js
  16. var keys = require('object-keys');
  17. var assert = require('assert');
  18. var obj = {
  19. a: true,
  20. b: true,
  21. c: true
  22. };
  23. assert.deepEqual(keys(obj), ['a', 'b', 'c']);
  24. ```
  25. ```js
  26. var keys = require('object-keys');
  27. var assert = require('assert');
  28. /* when Object.keys is not present */
  29. delete Object.keys;
  30. var shimmedKeys = keys.shim();
  31. assert.equal(shimmedKeys, keys);
  32. assert.deepEqual(Object.keys(obj), keys(obj));
  33. ```
  34. ```js
  35. var keys = require('object-keys');
  36. var assert = require('assert');
  37. /* when Object.keys is present */
  38. var shimmedKeys = keys.shim();
  39. assert.equal(shimmedKeys, Object.keys);
  40. assert.deepEqual(Object.keys(obj), keys(obj));
  41. ```
  42. ## Source
  43. Implementation taken directly from [es5-shim][11], with modifications, including from [lodash][12].
  44. ## Tests
  45. Simply clone the repo, `npm install`, and run `npm test`
  46. [1]: https://npmjs.org/package/object-keys
  47. [2]: http://vb.teelaun.ch/ljharb/object-keys.svg
  48. [3]: https://travis-ci.org/ljharb/object-keys.svg
  49. [4]: https://travis-ci.org/ljharb/object-keys
  50. [5]: https://david-dm.org/ljharb/object-keys.svg
  51. [6]: https://david-dm.org/ljharb/object-keys
  52. [7]: https://david-dm.org/ljharb/object-keys/dev-status.svg
  53. [8]: https://david-dm.org/ljharb/object-keys#info=devDependencies
  54. [9]: https://ci.testling.com/ljharb/object-keys.png
  55. [10]: https://ci.testling.com/ljharb/object-keys
  56. [11]: https://github.com/es-shims/es5-shim/blob/master/es5-shim.js#L542-589
  57. [12]: https://github.com/bestiejs/lodash
  58. [13]: https://nodei.co/npm/object-keys.png?downloads=true&stars=true
  59. [license-image]: http://img.shields.io/npm/l/object-keys.svg
  60. [license-url]: LICENSE
  61. [downloads-image]: http://img.shields.io/npm/dm/object-keys.svg
  62. [downloads-url]: http://npm-stat.com/charts.html?package=object-keys