ether-fe-common
v0.0.3
Published
common kits for fe
Readme
fe-common
common kits for fe
安装
npm i ether-fe-common --save-dev使用
import * as commmon from 'ether-fe-common';Url
let url = new commmon.helper.Url('https://www.google.com/index?id=abc#hash');properties:
|property|type| |:---:|:---:| |protocol|string| |host|string| |path|string| |fullPath|string| |params|object| |hash|string|
methods:
- url.addParams(obj);
- url.removeParams(key|arr);
- url.replaceParams(obj);
- url.toString();
- url.getFullPath();
// 示例
url.addParams({
p: 'msg'
});
url.removeParams('id');
url.replaceParams({
p: 'new-msg'
});
url.toString();Ls
let ls = new commmon.helper.Ls([config]);config properties:
|property|type|default| |:---:|:---:|:---:| |prefix|string|#|| |gcRate|number|.1|
methods:
- ls.set(key, value[, expire]);
- ls.get(key).then(cb);
- ls.remove(key|arr).then(cb);
- ls.getOrSet(key, value).then(cb);
// 示例
ls.set('test', { msg: 'some msg' });
ls.get('test').then(data => { console.log(data) });
ls.remove('test').then(() => {});
ls.remove(['test']).then(() => {});
ls.getOrSet('test', { msg: 'other msg' }).then(data => { console.log(data) });Ua
commmon.helper.Ua.isDealEase(); // boolean
commmon.helper.Ua.isWx(); // boolean
commmon.helper.Ua.isIOS(); // boolean
commmon.helper.Ua.isAndroid(); // boolean
commmon.helper.Ua.isIOS(); // boolean
commmon.helper.Ua.getEnv(); // stringTime
commmon.helper.Time.format(date, format);format:
|format|value| |:---:|:---:| |yyyy|year| |yy|year| |MM|month| |M|month| |dd|date| |d|date| |DD|week| |D|week| |DC|week cn| |hh|hour| |h|hour| |mm|munite| |m|munite| |ss|second| |s|second|
// 示例
let date = new Date();
commmon.helper.Time.format(date, 'yyyy-MM-dd 星期DC');Factory
methods:
- commmon.helper.Factory.getSingle(fn);
// 示例
let fn1 = commmon.helper.Factory.getSingle(function() {
let date = new Date();
return date;
});