Lodash & Underscore.js
A modern JavaScript utility library delivering modularity, performance & extras.
_.cloneDeep(obj) // 深度拷贝
_.isEqual(value, other) // 深度比较
_.debounce(func, [wait=0])
_.throttle(func, [wait=0])
_.omit(object, [props])
_.uniqueId()
_.random(0, 5)
Moment.js
Parse, validate, manipulate,and display dates and times in JavaScript.
moment('20:10:30', 'HH:mm:ss')
moment().format('YYYY/MM/DD HH:mm')
moment().valueOf()
moment().year(2022).year() // 2022
Day.js
Day.js 是一个轻量的处理时间和日期的 JavaScript 库,和 Moment.js 的 API 设计保持完全一样. 如果您曾经用过 Moment.js, 那么您已经知道如何使用 Day.js。
全浏览器兼容。仅 2kb 大小的微型库。
dayjs()
.startOf('month')
.add(1, 'day')
.set('year', 2018)
.format('YYYY-MM-DD HH:mm:ss')
DOM
@egstad/detect-scroll
The default scroll event listener is amazing and all, but isn’t exactly the most usable tool out of the box. It’s all, “Hey look, a user scrolled!”. And I’m like “Great! But like, in what direction and where did they stop?”. And then it’s all like, “IDFK, how about you do some math and figure it out”.
通过轮训,来探测 DOM 的滚动状态,开始滚动,结束滚动等。
BOM
query-string
解析URL中的参数(location.search) 。
const queryString = require('query-string');
console.log(location.search);
//=> '?foo=bar'
const parsed = queryString.parse(location.search);
console.log(parsed);
//=> {foo: 'bar'}
console.log(location.hash);
//=> '#token=bada55cafe'
const parsedHash = queryString.parse(location.hash);
console.log(parsedHash);
//=> {token: 'bada55cafe'}
parsed.foo = 'unicorn';
parsed.ilike = 'pizza';
const stringified = queryString.stringify(parsed);
//=> 'foo=unicorn&ilike=pizza'
location.search = stringified;
// note that `location.search` automatically prepends a question mark
console.log(location.search);
//=> '?foo=unicorn&ilike=pizza'
proper-url-join
url 地址拼接库。
import urlJoin from 'proper-url-join';
// 路径
urlJoin('foo', 'bar'); // /foo/bar
urlJoin('/foo/', '/bar/'); // /foo/bar
urlJoin('foo', '', 'bar'); // /foo/bar
urlJoin('foo', undefined, 'bar'); // /foo/bar
// 请求参数
urlJoin('foo', { query: { biz: 'buz', foo: 'bar' } }); // /foo?biz=buz&foo=bar
urlJoin('foo', 'bar?queryString', { query: { biz: 'buz', foo: 'bar' } }); // /foo/bar?biz=buz&foo=bar&queryString
React 第三方库
见这里。