The modern build of lodash's _.keys as a module for creating arrays of own enumerable property names.
npx @tessl/cli install tessl/npm-lodash--keys@3.1.0Lodash Keys is a modularized version of lodash's _.keys functionality that creates an array of the own enumerable property names of an object. It provides a robust implementation with cross-browser compatibility and fallback support for environments without native Object.keys.
npm install lodash.keysvar keys = require('lodash.keys');For ES modules environments:
import keys from 'lodash.keys';var keys = require('lodash.keys');
// Get keys from a plain object
var obj = { 'a': 1, 'b': 2, 'c': 3 };
console.log(keys(obj)); // => ['a', 'b', 'c'] (iteration order is not guaranteed)
// Works with constructor functions
function Foo() {
this.a = 1;
this.b = 2;
}
Foo.prototype.c = 3;
console.log(keys(new Foo)); // => ['a', 'b'] (excludes inherited properties)
// Handles string objects
console.log(keys('hi')); // => ['0', '1']
// Returns empty array for null/undefined
console.log(keys(null)); // => []
console.log(keys(undefined)); // => []Creates an array of the own enumerable property names of an object, excluding inherited properties.
/**
* Creates an array of the own enumerable property names of object.
* Non-object values are coerced to objects.
*
* @param {Object} object The object to query.
* @returns {Array} Returns the array of property names.
*/
function keys(object);Key Features:
Object.keys when available and appropriateUsage Examples:
var keys = require('lodash.keys');
// Plain objects
keys({ 'name': 'John', 'age': 30 }); // => ['name', 'age']
// Arrays (returns string indices)
keys(['a', 'b', 'c']); // => ['0', '1', '2']
// Strings (returns character indices)
keys('hello'); // => ['0', '1', '2', '3', '4']
// Constructor instances (excludes prototype properties)
function Person() {
this.name = 'John';
this.age = 30;
}
Person.prototype.species = 'human';
keys(new Person()); // => ['name', 'age']
// Array-like objects
var arrayLike = { '0': 'a', '1': 'b', 'length': 2 };
keys(arrayLike); // => ['0', '1', 'length']
// Edge cases
keys(null); // => []
keys(undefined); // => []
keys(42); // => [] (number coerced to Number object)
keys(true); // => [] (boolean coerced to Boolean object)This package depends on other modularized lodash utilities:
lodash._getnative (^3.0.0): For getting native method referenceslodash.isarguments (^3.0.0): For detecting arguments objectslodash.isarray (^3.0.0): For detecting arraysThese dependencies are automatically installed and provide specialized functionality for robust object property enumeration across different JavaScript environments.