@newdash/newdash
Version:
javascript/typescript utility library
38 lines (37 loc) • 1.25 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.pickBy = void 0;
// @ts-nocheck
const map_1 = __importDefault(require("./map"));
const basePickBy_1 = __importDefault(require("./.internal/basePickBy"));
const getAllKeysIn_1 = __importDefault(require("./.internal/getAllKeysIn"));
/**
* Creates an object composed of the `object` properties `predicate` returns
* truthy for. The predicate is invoked with two arguments: (value, key).
*
* @since 5.7.0
* @category Object
* @param object The source object.
* @param predicate The function invoked per property.
* @returns Returns the new object.
* @example
*
* ```js
* const object = { 'a': 1, 'b': '2', 'c': 3 }
*
* pickBy(object, isNumber)
* // => { 'a': 1, 'c': 3 }
* ```
*/
function pickBy(object, predicate) {
if (object == null) {
return {};
}
const props = (0, map_1.default)((0, getAllKeysIn_1.default)(object), (prop) => [prop]);
return (0, basePickBy_1.default)(object, props, (value, path) => predicate(value, path[0]));
}
exports.pickBy = pickBy;
exports.default = pickBy;