You may already use Underscore or Lodash. This article lists 11 commonly used libraries to improve development efficiency.
- 11 Javascript Utility Libraries You Should Know In 2018
- Translator: Fundebug
To ensure readability, free translation rather than literal translation is used in this paper. In addition, the copyright of this article belongs to the original author, and translation is for study only.
JavaScript is still the most popular and popular programming language in 2018, so its ecosystem is well established.
JavaScript’s small standard library is not enough to meet all development needs. There are many popular JavaScript libraries on Github. Here, I compiled a list of recommendations for you:
1. Underscore & Lodash(dah)
Probably most kids already know about them. Underscore provides basic functions for everyday use. Lodash, NPM’s most downloaded and relied upon package, provides greater support for arrays, strings, objects, and parameter objects across environments. It is already a superset of Underscore. Underscore and Lodash are maintained by the same core group of developers. You definitely need it in your daily development.
- Lodash
- Underscore
2. Ramda
With over 12K stars, the Ramda library can be used for functional programming in JavaScript, designed specifically for the functional programming style, making it easier to create functional pipelines without changing user data.
From the official:
The main features of Ramda are:
- Ramda emphasizes a more purely functional style. Data invariance and function free of side effects are its core design concepts. This helps you get your work done with clean, elegant code.
- Ramda functions themselves are automatically currified. This allows you to easily create new functions from existing ones with only partial parameters.
- The order of parameters of Ramda functions is easier to currize. The data to be manipulated is usually provided at the end.
Together, these last two points make it easy to build multiple functions into simple sequences of functions, each transforming the data and passing the results to the next. Ramda is designed to support this style of programming well.
You can also check out immutable.js
3. MathJS
With over 6K stars, Math.js is a Node.js and JavaScript Math extension library that is compatible with the built-in Math library. The library includes a flexible expression parser and a number of built-in functions to use. You can even make extensions yourself.
4. Moment/date-fns
With over 40K stars, moment.js is a JavaScript time-handling library that can be used to analyze, validate, process, and format time. Moment is designed to work in browsers and Node.js environments. For V2.10.0, the code is implemented entirely in the ECMAScript 6 module.
Date-fns is also a very popular (over 11K stars) time-processing library that offers over 130 functions and is used by many as an alternative to moment.js(see comparison). Date-fns is implemented entirely with pure functions and is guaranteed to be unmodifiable. It works well with Webpack, Browserify, or Rollup, and supports tree-shaking.
- moment
- date-fns
5. Sugar
With over 3.5K stars, Sugar is a library that can be used to work with native objects. Custom built and modular NPM packages enable you to load only the packages you need. Users can also customize methods or use plug-ins to handle special cases.
6. Lazy
With 5K stars, lazy.js is a functional JavaScript library. The underlying implementation of the library is lazy, meaning that it does not perform operations unless the station needs it. This library doesn’t rely on third-party libraries, so here’s a demo, here’s the API documentation.
For example, if we want to generate 300 completely different random numbers between 1 and 1000, we could write it like this:
Lazy.generate(Math.random)
.map(function(e) { return Math.floor(e * 1000) + 1; })
.uniq()
.take(300)
.each(function(e) { console.log(e); });
Copy the code
Writing it directly in JavaScript makes the code much more complex.
7. CollectJS
With over 3.5K stars, collect.js is a very promising library that doesn’t rely on any third party libraries. It provides a wrapper for arrays and objects, making it very easy to use.
const collection = collect([{ name: 'JavaScript: The Good Parts', pages: 176 }, { name: 'JavaScript: The Definitive Guide', pages: 1096 }]); collection.avg('pages'); / / = > 636Copy the code
8. ChanceJS
Chance is a function that randomly generates strings, numbers, etc. It can reduce some of the non-randomness, which is useful if you need to write automated tests or anything else where you need to generate randomness. It’s only 3K stars, but the library is really handy.
- chancejs
9. ChartJS
With over 40K stars, chart.js is a classic example of how less is more. It provides only eight types of visualization, each of which is animated and customizable. Chart.js lets you draw with the
10. Polished
With over 3.5K stars, developed by the Style-Components team, Polished is a set of tools for writing CSS styles that provide saas style help functions and mixins. The library is compatible with Styled – Components, Aphrodite, Radium.
11. Mout
Out.js is a modular set of JavaScript tools that can be used in browsers as AMD modules or in Node.js. Out.js lets you load only the modules or functions you need, as shown below:
// you can load individual methods (recommended) var map = require('mout/array/map'); map([1, 2], function(v){ return val * val; }); // [1, 4] // a single package var stringUtils = require('mout/string'); stringUtils.camelCase('Foo Bar'); // "fooBar" // or the whole lib var mout = require('mout'); console.log( mout.math.clamp(17, 0, 10) ); / / 10Copy the code
12. Voca
A JavaScript library for handling strings, including many helper functions such as: change Case, trim, pad, slugify, latinise, sprintf ‘y, truncate, escape, etc.
13. Licia
Although there are only 500 or so stars, Licia provides a large number of utility functions that are useful for daily use. Official introduction:
Licia is a library of useful JavaScript tools accumulated during development. At present, the library has more than 180 modules, including Dom operation, cookie setting, class creation, template function, date formatting and other practical modules. At the same time, it is equipped with packaging tool Eustia for customization, which reduces the loading load of JS scripts to less than 10KB, greatly optimizing the loading speed of mobile terminal pages.
Licia was developed by RedHood. For details, check out his introduction to Licia on Zhihu: A library of super Useful JavaScript tools.
- licia
About Fundebug
Fundebug focuses on BUG monitoring of JavaScript, wechat mini programs and small games. Since its official launch on November 11, 2016, Fundebug has been serving for one and a half years and has handled over 500 million error events in total, which has been recognized by many well-known users. Fundebug supports mainstream front-end framework bug monitoring, welcome to experience!
Are your users experiencing bugs?