febs 库是一些常用的工具的合集;
febs实现了jquery的常用方法(dom操作/事件/css/遍历等), 当页面引入febs前如果未引入jquery, 会自动设置全局变量 $
为内部实现的jquery相关方法.
大多数场景下可以使用febs库代替jquery, 而解决jquery臃肿的问题.
兼容ie9及以上浏览器
支持微信小程序 (暂时不支持dom库)
Install
Use npm to install:
npm install febs-browser --save
发布包位置在febs-browser/dist
下, 提供如下两种不同体积的发布包:
类型 | 路径 |
---|
不包含BigNumber相关的库 (体积较小) | febs-browser/dist/index.noBignumber.min.js |
包含BigNumber相关的库 | febs-browser |
同时提供如下三种模式的库:
类型 | 对应文件 |
---|
umd | dist/index.js 或 dist/index.noBignumber.js |
commonjs | dist/index.common.js 或 dist/index.noBignumber.common.js |
esm | dist/index.esm.js 或 dist/index.noBignumber.esm.js |
commonjs
以下列方式使用
var febs = require('febs-browser');
febs.string.replace();
browser
以下列方式使用
copy directory node_modules/febs/dist/index.min.js
to client
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<script charset='UTF-8' type="text/javascript" src="path/dist/index.min.js"></script>
<script>
febs.string.replace();
</script>
babel
以下列方式使用
import * as febs from 'febs-browser';
febs.string.replace();
framework
说明
name | description |
---|
__line | 当前所在行, 可以配合 __filename 定位错误日志 |
__debug | 判断当前的环境process.env.NODE_ENV是否为development, 如对此值设置后, 使用设置后的值. |
console.debug | development 环境下输出日志 |
其他
- 函数调用使用
类名.xxx
的方式调用, 例如: febs.utils.browserIsMobile()
- 对早期的浏览器定义了
window.requestAnimationFrame
和window.cancelAnimationFrame
方法,可进行动画帧操作. - 对早期的浏览器添加了
Promise
支持.
polyfill
name |
---|
promise.finally |
console |
fetch |
AnimationFrame |
dom
febs.dom.getViewPort():{width:number, height:number};
febs.dom.getDocumentPort():{width:number, height:number};
febs.dom..getDocumentOffset():{top:number, left:number};
febs.dom.getElementOffset(e:any):{left:number, top:number};
febs.dom.isDom(e: any): boolean;
febs.dom.addEventListener(domElement:any, event:string, func:any, useCapture?:boolean):null;
febs.dom.removeEventListener(domElement:any, event:string, func:any, useCapture?:boolean):null;
date
date库包含了一些常用的时间操作库, 如验证时间对象是否有效等.
febs.date.isValidate(date: Date): boolean;
febs.date.getTimeString(localtime: number, fmt: string, weekFmt: WeekFmt): string;
febs.date.getUTCTimeString(localtime: number, fmt: string, weekFmt: WeekFmt): string;
febs.date.getTimeStringFromNow(localtime: number, strFmt: string): string;
febs.date.getDate(strDate: string): Date
febs.date.getDateFromUTC(strDateUTC: string): Date;
febs.date.getDate2(strDate: string): Date;
febs.date.getDate2FromUTC(strDateUTC: string): Date;
febs.date.getTime(strTime:string): Date;
febs.date.getTime2(strTime:string): Date;
febs.date.getTimeFromUTC(strTimeUTC: string): Date;
febs.date.getTime2FromUTC(strTimeUTC: string): Date;
utils
utils库包含了一些常用的函数, 如判断浏览器是否是手机/时间字符串格式化等.
febs.utils.sleep(ms)
febs.utils.browserIsMobile()
febs.utils.browserIsIOS()
febs.utils.browserIsPhone()
febs.utils.browserIsWeixin()
febs.utils.browserIsIE()
febs.utils.browserIEVer()
febs.utils.browserIsSupportHtml5() `服务端不支持`
febs.utils.browserIsSafari()
febs.utils.browserIsOpera()
febs.utils.browserIsFirefox()
febs.utils.browserIsChrome()
febs.utils.browserIsEdge()
febs.utils.mergeMap(...)
febs.utils.isNull(e)
febs.utils.denodeify(fn, self, argumentCount)
大数类型: febs.BigNumber
febs.utils.bigint(v: any): number|BigNumber;
febs.utils.bigint_check(v)
febs.utils.bigint_add(a, b)
febs.utils.bigint_minus(a, b)
febs.utils.bigint_dividedBy(a, b)
febs.utils.bigint_mul(a, b)
febs.utils.bigint_equal(a, b)
febs.utils.bigint_more_than(a, b)
febs.utils.bigint_more_than_e(a, b)
febs.utils.bigint_less_than(a, b)
febs.utils.bigint_less_than_e(a, b)
febs.utils.bigint_toFixed(a, fixed)
string
string 提供了一些js string对象缺少且较常使用的函数.
febs.string.isPhoneMobile(str)
febs.string.isEmpty(s)
febs.string.getByteSize(s)
febs.string.replace(str, strSrc, strDest)
febs.string.utf8ToBytes(str)
febs.string.bytesToUtf8(utfBytes:number[]):string;
febs.string.trim(str)
febs.string.escapeHtml(str);
crypt
目前提供了uuid,crc32,base64.
客户端独有.
febs.crypt.crc32_file(fileObj, cb)
febs.crypt.crc32_fileSegment(fileObj: any, offset:number, length:number, cb: (crc32: number) => void): void;
febs.crypt.base64_decode(strBase64)
通用.
febs.crypt.crc32( str, crc )
febs.crypt.base64_encode(arrByte)
febs.crypt.md5( strOrBuffer )
febs.crypt.sha1( strOrBuffer )
febs.crypt.uuid()
animationFrame
各浏览器兼容的 requestAnimationFrame
, cancelAnimationFrame
动画方法.
var total = 0;
var timer;
var now = Date.now();
function foo(tm) {
var now2 = Date.now();
total += now2-now;
now = now2;
if (total > 10000) {
cancelAnimationFrame(timer);
} else {
timer = requestAnimationFrame(foo);
}
}
timer = requestAnimationFrame(foo);
net
net封装了浏览器通信方法: ajax, fetch, jsonp
febs.net.ajax(cfg:any):{abort:()=>void}
febs.net.fetch(url, option)
febs.net.jsonp(url, option)
jquery
febs库模拟了jquery的常用方法(dom操作/事件/css等), 当页面引入febs前如果未引入jquery, 会自动设置全局变量 $
为内部实现的jquery相关方法.
目前已经实现的方法如下:
常用
$(selector?:string|dom|HTMLElement);
get(index:number): any;
hasClass( cName:string ): boolean;
addClass( cName:string ): $;
removeClass( cName:string ): $;
toggleClass( cName:string ): $;
remove(): void;
append(selector?:string|dom|HTMLElement): $;
appendTo(selector?:string|dom|HTMLElement): $;
prepend(selector?:string|dom|HTMLElement): $;
prependTo(selector?:string|dom|HTMLElement): $;
before(selector?:string|dom|HTMLElement): $;
insertBefore(selector?:string|dom|HTMLElement): $;
after(selector?:string|dom|HTMLElement): $;
insertAfter(selector?:string|dom|HTMLElement): $;
attr(attrName:any, value:any): string;
removeAttr(name:any): $;
empty(): $;
html(v:string): string;
text(v:string): string;
val(v:string): string;
css(name:string, value:string): string;
事件.
on(eventname:string, foo:any): $;
one(event:string, f:any): $;
off(eventname:string, foo?:any): $;
trigger(eventname:string, extraParameters?:any): $;
ready(f?:any):$;
unload(f?:any):$;
blur(f?:any):$;
change(f?:any):$;
click(f?:any):$;
dblclick(f?:any):$;
error(f?:any):$;
keydown(f?:any):$;
keypress(f?:any):$;
keyup(f?:any):$;
load(f?:any):$;
mousedown(f?:any):$;
mouseenter(f?:any):$;
mouseleave(f?:any):$;
mousemove(f?:any):$;
mouseout(f?:any):$;
mouseover(f?:any):$;
mouseup(f?:any):$;
scroll(f?:any):$;
select(f?:any):$;
submit(f?:any):$;
遍历
parent(selector?:string|dom|HTMLElement) : $;
parents(selector?:string|dom|HTMLElement) : $;
children(selector?:string|dom|HTMLElement) : $;
prev(selector?:string|dom|HTMLElement) : $;
next(selector?:string|dom|HTMLElement) : $;
each((e)=>{});