React 《常用库》

lodash

Lodash 通过降低 array、number、objects、string 等等的使用难度从而让 JavaScript 变得更简单。 Lodash 的模块化方法 非常适用于:
遍历 array、object 和 string
对值进行操作和检测
创建符合功能的函数

官网 https://www.lodashjs.com/

# install
npm i --save lodash
// Load the full build.
var _ = require('lodash');
// Load the core build.
var _ = require('lodash/core');
// Load the FP build for immutable auto-curried iteratee-first data-last methods.
var fp = require('lodash/fp');
// Load method categories.
var array = require('lodash/array');
var object = require('lodash/fp/object');
 
// Cherry-pick methods for smaller browserify/rollup/webpack bundles.
var at = require('lodash/at');
var curryN = require('lodash/fp/curryN');

classnames 优化类名控制

classNames
https://github.com/JedWatson/classnames

# install 
npm install classnames
# use
classNames('foo', 'bar'); // => 'foo bar'
classNames('foo', { bar: true }); // => 'foo bar'
classNames({ 'foo-bar': true }); // => 'foo-bar'
classNames({ 'foo-bar': false }); // => ''
classNames({ foo: true }, { bar: true }); // => 'foo bar'
classNames({ foo: true, bar: true }); // => 'foo bar'

// lots of arguments of various types
classNames('foo', { bar: true, duck: false }, 'baz', { quux: true }); // => 'foo bar baz quux'

// other falsy values are just ignored
classNames(null, false, 'bar', undefined, 0, { baz: null }, ''); // => 'bar'

uuid 生成随机uuid

see https://github.com/uuidjs/uuid

#install
npm install uuid
#use
import { v4 as uuidv4 } from 'uuid';
uuidv4(); // ⇨ '9b1deb4d-3b7d-4bad-9bdd-2b0d7b3dcb6d

dayjs 要求以当前时间为标准,生成固定格式时间

see https://dayjs.gitee.io/zh-CN/

# install
npm install dayjs
# use
import dayjs from "dayjs";

dayjs(new Date()).format('MM-DD hh:mm')

posted @ 2024-04-25 17:20  一个小笨蛋  阅读(4)  评论(0编辑  收藏  举报