amp-keys: Object Keys Utility
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.
Common errors
-
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.fixUse CommonJS `require` to import the default export: `const keys = require('amp-keys');` -
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');`).fixThe module exports the function directly. Import it as a single variable: `const ampKeys = require('amp-keys');`
Warnings
- 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.
- 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.
- 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.
Install
-
npm install amp-keys -
yarn add amp-keys -
pnpm add amp-keys
Imports
- keys
import { keys } from 'amp-keys';const keys = require('amp-keys'); - keys (via destructuring)
const { keys } = require('amp-keys');const getObjectKeys = require('amp-keys'); const keys = getObjectKeys; // The function is the default export
Quickstart
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']