Home » Frontend Developer » Lodash – Functional Javascript library

Lodash – Functional Javascript library

Lodash


Introduce

If you are familiar with functional programming language such as Haskell, Erlang… or fell in love with awesome collection method of Scala, you will may need to develop your front end application with these features too.
Luckily, we have a modern JavaScript utility library delivering modularity, performance, & extras, it named as Lodash.

Lodash is inspired by Underscore, but nowadays is superior solution and Lodash is updated more frequently than Underscore.

Lodash makes JavaScript easier by taking the hassle out of working with arrays, numbers, objects, strings, etc.

Installation

Homepage
  • Download  source
  • Via npm

Features

Collection

map/flatMap


filter – order


There are many collection function such as:
  • _.every //Returns true if all elements pass the predicate check, else false.
  • _.find //Returns the matched element, else undefined.
  • _.groupBy //Returns the composed aggregate object.
  • _.includes //Returns true if value is found, else false.
  • _.sortBy //Returns the new sorted array.
  • _.partition //Returns the array of grouped elements.
  • _.reduce //Returns the accumulated value.
  • _.reject //Returns the new filtered array.
To figure out more method, you can go to document in this page

String

It’s also contains function interact with string
  • _.lowerCase //Returns the lower cased string
  • _.repeat //Returns the repeated string.
  • _.truncate // Returns the truncated string.
  • _.upperFirst //Returns the converted string with first letter upcase.
  • _.template //Returns the compiled template function.

Lang

Common function deal with value of variable
  • _.isDate
  • _.isElement
  • _.isEmpty
  • _.isEqual
  • _.isFunction
  • _.isInteger
  • _.isLength
  • _.isMatch
  • _.isNaN
  • _.isNull
  • _.isNumber
It’s very helpful and save a lot of time while develop application. You just need to focus on the main problem and doesn’t care about issue of Javascript, for example like: NaN is not equal NaN  or truthy and falsy things.

Conclusion

Lodash has been doing great for me and I will continue to drop it in all my Javascript project. It reduces the amount of boilerplate code and also improves the clarity of my application logic.

But my biggest takeaway is this – Lodash forces me to think in a more functional manner. I can break my application into many smaller modules with singular focus and no side effects.

There’s no reason you shouldn’t try it and figure out yourself what it’s interesting.

Thanks for your reading.

Tagged width: