amp-is-object: Object Type Checker

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

The `amp-is-object` package provides a minimalist utility function to reliably determine if a given JavaScript value is an object. It is part of the `ampersand.js` ecosystem, a loosely coupled, non-frameworky collection of modules for client-side applications, often drawing inspiration from Backbone.js. Crucially, this package is unrelated to Google's Accelerated Mobile Pages (AMP Project), which is a distinct initiative for web content optimization. Currently at version 1.0.1, `amp-is-object` is a stable, simple module with a focused scope. The broader `ampersand.js` project appears to be in a maintenance state with infrequent updates, meaning this utility package is largely static, offering consistent behavior without active feature development or frequent new releases. Its primary differentiation lies in its minimal footprint and specific role within the `ampersand.js` context, providing a core type-checking function.

error ReferenceError: require is not defined in ES module scope
cause Attempting to use `require()` in a JavaScript file that is being interpreted as an ES Module (e.g., due to `"type": "module"` in `package.json`).
fix
For basic CJS compatibility in ESM, you can typically use import { createRequire } from 'module'; const require = createRequire(import.meta.url); then const isObject = require('amp-is-object');. Alternatively, use a build tool that handles CJS-to-ESM conversion.
error TypeError: (0, _ampIsObject.default) is not a function
cause This error occurs when an ES Module `import isObject from 'amp-is-object';` attempts to treat the CommonJS module's `module.exports` as a default export, but the export is not structured that way, or the transpiler/runtime incorrectly handles it.
fix
Since amp-is-object likely exports a single function directly via module.exports = function() { ... }, the correct (though sometimes still problematic in pure ESM) import if you absolutely must use import syntax would be import isObject = require('amp-is-object'); (TypeScript specific) or import * as isObject from 'amp-is-object'; followed by isObject.default() or isObject() depending on build/runtime behavior, but require is safest.
gotcha This package, `amp-is-object`, is part of the `ampersand.js` project and is NOT related to Google's Accelerated Mobile Pages (AMP Project / amp.dev). The names are coincidental, but the technologies and ecosystems are completely different. Do not confuse them.
fix Verify the package origin (`ampersandjs` on GitHub) and context (a client-side JS framework utility) to ensure it aligns with your project's needs, distinct from Google AMP.
gotcha The `amp-is-object` package is implemented as a CommonJS module. In modern Node.js environments configured for ES Modules (`"type": "module"` in `package.json`), a direct `require()` call might lead to errors, or `import` statements might fail to resolve the module correctly without specific interoperability settings or transpilation.
fix In ES Module contexts, consider using dynamic import (`import('amp-is-object').then(mod => mod)`) or ensure your build tools (e.g., Webpack, Rollup, Babel) are configured to handle CommonJS modules.
gotcha This package, being at version 1.0.1 and part of an older, largely maintenance-mode ecosystem (`ampersand.js`), is unlikely to receive new features, significant bug fixes, or updates to modern JavaScript paradigms (e.g., native ESM support, TypeScript definitions). It is stable but static.
fix Consider if a more actively maintained and modern utility for object type checking (e.g., from Lodash, Underscore, or a dedicated modern small utility) would better suit long-term project needs, especially for new projects.
npm install amp-is-object
yarn add amp-is-object
pnpm add amp-is-object

Demonstrates how to import and use the `isObject` function to check various JavaScript values.

const isObject = require('amp-is-object');

console.log('Is {} an object?', isObject({})); // Expected: true
console.log('Is [] an object?', isObject([])); // Expected: true (arrays are objects in JS)
console.log('Is null an object?', isObject(null)); // Expected: false (common JS gotcha)
console.log('Is "hello" an object?', isObject('hello')); // Expected: false
console.log('Is 123 an object?', isObject(123)); // Expected: false
console.log('Is undefined an object?', isObject(undefined)); // Expected: false
console.log('Is new Date() an object?', isObject(new Date())); // Expected: true