UNPKG

has-util

Version:

Check if an object has a given key.

30 lines (22 loc) 769 B
(function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : typeof define === 'function' && define.amd ? define(factory) : (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.has = factory()); })(this, (function () { 'use strict'; const has = (obj, path) => obj != null && Object.prototype.hasOwnProperty.call(obj, path); var hasUtil = (obj, path) => { if (!Array.isArray(path)) { return has(obj, path); } const { length } = path; for (let i = 0; i < length; i++) { const key = path[i]; if (obj == null || !Object.prototype.hasOwnProperty.call(obj, key)) { return false; } obj = obj[key]; } return !!length; }; return hasUtil; }));