UNPKG

@newdash/newdash

Version:

javascript/typescript utility library

38 lines (37 loc) 1.17 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.property = void 0; const baseProperty_1 = __importDefault(require("./.internal/baseProperty")); const basePropertyDeep_1 = __importDefault(require("./.internal/basePropertyDeep")); const isKey_1 = __importDefault(require("./.internal/isKey")); const toKey_1 = __importDefault(require("./.internal/toKey")); /** * Creates a function that returns the value at `path` of a given object. * * @since 5.0.0 * @category Util * @param path The path of the property to get. * @example * * ```js * const objects = [ * { 'a': { 'b': 2 } }, * { 'a': { 'b': 1 } } * ] * * map(objects, property('a.b')) * // => [2, 1] * * map(sortBy(objects, property(['a', 'b'])), 'a.b') * // => [1, 2] * ``` */ function property(path) { // @ts-ignore return (0, isKey_1.default)(path) ? (0, baseProperty_1.default)((0, toKey_1.default)(path)) : (0, basePropertyDeep_1.default)(path); } exports.property = property; exports.default = property;