UNPKG

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