Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ljharb/object-keys
Object.keys shim
https://github.com/ljharb/object-keys
ecmascript es-shims es5 javascript keys object polyfill shim
Last synced: 4 days ago
JSON representation
Object.keys shim
- Host: GitHub
- URL: https://github.com/ljharb/object-keys
- Owner: ljharb
- License: mit
- Created: 2013-03-29T18:19:42.000Z (almost 12 years ago)
- Default Branch: main
- Last Pushed: 2022-10-27T21:35:19.000Z (about 2 years ago)
- Last Synced: 2025-01-11T10:13:01.384Z (11 days ago)
- Topics: ecmascript, es-shims, es5, javascript, keys, object, polyfill, shim
- Language: JavaScript
- Homepage:
- Size: 237 KB
- Stars: 45
- Watchers: 7
- Forks: 17
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
- awesome-ponyfills - object-keys - [`Object.keys`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/keys) (Objects)
README
# object-keys [![Version Badge][npm-version-svg]][package-url]
[![github actions][actions-image]][actions-url]
[![coverage][codecov-image]][codecov-url]
[![dependency status][deps-svg]][deps-url]
[![dev dependency status][dev-deps-svg]][dev-deps-url]
[![License][license-image]][license-url]
[![Downloads][downloads-image]][downloads-url][![npm badge][npm-badge-png]][package-url]
An Object.keys shim. Invoke its "shim" method to shim Object.keys if it is unavailable.
Most common usage:
```js
var keys = Object.keys || require('object-keys');
```## Example
```js
var keys = require('object-keys');
var assert = require('assert');
var obj = {
a: true,
b: true,
c: true
};assert.deepEqual(keys(obj), ['a', 'b', 'c']);
``````js
var keys = require('object-keys');
var assert = require('assert');
/* when Object.keys is not present */
delete Object.keys;
var shimmedKeys = keys.shim();
assert.equal(shimmedKeys, keys);
assert.deepEqual(Object.keys(obj), keys(obj));
``````js
var keys = require('object-keys');
var assert = require('assert');
/* when Object.keys is present */
var shimmedKeys = keys.shim();
assert.equal(shimmedKeys, Object.keys);
assert.deepEqual(Object.keys(obj), keys(obj));
```## Source
Implementation taken directly from [es5-shim][es5-shim-url], with modifications, including from [lodash][lodash-url].## Tests
Simply clone the repo, `npm install`, and run `npm test`[package-url]: https://npmjs.org/package/object-keys
[npm-version-svg]: https://versionbadg.es/ljharb/object-keys.svg
[deps-svg]: https://david-dm.org/ljharb/object-keys.svg
[deps-url]: https://david-dm.org/ljharb/object-keys
[dev-deps-svg]: https://david-dm.org/ljharb/object-keys/dev-status.svg
[dev-deps-url]: https://david-dm.org/ljharb/object-keys#info=devDependencies
[es5-shim-url]: https://github.com/es-shims/es5-shim/blob/master/es5-shim.js#L542-589
[lodash-url]: https://github.com/lodash/lodash
[npm-badge-png]: https://nodei.co/npm/object-keys.png?downloads=true&stars=true
[license-image]: https://img.shields.io/npm/l/object-keys.svg
[license-url]: LICENSE
[downloads-image]: https://img.shields.io/npm/dm/object-keys.svg
[downloads-url]: https://npm-stat.com/charts.html?package=object-keys
[codecov-image]: https://codecov.io/gh/ljharb/object-keys/branch/main/graphs/badge.svg
[codecov-url]: https://app.codecov.io/gh/ljharb/object-keys/
[actions-image]: https://img.shields.io/endpoint?url=https://github-actions-badge-u3jn4tfpocch.runkit.sh/ljharb/object-keys
[actions-url]: https://github.com/ljharb/object-keys/actions