fetools
前端通用工具库
优点:提高前端业务代码开发效率,增强代码复用性
前端开发过程中,会经常用到判断浏览器类型
、格式化各种日期
、获取url参数
、queryString转对象
、防抖函数
、节流函数
等常用函数,为避免不同项目多次复制粘贴的麻烦,这里统一封装,并发布到npm,以提高开发效率。
安装使用
- 直接下载
dist
目录下的wecoder-fetools.min.js使用,支持UMD通用模块规范 - 使用npm安装
浏览器:
<script src="wecoder-fetools.min.js"></script>
<script>
var color = fetools.randomColor()
</script>
npm:
$ npm install --save-dev wecoder-fetools
webpack、RequireJS、SeaJS, esModule等
const fetools = require('wecoder-fetools')
const color = fetools.randomColor()
or
import fetools from 'wecoder-fetools'
推荐使用方法
不需要完整引入所有函数,只引入需要使用的方法即可。
const color = require('wecoder-fetools/modules/randomColor')
or
import { randomColor } from 'wecoder-fetools'
API文档
Array
Class
Cookie
Device
Dom
offset 获取一个元素的距离文档(document)的位置,类似jQ中的offset()
scrollTo 在${duration}时间内,滚动条平滑滚动到${to}指定位置
Function
Keycode
Object
Random
Regexp
isUrl 判断是否为URL地址
String
Support
Time
Url
Number