amp-has utility (re-export of lodash.has)

1.0.1 · deprecated · verified Wed Apr 22

The `amp-has` package provides a simple utility function, `has`, designed to check for the existence of nested properties within an object. It is part of the `ampersand.js` ecosystem, which was a collection of loosely coupled JavaScript modules for client-side applications. The package, currently at version 1.0.1, was last updated in April 2016 and is essentially a direct re-export of the `lodash.has` function. Given the minimal activity on the `ampersand.js` project and this specific utility's unmaintained status for many years, its release cadence is effectively ceased. Its key differentiator was its inclusion in the `ampersand.js` modular approach; however, modern applications are strongly advised to use `lodash.has` directly, which is actively maintained and supports contemporary JavaScript module systems.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates importing and using the `has` function to safely check for the existence of nested properties within an object, including null or undefined paths.

const has = require('amp-has');

const user = {
  id: 1,
  name: 'Alice',
  address: {
    street: '123 Main St',
    city: 'Anytown',
    zip: '12345'
  },
  contact: null
};

console.log('User has address.city:', has(user, 'address.city'));
// Expected: true

console.log('User has address.country:', has(user, 'address.country'));
// Expected: false

console.log('User has id:', has(user, 'id'));
// Expected: true

console.log('User has contact.email:', has(user, 'contact.email'));
// Expected: false (handles null paths gracefully)

// For modern usage, it's recommended to use lodash.has directly:
// const lodashHas = require('lodash.has');
// console.log('Using lodash.has directly:', lodashHas(user, 'address.zip'));

view raw JSON →