CoolFace
Datasetpublic

basant307/AI_Governance_Project

sourceHugging Faceapache-2.0updated 2mo agoView on Hugging Face
0likes48downloads
result.js57 linesDownload Raw Back to lodash-es
1import castPath from './_castPath.js';2import isFunction from './isFunction.js';3import toKey from './_toKey.js';4 5/**6 * This method is like `_.get` except that if the resolved value is a7 * function it's invoked with the `this` binding of its parent object and8 * its result is returned.9 *10 * @static11 * @since 0.1.012 * @memberOf _13 * @category Object14 * @param {Object} object The object to query.15 * @param {Array|string} path The path of the property to resolve.16 * @param {*} [defaultValue] The value returned for `undefined` resolved values.17 * @returns {*} Returns the resolved value.18 * @example19 *20 * var object = { 'a': [{ 'b': { 'c1': 3, 'c2': _.constant(4) } }] };21 *22 * _.result(object, 'a[0].b.c1');23 * // => 324 *25 * _.result(object, 'a[0].b.c2');26 * // => 427 *28 * _.result(object, 'a[0].b.c3', 'default');29 * // => 'default'30 *31 * _.result(object, 'a[0].b.c3', _.constant('default'));32 * // => 'default'33 */34function result(object, path, defaultValue) {35  path = castPath(path, object);36 37  var index = -1,38      length = path.length;39 40  // Ensure the loop is entered when path is empty.41  if (!length) {42    length = 1;43    object = undefined;44  }45  while (++index < length) {46    var value = object == null ? undefined : object[toKey(path[index])];47    if (value === undefined) {48      index = length;49      value = defaultValue;50    }51    object = isFunction(value) ? value.call(object) : value;52  }53  return object;54}55 56export default result;57 
basant307/AI_Governance_Project · CoolFace