Lodash & Underscore.js

A modern JavaScript utility library delivering modularity, performance & extras.

  1. _.cloneDeep(obj) // 深度拷贝
  2. _.isEqual(value, other) // 深度比较
  3. _.debounce(func, [wait=0])
  4. _.throttle(func, [wait=0])
  5. _.omit(object, [props])
  6. _.uniqueId()
  7. _.random(0, 5)

Moment.js

Parse, validate, manipulate,and display dates and times in JavaScript.

  1. moment('20:10:30', 'HH:mm:ss')
  2. moment().format('YYYY/MM/DD HH:mm')
  3. moment().valueOf()
  4. moment().year(2022).year() // 2022

Day.js

Day.js 是一个轻量的处理时间和日期的 JavaScript 库,和 Moment.js 的 API 设计保持完全一样. 如果您曾经用过 Moment.js, 那么您已经知道如何使用 Day.js。

全浏览器兼容。仅 2kb 大小的微型库。

  1. dayjs()
  2. .startOf('month')
  3. .add(1, 'day')
  4. .set('year', 2018)
  5. .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) 。

  1. const queryString = require('query-string');
  2. console.log(location.search);
  3. //=> '?foo=bar'
  4. const parsed = queryString.parse(location.search);
  5. console.log(parsed);
  6. //=> {foo: 'bar'}
  7. console.log(location.hash);
  8. //=> '#token=bada55cafe'
  9. const parsedHash = queryString.parse(location.hash);
  10. console.log(parsedHash);
  11. //=> {token: 'bada55cafe'}
  12. parsed.foo = 'unicorn';
  13. parsed.ilike = 'pizza';
  14. const stringified = queryString.stringify(parsed);
  15. //=> 'foo=unicorn&ilike=pizza'
  16. location.search = stringified;
  17. // note that `location.search` automatically prepends a question mark
  18. console.log(location.search);
  19. //=> '?foo=unicorn&ilike=pizza'

proper-url-join

url 地址拼接库。

  1. import urlJoin from 'proper-url-join';
  2. // 路径
  3. urlJoin('foo', 'bar'); // /foo/bar
  4. urlJoin('/foo/', '/bar/'); // /foo/bar
  5. urlJoin('foo', '', 'bar'); // /foo/bar
  6. urlJoin('foo', undefined, 'bar'); // /foo/bar
  7. // 请求参数
  8. urlJoin('foo', { query: { biz: 'buz', foo: 'bar' } }); // /foo?biz=buz&foo=bar
  9. urlJoin('foo', 'bar?queryString', { query: { biz: 'buz', foo: 'bar' } }); // /foo/bar?biz=buz&foo=bar&queryString

React 第三方库

这里