Home >headlines >10 latest and practical JS tool libraries in 2022 [Recommended]

10 latest and practical JS tool libraries in 2022 [Recommended]

青灯夜游
青灯夜游forward
2022-01-18 14:16:573788browse

This article will share with you the 10 most popular practical JS tool libraries, which are used in 80% of projects. Come and collect them for use. I hope it will be helpful to everyone!

10 latest and practical JS tool libraries in 2022 [Recommended]

The important thing that distinguishes masters from ordinary people is that they are good at using tools and leave more time for planning and thinking. The same goes for writing code. If you use the tools well, you will have more time to plan the architecture and overcome difficulties. Today I will share with you the most popular js tool library currently. If you find it useful, please give it a thumbs up!

1. Day.js

A minimalist JavaScript library for processing time and date. The API design remains the same as Moment.js, but the size is only 2KB.

npm install dayjs

Basic usage

import dayjs from 'dayjs'

dayjs().format('YYYY-MM-DD HH:mm') // => 2022-01-03 15:06
dayjs('2022-1-3 15:06').toDate() // => Mon Jan 03 2022 15:06:00 GMT+0800 (中国标准时间)

2. qs

A lightweight JavaScript library for url parameter conversion

npm install qs

Basic usage

import qs from 'qs'

qs.parse('user=tom&age=22') // => { user: "tom", age: "22" }
qs.stringify({ user: "tom", age: "22" }) // => user=tom&age=22

3. js-cookie

A simple, lightweight js API for handling cookies

npm install js-cookie

Basic usage

import Cookies from 'js-cookie'

Cookies.set('name', 'value', { expires: 7 }) // 有效期7天
Cookies.get('name') // => 'value'

4. flv.js

bilibili is an open source html5 flash video player that makes the browser FLV can be played without the help of flash plug-in, which is currently the mainstream live broadcast and on-demand solution.

npm install flv.js

Basic usage

<video autoplay controls width="100%" height="500" id="myVideo"></video>

import flvjs from &#39;flv.js&#39;

