What's lodash?
Tags: beginners, javascript, github
Published: 2019-07-20 08:32:05

---
title: What's lodash?
published: true
description: 
tags: beginner, javascript, github
---

<p>
 Like most of you - or @KyleShevlin at least - I seem to be really popular with Github lately.  They've been sending me a lot of email, most of which says "One of your dependencies has a security vulnerability..."
</p>

![](https://thepracticaldev.s3.amazonaws.com/i/qtem31v7d3wrxoiv6g1o.png)

<p>
 A large number of the ones I receive have something to do with the Lodash dependency (and it seems a lot of yours do too) in repos for projects built with Express, React, all kinds of packages really.  I know I never explicitly installed anything called Lodash, but these repos all have it so what is it, what does it do and how did it get there in the first place?  Welcome to another episode of 'Rushton Investigates'...
</p>

<p>
The official website - <a src="https://lodash.com/">Lodash.com</a> tells me it's: 
<blockquote>A modern JavaScript utility library delivering modularity, performance & extras.</blockquote>Ok, so it's a library.  Makes sense. It's written in JavaScript, which also makes sense given the repos that have the issues.
</p>

<p>
<a src="https://lodash.com/">Lodash.com</a> also says it can be installed with npm, it comes in a variety of builds, and it has methods for working with arrays, numbers, strings, objects etc.  Cool. You can use these methods for iterating, doing stuff with values (like testing) and creating composite functions (applying one function to the results of another). To use the methods you call them on underscore and pass in the objects you want to use them on, as arguments. I didn't understand why at first but it seems that by convention you should map the Lodash library to the underscore character, eg:  
</p>
![](https://thepracticaldev.s3.amazonaws.com/i/cfij7ijl5r1ozwkbpycr.png)
<p>
This blog by Vincent D'amour has good examples of Lodash methods - <a>https://medium.com/voobans-tech-stories/10-lodash-functions-everyone-should-know-334b372aec5d</a> - including _.deburr, which removes accents from characters:
</p>


![Lodash _.deburr method](https://thepracticaldev.s3.amazonaws.com/i/k1n3r3uihfi8bxr46mta.png)

<p>
So that's briefly what it is and what it does, next question is how did it get there if I never installed it explicitly?
</p>

<p>
I thought google would answer this one pretty easily but no, or maybe I just wasn't googling the right thing.  I've discovered that a key skill of the developer is knowing how to phrase your google search! It seemed logical that the libraries I was using to build my projects were using Lodash as a dependency, and a quick search for 'create-react-app lodash' returned this top result:
</p>

![](https://thepracticaldev.s3.amazonaws.com/i/coccg4xpe9ta895k47f9.png)

<p>
All very well, but when I looked at one of my repo's built with create-react-app, it wasn't there in the package.json, but it was in the package-lock.json, 84 times! 1 time was for Lodash itself, 9 for individual Lodash methods, the rest were required by other libraries. For instance, eslint requires the whole Lodash library, while css-loader requires only "lodash.camelcase".
</p>

<p>To be honest I was still a bit confused at this point - what was the link between the stuff in those 2 files?  How deeply nested were these dependencies?  Discussing with a dev friend, he suggested a dependency graph would help me visualise the relationships - I wasn't familiar with the term but I managed to find some excellent resources:
<ul>
<li>
<a src="http://npm.broofa.com/">npm.broofa.com</a>: Produces straightforward, easy to read graph
</li>
<li>
<a src="https://npm.anvaka.com/#/">npm.avanka.com</a>: Visually impressive, dynamically builds a nice floaty graph but I didn't find it as easy to read
</li>
</ul> 
From the graphs generated, it was easy to see where lodash came from - create-react-app requires a library of command-line interfaces called Inquirer, which in turn requires Lodash. Boom!  
</p>


![](https://thepracticaldev.s3.amazonaws.com/i/zjqqk034ifrsdg0siqnd.png)