obj-props: JavaScript Object Property Lists
obj-props is a utility package that provides a structured JSON file containing lists of properties for various built-in JavaScript objects. It offers a static dataset, mapping JavaScript constructor names (e.g., "Array", "Boolean", "Object") to an array of their respective property names. The current stable version is 2.0.0. Due to its nature as a static data provider, the package follows an infrequent release cadence, with new versions primarily released when new ECMAScript features introduce new built-in properties or when the underlying data source is updated. It differentiates itself by being a pre-generated, easily consumable JSON resource, forked from Sindre Sorhus's `proto-props`, making it suitable for environments where runtime reflection or dynamic property enumeration might be undesirable or overkill. This makes it valuable for static analysis, documentation, or environments with restricted execution contexts.
Common errors
-
ERR_REQUIRE_ESM
cause Attempting to import `obj-props` using `require()` in an ES module context or when the package is primarily designed as an ES module, which prevents synchronous `require` calls.fixUse the ES module `import` syntax: `import objProps from 'obj-props';` -
TypeError: objProps is not a function
cause Mistakenly treating the `objProps` export as a callable function or class constructor instead of a plain JavaScript object that serves as a data map.fixAccess `objProps` directly as an object, for example, `objProps.Array` or `Object.keys(objProps)`. -
Property 'X' does not exist on type 'Record<string, string[]>' (TypeScript error)
cause Attempting to access a property (e.g., `objProps.MyCustomObject`) that is not explicitly part of the `objProps` object's inferred type or included in the static JSON data, which primarily covers built-in JavaScript intrinsics.fixAccess the property with optional chaining (`objProps.MyCustomObject?.propertyName`) or use a type assertion (`(objProps as Record<string, string[]>).MyCustomObject`) if you are confident it exists, or check `Object.keys(objProps)` for available properties. Remember it only contains built-in objects.
Warnings
- breaking The package explicitly requires Node.js version 18.0.0 or higher. Installation or execution in older Node.js environments will fail due to engine restrictions.
- breaking This package is a fork of Sindre Sorhus's `proto-props`. While it offers similar functionality, there may be divergences in the data structure, the set of covered properties, or future maintenance. Users migrating from `proto-props` should carefully review the contents and changelog for `obj-props` to understand any behavioral or data differences.
- breaking As a major version (`2.0.0`), there may be breaking changes in the structure or content of the `objProps` data object compared to previous major versions. Always consult the release notes when upgrading between major versions.
- gotcha The `obj-props` package provides a static snapshot of JavaScript object properties. Its data is generated at build time (via `npm run generate`) and does not dynamically reflect runtime changes to object prototypes or properties in your specific JavaScript environment. New ECMAScript features or host object properties will only be included in new package versions.
Install
-
npm install obj-props -
yarn add obj-props -
pnpm add obj-props
Imports
- objProps
import objProps from 'obj-props';
- objProps
const objProps = require('obj-props'); - Array, Object (example named exports)
import { Array, Object } from 'obj-props';
Quickstart
import objProps from 'obj-props';
// objProps contains a mapping of JavaScript intrinsic object names to their properties.
// For example, to see properties of the Array constructor:
console.log('Array Constructor Properties:', objProps.Array);
// To access properties of the Object constructor:
console.log('Object Constructor Properties:', objProps.Object);
// The entire data structure can be iterated or accessed directly.
// For instance, to list all known intrinsic objects and their property counts:
console.log('\n--- All Intrinsic Objects and Property Counts ---');
for (const constructorName in objProps) {
if (Object.prototype.hasOwnProperty.call(objProps, constructorName)) {
const properties = objProps[constructorName];
console.log(`${constructorName}: ${properties.length} properties`);
}
}
// Example: Check if 'Promise' properties are listed and access them safely
const promiseProps = objProps.Promise;
if (promiseProps) {
console.log('\nPromise Constructor Properties (first 3):', promiseProps.slice(0, 3));
} else {
console.log('\nPromise properties not explicitly listed or available in this version.');
}