// 页面渲染完成后执行
if (flvjs.isSupported()) {
  var myVideo = document.getElementById(&#39;myVideo&#39;)
  var flvPlayer = flvjs.createPlayer({
    type: &#39;flv&#39;,
    url: &#39;http://localhost:8080/test.flv&#39; // 视频 url 地址
  })
  flvPlayer.attachMediaElement(myVideo)
  flvPlayer.load()
  flvPlayer.play()
}

5. vConsole

A lightweight, scalable front-end development for mobile web pages or debug panel. If you are still struggling with how to debug code on your mobile phone, use it.

npm install vconsole

Basic Usage

import VConsole from &#39;vconsole&#39;

const vConsole = new VConsole()
console.log(&#39;Hello world&#39;)

Recently I have found that many guys only collect and don’t like. This is not a good habit. Rejecting free prostitution starts with you and me! Come move with me and give me a like first! Collect again!

6. Animate.css

A cross-browser css3 animation library with many typical css3 animations built-in, with good compatibility and easy use.

npm install animate.css

Basic usage

<h1 class="animate__animated animate__bounce">An animated element</h1>

import &#39;animate.css&#39;

7. animejs

A powerful Javascript animation library. It can work with CSS3 properties, SVG, DOM elements, and JS objects to produce various high-performance, smooth transition animation effects.

npm install animejs

Basic usage

<div class="ball" style="width: 50px; height: 50px; background: blue"></div>

import anime from &#39;animejs/lib/anime.es.js&#39;

// 页面渲染完成之后执行
anime({
  targets: &#39;.ball&#39;,
  translateX: 250,
  rotate: &#39;1turn&#39;,
  backgroundColor: &#39;#F00&#39;,
  duration: 800
})

8, lodash.js

A consistent, modular, high-performance JavaScript Practical tool library

npm install lodash

Basic usage

import _ from &#39;lodash&#39;

_.max([4, 2, 8, 6]) // 返回数组中的最大值 => 8
_.intersection([1, 2, 3], [2, 3, 4]) // 返回多个数组的交集 => [2, 3]

9, mescroll.js

An exquisite, on the H5 side The running pull-down refresh and pull-up loading plug-ins are mainly used in scenarios such as list paging and refreshing.

npm install mescroll.js

Basic usage (vue component)

<template>
  <div>
    <mescroll-vue
      ref="mescroll"
      :down="mescrollDown"
      :up="mescrollUp"
      @init="mescrollInit"
    >
      <!--内容...-->
    </mescroll-vue>
  </div>
</template>

<script>
import MescrollVue from &#39;mescroll.js/mescroll.vue&#39;

export default {
  components: {
    MescrollVue
  },
  data() {
    return {
      mescroll: null, // mescroll实例对象
      mescrollDown: {}, //下拉刷新的配置
      mescrollUp: {
        // 上拉加载的配置
        callback: this.upCallback
      },
      dataList: [] // 列表数据
    }
  },
  methods: {
    // 初始化的回调,可获取到mescroll对象
    mescrollInit(mescroll) {
      this.mescroll = mescroll
    },
    // 上拉回调 page = {num:1, size:10}; num:当前页 ,默认从1开始; size:每页数据条数,默认10
    upCallback(page, mescroll) {
      // 发送请求
      axios
        .get(&#39;xxxxxx&#39;, {
          params: {
            num: page.num, // 当前页码
            size: page.size // 每页长度
          }
        })
        .then(response => {
          // 请求的列表数据
          let arr = response.data
          // 如果是第一页需手动置空列表
          if (page.num === 1) this.dataList = []
          // 把请求到的数据添加到列表
          this.dataList = this.dataList.concat(arr)
          // 数据渲染成功后,隐藏下拉刷新的状态
          this.$nextTick(() => {
            mescroll.endSuccess(arr.length)
          })
        })
        .catch(e => {
          // 请求失败的回调,隐藏下拉刷新和上拉加载的状态;
          mescroll.endErr()
        })
    }
  }
}
</script>

<style scoped>
.mescroll {
  position: fixed;
  top: 44px;
  bottom: 0;
  height: auto;
}
</style>

10. Chart.js

A set of simple, Clean and attractive JavaScript chart library

npm install chart.js

Basic usage

<canvas id="myChart" width="400" height="400"></canvas>

import Chart from &#39;chart.js/auto&#39;

// 页面渲染完成后执行
const ctx = document.getElementById(&#39;myChart&#39;)
const myChart = new Chart(ctx, {
  type: &#39;bar&#39;,
  data: {
    labels: [&#39;Red&#39;, &#39;Blue&#39;, &#39;Yellow&#39;, &#39;Green&#39;, &#39;Purple&#39;, &#39;Orange&#39;],
    datasets: [
      {
        label: &#39;# of Votes&#39;,
        data: [12, 19, 3, 5, 2, 3],
        backgroundColor: [
          &#39;rgba(255, 99, 132, 0.2)&#39;,
          &#39;rgba(54, 162, 235, 0.2)&#39;,
          &#39;rgba(255, 206, 86, 0.2)&#39;,
          &#39;rgba(75, 192, 192, 0.2)&#39;,
          &#39;rgba(153, 102, 255, 0.2)&#39;,
          &#39;rgba(255, 159, 64, 0.2)&#39;
        ],
        borderColor: [
          &#39;rgba(255, 99, 132, 1)&#39;,
          &#39;rgba(54, 162, 235, 1)&#39;,
          &#39;rgba(255, 206, 86, 1)&#39;,
          &#39;rgba(75, 192, 192, 1)&#39;,
          &#39;rgba(153, 102, 255, 1)&#39;,
          &#39;rgba(255, 159, 64, 1)&#39;
        ],
        borderWidth: 1
      }
    ]
  },
  options: {
    scales: {
      y: {
        beginAtZero: true
      }
    }
  }
})

Each of the above tool libraries was personally tested by myself, and the current company projects are basically in use. If you have any questions, please share them in the comment area. If you have other good tools, please share them. Let’s improve work efficiency together and defeat all evil capitalism

Finally, don’t forget to like it! Wish you riches in 2022! Gorgeous! Extremely thin!

Original address: https://juejin.cn/post/7048963605462515743

Author: Front-end A Fei

[Related recommendations: javascript Study tutorial

Statement:
This article is reproduced at:juejin.cn. If there is any infringement, please contact admin@php.cn delete