Libs
零散的工具函数,独立业务场景,几乎不可能用到全部的函数 建议:单独引用
// 调用名libsbase64encodelibsbase64decodelibsbase64toBloblibscookielibscountDownlibsdealImagelibsemojilibsfileToBase64libsgetStrLengthlibsgetSuffixNamelibsimgLoadlibslocalStoragelibsOSSAjaxlibsqueryStringlibssessionStoragelibsturnTimelibsXMLToJson
queryString
//单个参数; //以哈希取,以哈希返回; //以数组取,以数组希返回;
cookie
//写入cookie; //取值; //取一堆值;//{key1:"value",key2:"value",key3:"value"}
countDown
;
localStorage,sessionStorage
sessionStorage用法与 localStorage一致
local_storage remove_local_storage_item clear_local_storage from 'libs-js/src/localStorage' //写入; //取值; //删除某一项; //清空;
imgLoad
图片加载回调
;
XMLToJson
const xmlstr=`<?xml version="1.0" encoding="UTF-8"?><PostResponse> <Bucket>Bucket</Bucket> <Location>Location</Location> <Key>Key</Key> <ETag>ETag</ETag></PostResponse>`; const xmlstr2=`<?xml version="1.0" encoding="UTF-8"?><PostResponse> <Bucket>Bucket2</Bucket> <Location>Location2</Location> <Key>Key2</Key> <ETag>ETag2</ETag></PostResponse>`;const xml = ;/*{ xmlstr:`同xmlstr`, jsonObj:{ PostResponse:{ Bucket:{ 'text':'Bucket' }, ETag:{ 'text':'ETag' }, Key:{ 'text':'Key' }, Location:{ 'text':'Location' }, } }}*/ console; xmlxmlstr = xmlstr2; /*{ xmlstr:`同xmlstr`, jsonObj:{ PostResponse:{ Bucket:{ 'text':'Bucket2' }, ETag:{ 'text':'ETag2' }, Key:{ 'text':'Key2' }, Location:{ 'text':'Location2' }, } }}*/ console;
OSSAjax
oss上传文件用的ajax
/** * 往oss上传用的ajax * * @param * @param * @param * @param * key:"保存到oss的文件名", * OSSAccessKeyId:"", * policy:"", * Signature:"" * } * @param * @param * @param * @param */;
fileToBase64
文件转base64
;
dealImage
处理图像:等比降低图像质量 未裁剪
const max_size = 1024; //假设限制最大1Mconst img_size = 2048; //假设当前图片2M,一般是file.size / 1024 除以1024是为了转成k //先将上传域的图片base64;
base64ToBlob
base64编码转Blob
// 一系列处理 可以 实现 前端压缩图片(仅压缩),然后上传 const max_size = 1024; //假设限制最大1Mconst img_size = 2048; //假设当前图片2M,一般是file.size / 1024 除以1024是为了转成k //先将上传域的图片base64;
emoji
包含2个方法:is_emoji_character,utf16_to_entities
turnTime
时间差拆分
//这段创建时间的代码是demo,别模仿,渣渣浏览器可能new不出来的const d1 = +'2017-11-11 10:00:00';const d2 = +'2017-11-11 12:01:01'; /*{ d:0, h:2, m:1, millisecond:0, s:1}*/;
base64
base64加密解密
; // YWJjZA==; // abcd ; //JUU1JThBJUEwJUU1JUFGJTg2JUU0JUI4JUFEJUU2JTk2JTg3 //加密中文
getStrLength
中文2个字符,其他1个字符,计算字符串长度
; // 4 ; // 7
getSuffixName
获取后缀名
; // jpg
invisibleAsciiToHtml
不可见Ascii码,转html,目前只有
/n => <br> /r => <br> /x20 => //空格
; //1<br>2 3
FormatDate
对 Date 的扩展
; ; //2017-01-01 01:01