Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
object-keys
Advanced tools
An Object.keys replacement, in case Object.keys is not available. From https://github.com/es-shims/es5-shim
The object-keys npm package is a utility that provides a shim for the Object.keys method, which returns an array of a given object's own enumerable property names. It is particularly useful for environments that do not support the native Object.keys method, such as older versions of JavaScript engines.
Shim for Object.keys
Provides a cross-browser implementation of Object.keys to retrieve the keys of an object.
var keys = require('object-keys');
var obj = { a: 1, b: 2, c: 3 };
console.log(keys(obj)); // ['a', 'b', 'c']
Lodash is a popular utility library that includes a method called _.keys, which is similar to object-keys. It provides a more robust solution for getting the keys of an object, handling edge cases and supporting a wider range of environments, but it is part of a larger library which may be more than needed if only this functionality is required.
Core-js is a modular standard library for JavaScript, which includes polyfills for many ECMAScript features. It offers a polyfill for Object.keys, among many other features. It is more comprehensive than object-keys, but also larger in size, which might not be ideal for projects looking to minimize dependencies.
An Object.keys shim. Invoke its "shim" method to shim Object.keys if it is unavailable.
Most common usage:
var keys = Object.keys || require('object-keys');
var keys = require('object-keys');
var assert = require('assert');
var obj = {
a: true,
b: true,
c: true
};
assert.deepEqual(keys(obj), ['a', 'b', 'c']);
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));
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));
Implementation taken directly from es5-shim, with modifications, including from lodash.
Simply clone the repo, npm install
, and run npm test
FAQs
An Object.keys replacement, in case Object.keys is not available. From https://github.com/es-shims/es5-shim
The npm package object-keys receives a total of 14,016,662 weekly downloads. As such, object-keys popularity was classified as popular.
We found that object-keys demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.