react / wstein / node_modules / jest-cli / node_modules / istanbul / node_modules / js-yaml / node_modules / argparse / node_modules / lodash / object / has.js
80742 viewsvar baseGet = require('../internal/baseGet'),1baseSlice = require('../internal/baseSlice'),2isArguments = require('../lang/isArguments'),3isArray = require('../lang/isArray'),4isIndex = require('../internal/isIndex'),5isKey = require('../internal/isKey'),6isLength = require('../internal/isLength'),7last = require('../array/last'),8toPath = require('../internal/toPath');910/** Used for native method references. */11var objectProto = Object.prototype;1213/** Used to check objects for own properties. */14var hasOwnProperty = objectProto.hasOwnProperty;1516/**17* Checks if `path` is a direct property.18*19* @static20* @memberOf _21* @category Object22* @param {Object} object The object to query.23* @param {Array|string} path The path to check.24* @returns {boolean} Returns `true` if `path` is a direct property, else `false`.25* @example26*27* var object = { 'a': { 'b': { 'c': 3 } } };28*29* _.has(object, 'a');30* // => true31*32* _.has(object, 'a.b.c');33* // => true34*35* _.has(object, ['a', 'b', 'c']);36* // => true37*/38function has(object, path) {39if (object == null) {40return false;41}42var result = hasOwnProperty.call(object, path);43if (!result && !isKey(path)) {44path = toPath(path);45object = path.length == 1 ? object : baseGet(object, baseSlice(path, 0, -1));46if (object == null) {47return false;48}49path = last(path);50result = hasOwnProperty.call(object, path);51}52return result || (isLength(object.length) && isIndex(path, object.length) &&53(isArray(object) || isArguments(object)));54}5556module.exports = has;575859