UNPKG

2.34 kBMarkdownView Raw
1# object.entries <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 ES7 spec-compliant `Object.entries` shim. Invoke its "shim" method to shim `Object.entries` if it is unavailable or noncompliant.
14
15This package implements the [es-shim API](https://github.com/es-shims/api) interface. It works in an ES3-supported environment and complies with the [proposed spec](https://github.com/ljharb/proposal-object-values-entries/blob/master/spec.md#objectentries-o-).
16
17Most common usage:
18```js
19var assert = require('assert');
20var entries = require('object.entries');
21
22var obj = { a: 1, b: 2, c: 3 };
23var expected = [['a', 1], ['b', 2], ['c', 3]];
24
25if (typeof Symbol === 'function' && typeof Symbol() === 'symbol') {
26 // for environments with Symbol support
27 var sym = Symbol();
28 obj[sym] = 4;
29 obj.d = sym;
30 expected.push(['d', sym]);
31}
32
33assert.deepEqual(entries(obj), expected);
34
35if (!Object.entries) {
36 entries.shim();
37}
38
39assert.deepEqual(Object.entries(obj), expected);
40```
41
42## Tests
43Simply clone the repo, `npm install`, and run `npm test`
44
45[package-url]: https://npmjs.com/package/object.entries
46[npm-version-svg]: http://versionbadg.es/es-shims/Object.entries.svg
47[travis-svg]: https://travis-ci.org/es-shims/Object.entries.svg
48[travis-url]: https://travis-ci.org/es-shims/Object.entries
49[deps-svg]: https://david-dm.org/es-shims/Object.entries.svg
50[deps-url]: https://david-dm.org/es-shims/Object.entries
51[dev-deps-svg]: https://david-dm.org/es-shims/Object.entries/dev-status.svg
52[dev-deps-url]: https://david-dm.org/es-shims/Object.entries#info=devDependencies
53[testling-svg]: https://ci.testling.com/es-shims/Object.entries.png
54[testling-url]: https://ci.testling.com/es-shims/Object.entries
55[npm-badge-png]: https://nodei.co/npm/object.entries.png?downloads=true&stars=true
56[license-image]: http://img.shields.io/npm/l/object.entries.svg
57[license-url]: LICENSE
58[downloads-image]: http://img.shields.io/npm/dm/object.entries.svg
59[downloads-url]: http://npm-stat.com/charts.html?package=object.entries