What is has?
The 'has' npm package is a utility module that provides a function to check if an object has a property with a given key. It is a safer way to check for properties than the built-in JavaScript 'in' operator or property access, as it doesn't check the prototype chain and avoids potential issues with objects that have modified prototypes or lack a prototype altogether.
What are has's main functionalities?
Check for own property
This feature allows you to check if an object has a specific own property. It returns true if the property exists directly on the object, and false otherwise.
const has = require('has');
const obj = { a: 1 };
console.log(has(obj, 'a')); // true
console.log(has(obj, 'b')); // false
Other packages similar to has
lodash.has
Lodash's 'has' function is similar to 'has' in that it checks if a path is a direct property of an object. However, lodash.has also allows checking for deep properties using a dot or array path notation, which 'has' does not support.
object-has-property
This package provides functionality similar to 'has' by checking if an object contains a certain property. The difference is mainly in the implementation and the specific API provided by the package.