js-util-plus一、typescript编写的常用工具类介绍每次写项目的时候,都要写一些重复的工具类,所以封装了一些常用的工具类。2.如何使用yarnaddjs-util-plus/npminstalljs-util-plus--devimport*asutilfrom'js-util-plus';3.案例是用ts写的,提示很友好4.API1。string1.1strCheck验证util.strCheck(str:string,type:StrEnum)=>booleanenumStrEnum{PHONE='phone',//查电话号码TEL='tel',//查电话号码CARD='card',//查询身份证PWD='pwd',POSTAL='邮政',QQ='qq',EMAIL='邮箱',MONEY=??'钱',URL='网址',IP='IP',DATE='date',NUMBER='number',ENGLISH='english',CHINESE='chinese',LOWER='lower',UPPER='upper',HTML='HTML'}//exampleutil.strCheck('18268100000','phone')=>true1.2strTransformName在两个字符之间加一个空格util.strTransformName(name:string)=>cname//exampleutil.strTransformName('王五')=>'王 五'2.object2.1objIsNullobjectnullutil.objIsNull(obj:object)=>boolean//exampleconstobj={}util.objIsNull(obj)=>false//传参不需要为null,代码已经判断为null3.array3.1arrIsNull数组空util.arrIsNull(arr:any[])=>boolean//exampleconstarr=[]util.arrIsNull(arr)=>false//传参不需要判断为null,在代码4中已经判断为null.store4.1storeCookieSet设置某个cookieutil.storeCookieSet(str:string,value:string)=>void//exampleutil.storeCookieSet('token','token')4.2storeCookieGet获取cookie中的值util.storeCookieGet(str:string)=>string//exampledocument.cookie="token=token";util.storeCookieGet('token')=>'token'4.3storeCookieDelete删除单个cookieutil.storeCookieDelete(str:string)=>void4.4storeCookieRemove删除所有cookiesutil.storeCookieRemove()=>void4.5storeLocalStorageSetsetlocalStorageJSON.stringifyutil.storeLocalStorageSet(name:string,value:any)=>void4.6storeLocalStorageGetgetlocalStorageJSON.parseutil.storeLocalStorageGet(str:string)=>any5.uri5.1uriGetParam获取uri上的某个参数util.uriGetParam(str:string)=>string//examplewww.xxx.com?a=1&b=2util.uriGetParam('a')=>'1'6.浏览器6.1browserGetType获取浏览器类型util.browserGetType()=>string//exampleutil.browserGetType()=>'Opera'||'IE'||'边缘'||'火狐'||'野生动物园'||'铬'||'OverIE10'6.2browserIsNew是否为现代浏览器(IE11及以上)util.browserIsNew()=>boolean//example//如果是IE11及以上则返回trueutil.browserIsNew()=>truegithub地址https://github.com/pengxingwa...感谢明星
