amp-keys: Object Keys Utility

raw JSON →
1.0.1 verified Wed Apr 22 auth: no javascript abandoned

amp-keys is a minimalist JavaScript utility module, currently at version 1.0.1. It provides a single `keys` function designed to mimic the functionality of `Object.keys`. This package originates from the Ampersand.js project, an older, modular client-side framework that emphasized loosely coupled components. Given that `amp-keys` was last published many years ago (approximately nine years ago, with its parent Ampersand.js last seeing activity around December 2022) and the broader Ampersand.js ecosystem appears to be largely unmaintained, this module can be considered stable but effectively abandoned. Its primary utility was likely for older JavaScript environments that lacked native `Object.keys` support or to provide API consistency within the Ampersand.js application architecture. For modern JavaScript development, relying on the native `Object.keys` is universally preferred, rendering this package largely redundant. Its release cadence was minimal, likely only seeing updates to align with the Ampersand.js framework's initial stable releases.

error TypeError: (0 , amp_keys_1.keys) is not a function
cause Attempting to use ES module named import syntax (`import { keys } from 'amp-keys';`) when the package is a CommonJS module exporting a single function as its default.
fix
Use CommonJS require to import the default export: const keys = require('amp-keys');
error TypeError: ampKeys is not a function
cause Incorrectly destructuring the CommonJS module import, assuming a named export when the module exports a single function as its default (e.g., `const { ampKeys } = require('amp-keys');`).
fix
The module exports the function directly. Import it as a single variable: const ampKeys = require('amp-keys');
breaking This package is effectively abandoned. There will be no further updates, bug fixes, or security patches. It is not compatible with modern JavaScript module systems (ESM) without specific CommonJS interop mechanisms or transpilation.
fix Migrate to native `Object.keys()` for all modern JavaScript environments. For extremely old environments, consider a modern polyfill or bundler configuration.
gotcha The functionality provided by `amp-keys` is natively available in all modern JavaScript environments (ES5 and above) via `Object.keys()`. Using this package introduces unnecessary overhead and a dependency for already available functionality.
fix Replace `require('amp-keys')(obj)` with `Object.keys(obj)` directly.
gotcha This package is a CommonJS module. Direct ES module `import` statements will not work as expected in a native ESM context (e.g., Node.js with type: 'module') unless transpiled or explicit CommonJS interop is used, which is not recommended for an abandoned package.
fix If absolutely necessary to use in an ESM context, wrap it in a compatibility layer or use dynamic `import()` for CJS modules (e.g., `const getKeys = await import('amp-keys'); const keys = getKeys.default;`), but migrating to `Object.keys()` is strongly advised.
npm install amp-keys
yarn add amp-keys
pnpm add amp-keys

Demonstrates how to import the `keys` function using CommonJS `require` and use it to retrieve the enumerable own property names of various objects.

const getKeys = require('amp-keys');

const myObject = {
  name: 'Alice',
  age: 30,
  city: 'New York'
};

// Get own enumerable property names
const objectKeys = getKeys(myObject);
console.log('Keys of myObject:', objectKeys); // Expected: ['name', 'age', 'city']

const emptyObject = {};
const emptyKeys = getKeys(emptyObject);
console.log('Keys of emptyObject:', emptyKeys); // Expected: []

// Demonstrates Object.keys-like behavior (does not include prototype properties)
function ProtoExample() {
  this.ownProperty = 'foo';
}
ProtoExample.prototype.protoProperty = 'bar';

const instance = new ProtoExample();
const instanceKeys = getKeys(instance);
console.log('Keys of instance (own properties only):', instanceKeys); // Expected: ['ownProperty']