What is lodash.omitby?
The lodash.omitby package is a utility function from the Lodash library that creates an object composed of the own and inherited enumerable string keyed properties of `object` that `predicate` doesn't return truthy for. Essentially, it allows you to omit properties from an object based on a condition.
What are lodash.omitby's main functionalities?
Omit properties based on a condition
This feature allows you to omit properties from an object where the values meet a certain condition. In this example, all properties with numeric values are omitted.
const omitBy = require('lodash.omitby');
const object = { 'a': 1, 'b': '2', 'c': 3 };
const result = omitBy(object, value => typeof value === 'number');
console.log(result); // { 'b': '2' }
Omit properties with null or undefined values
This feature allows you to omit properties from an object where the values are null or undefined. In this example, properties 'b' and 'c' are omitted.
const omitBy = require('lodash.omitby');
const object = { 'a': 1, 'b': null, 'c': undefined, 'd': 'text' };
const result = omitBy(object, value => value == null);
console.log(result); // { 'a': 1, 'd': 'text' }
Other packages similar to lodash.omitby
ramda
Ramda is a functional programming library for JavaScript. It provides a similar function called `R.omit` which can be used to omit properties from an object. However, Ramda's approach is more functional and may require a different mindset compared to Lodash.
underscore
Underscore is another utility library that provides a wide range of functions for manipulating objects and arrays. It has a function called `_.omit` which can be used to omit properties from an object based on keys. While similar, it does not provide the same predicate-based omission as lodash.omitby.
lodash.omitby v4.2.2
The lodash method _.omitBy
exported as a Node.js module.
Installation
Using npm:
$ {sudo -H} npm i -g npm
$ npm i --save lodash.omitby
In Node.js:
var omitBy = require('lodash.omitby');
See the documentation or package source for more details.