amp-is-object: Object Type Checker
raw JSON →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.
Common errors
error ReferenceError: require is not defined in ES module scope ↓
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 ↓
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. Warnings
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. ↓
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. ↓
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. ↓
Install
npm install amp-is-object yarn add amp-is-object pnpm add amp-is-object Imports
- isObject wrong
import isObject from 'amp-is-object'; import { isObject } from 'amp-is-object';correctconst isObject = require('amp-is-object');
Quickstart
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