npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

mydao-tools

v0.1.21

Published

业务常用工具类库

Downloads

49

Readme

mydao-tools

常用业务工具类库

安装

npm install mydao-tools --save

全局使用

mian.js中引入:


import Vue from 'vue';
import { BaseTool } from 'gk-tools';
Vue.property['$base'] = BaseTool;

基础工具类(BaseTool)

方法名称:typeEstimate(val)
方法说明:类型判断
参数说明:任意类型(必须)
返回说明:
0:函数类型(function)
1:长整型(bigint)
2:布尔类型(boolean)
3:数值类型(number)
4:对象类型(object、null)
5:字符串类型(string)
6:Symbol类型(symbol)
7: Undefined类型(undefined)
使用方式:
BaseTool.typeEstimate(val)

-----------------------------------------------------------------------------

方法名称:getUUID()
方法说明:生成UUID(通用唯一识别码)
参数说明:无
返回说明:字符串(string)
使用方式:BaseTool.getUUID()

------------------------------------------------------------------------------

方法名称:randomRgbaColor(isRgb)
方法说明:随机生成RGBA或RGB颜色值
参数说明:布尔(boolean,非必须,默认为false=RGBA,设置为true=RGB)
返回说明:字符串(string)
使用方式:BaseTool.randomRgbaColor(isRgb)

------------------------------------------------------------------------------

方法名称:randomHexColor()
方法说明:随机生成HEX颜色值
参数说明:无
返回说明:字符串(string)
使用方式:BaseTool.randomHexColor()

------------------------------------------------------------------------------

方法名称:hexToRgba(obj)
方法说明:HEX颜色值转RGBA
参数说明:对象(object,必须)
hex属性:字符串(string)
opacity属性:字符串(string),默认为1=RGB
返回说明:字符串(string)
使用方式:BaseTool.hexToRgba({hex: '#ffffff', opacity: '.3'})

-------------------------------------------------------------------------------

方法名称:rgbaToHex(rgbaArr)
方法说明:rgba颜色值转hex
参数说明:数组(array,必须)
返回说明:字符串(string)
使用方式:BaseTool.rgbaToHex([155,25,15,.7])

---------------------------------------------------------------------------------

方法名称:getFormatMoney(money)
方法说明:货币金额格式化(12,234,09)
参数说明:字符串(string,必须)
返回说明:字符串(string)
使用方式:BaseTool.getFormatMoney('283284.02483')

---------------------------------------------------------------------------------

方法名称:setCookie(obj)
方法说明:设置Cookie
参数说明:对象(object,必须)
cookieName属性:字符串(string,设置Cookie Name)
cookieValue属性:任意类型
cookieTime属性:字符串(string, 10s=10秒、10h=10小时、10d=10天)
返回说明:无
使用方式:BaseTool.setCookie({cookieName: 'token', cookieValue: 'ASYEGGD#@#@4!', cookieTime: '2d'})

-----------------------------------------------------------------------------------------------------

方法名称:getCookie(cookieName)
方法说明:读取Cookies
参数说明:字符串(string,必须)
返回说明:任意类型
使用方式:BaseTool.getCookie(cookieName)

-----------------------------------------------------------------------------------

方法名称:removeCookie(cookieName)
方法说明:删除Cookies
参数说明:字符串(string,必须)
返回说明:无
使用方式:BaseTool.removeCookie(cookieName)

------------------------------------------------------------------------------------

方法名称:setStorage(key, val)
方法说明:设置浏览器本地存储
参数说明:
key:字符串(string,必须)
val:任意类型(必须)
返回说明:无
使用方式:new BaseTool().setStorage(key, val)

-----------------------------------------------------------------------------------

方法名称:getStorage(key)
方法说明:读取浏览器本地存储
参数说明:字符串(string,必须)
返回说明:任意类型
使用方式:new BaseTool().getStorage(key)

-----------------------------------------------------------------------------------

方法名称:removeStorage(key)
方法说明:移除浏览器本地存储
参数说明:字符串(string,必须)
返回说明:无
使用方式:new BaseTool().removeStorage(key)

------------------------------------------------------------------------------------

方法名称:clearStorage()
方法说明:清空浏览器本地存储
参数说明:无
返回说明:无
使用方式:new BaseTool().clearStorage()

数组工具类(ArrayTool)

方法名称:uniqueArrValue(arr)
方法说明:数组去重
参数说明:数组(array,必须)
返回说明:数组(array)
使用方式:ArrayTool.uniqueArrValue(arr)

---------------------------------------------------------------

方法名称:uniqueArrObject(arr, key)
方法说明:对象数组去重
参数说明:
arr:数组(array,必须)
key:字符串(string,必须,要去重的属性)
返回说明:数组(array)
使用方式:ArrayTool.uniqueArrObject(arr, key)

----------------------------------------------------------------

方法名称:recursionTreeSearchProperty(obj)
方法说明:树结构数组(查找)
参数说明:对象(object,必须)
arr属性:数组(array,必须)
searchKey属性:字符串(string,必须,要查找的属性)
searchValue属性:任意类型(必须,要查找的属性值)
resultKey属性:字符串(string,必须,要返回的属性值)
返回说明:数组(array)
使用方式:new ArrayTool().recursionTreeSearchProperty({arr: arr, searchKey: 'label', searchValue: '2-1', resultKey: 'result'})

------------------------------------------------------------------------------------------------------------------------------------

方法名称:recursionTreeAddPropertiesArray(obj)
方法说明:向树结构数组添加属性(Array方式)
参数说明:对象(object,必须)
arr属性:数组(array,必须)
propertyArr属性:数组(array,必须)
返回说明:无
使用方式:new ArrayTool().recursionTreeAddPropertiesArray({arr: arr, propertyArr: [{key: 'name', value: 'gk'}]})

-------------------------------------------------------------------------------------------------------------------

方法名称:recursionTreeAddPropertiesMap(obj)
方法说明:向树结构数组添加属性(Map方式)
参数说明:对象(object,必须)
arr属性:数组(array,必须)
propertyMap属性:字典(map, 必须)
返回说明:无
使用方式:new ArrayTool().recursionTreeAddPropertiesMap({arr: arr, propertyMap: new Map().set('name', 'gk')})

对象工具类(ObjectTool)

方法名称:resetObject(obj)
方法说明:对象所有属性值清空
参数说明:对象(object,必须)
返回说明:无
使用方式:ObjectTool.resetObject(obj)

屏幕工具类(ScreenTool)

方法名称:isMobile()
方法说明:判断是否移动端
参数说明:无
返回说明:布尔(boolean)
使用方式:ScreenTool.isMobile()

-------------------------------------------------------------

方法名称:isTop()
方法说明:页面置顶
参数说明:无
返回说明:无
使用方式:ScreenTool.isTop()

----------------------------------------------------------------

方法名称:isIntoView(elem)
方法说明:页面锚点
参数说明:字符串(string,必须,标签名、id、class选择器名称)
返回说明:无
使用方式:ScreenTool.isIntoView(elem)

-------------------------------------------------------------

方法名称:openNewLink(href)
方法说明:页面新窗口打开
参数说明:字符串(string,必须)
返回说明:无
使用方式:ScreenTool.openNewLink(href)

--------------------------------------------------------------

方法名称:enablementFullScreen()
方法说明:启动全屏
参数说明:无
返回说明:无
使用方式:ScreenTool.enablementFullScreen()

---------------------------------------------------------------

方法名称:exitFullScreen()
方法说明:退出全屏
参数说明:无
返回说明:无
使用方式:ScreenTool.exitFullScreen()

--------------------------------------------------------------

方法名称:prohibitScale()
方法说明:禁止缩放(移动端)
参数说明:无
返回说明:无
使用方式:ScreenTool.prohibitScale()

---------------------------------------------------------------

方法名称:stopPageMove()
方法说明:设置禁止滚动(桌面端、移动端)
参数说明:无
返回说明:无
使用方式:new ScreenTool().stopPageMove()

----------------------------------------------------------------

方法名称:startPageMove()
方法说明:取消禁止滑动(桌面端、移动端)
参数说明:无
返回说明:无
使用方式:new ScreenTool().startPageMove()

-----------------------------------------------------------------

方法名称:debounce(fun, delay)
方法说明:防抖
参数说明:
fun:函数(function,必须)
delay:数值(number,必须)
返回说明:无
使用方式:ScreenTool.debounce(fun, delay)

------------------------------------------------------------------

方法名称:enablementThrottle(fun, delay)
方法说明:开启节流
参数说明:无
返回说明:无
使用方式:ScreenTool.enablementThrottle(fun, delay)

-------------------------------------------------------------------

方法名称:closeThrottle()
方法说明:关闭节流
参数说明:无
返回说明:无
使用方式:ScreenTool.closeThrottle()

字符串工具类(StringTool)

方法名称:checkHtmlTag(str)
方法说明:检测字符串是否包含HTML标记
参数说明:字符串(string,必须)
返回说明:布尔(boolean)
使用方式:StringTool.checkHtmlTag(str)

--------------------------------------------------------------

方法名称:delHtmlTag(str)
方法说明:去除字符串HTML标记
参数说明:字符串(string,必须)
返回说明:字符串(string)
使用方式:StringTool.delHtmlTag(str)

--------------------------------------------------------------

方法名称:oldstrReplaceNewstr(obj)
方法说明:字符串中将某个字符替换成新字符
参数说明:对象(object,必须)
str属性:字符串(string,必须)
oldStr属性:字符串(string,必须)
newStr属性:字符串(string,必须)
返回说明:字符串(string)
使用方式:StringTool.oldstrReplaceNewstr({str: 'abcde', oldStr: 'a', newStr: 'A'})

--------------------------------------------------------------------------------------

方法名称:checkStrContainChinese(str)
方法说明:检测字符串是否包含中文
参数说明:字符串(string,必须)
返回说明:布尔(boolean)
使用方式:StringTool.checkStrContainChinese(str)

--------------------------------------------------------------

方法名称:checkPureNumber(str)
方法说明:检测字符串是否纯数字
参数说明:字符串(string,必须)
返回说明:布尔(boolean)
使用方式:StringTool.checkPureNumber(str)

--------------------------------------------------------------

方法名称:getCaptionBefore(obj)
方法说明:获取指定字符之前所有字符
参数说明:对象(object,必须)
str属性:字符串(string,必须)
character属性:字符串(string,必须)
返回说明:字符串(string)
使用方式:StringTool.getCaptionBefore({str: 'hello', character: 'e'})

--------------------------------------------------------------

方法名称:getCaptionLast(obj)
方法说明:获取指定字符之后所有字符
参数说明:对象(object,必须)
str属性:字符串(string,必须)
character属性:字符串(string,必须)
返回说明:字符串(string)
使用方式:StringTool.getCaptionLast({str: 'hello', character: 'e'})

--------------------------------------------------------------

方法名称:utf16toUtf8(utf16Str)
方法说明:UTF-16字符转换UTF-8字符
参数说明:字符串(string,必须)
返回说明:字符串(string)
使用方式:StringTool.utf16toUtf8(utf16Str)

--------------------------------------------------------------

方法名称:forWords(obj)
方法说明:字符串敏感词过滤或标红
参数说明:对象(object,必须)
oldStr属性:字符串(string,必须)
wordsStr属性:字符串(string,必须)
singleWord属性:布尔(boolean,非必须,默认false,全部=false,单个=true)
markedInRed属性:布尔(boolean,非必须,默认false,过滤=false,标红=true)
返回说明:字符串(string)
使用方式:StringTool.forWords({oldStr: `djashgjkd习近平dasdsa习近平aajsd`, wordsStr: '习近平', singleWord: true, markedInRed: true})

日期工具类(DateTool)

方法名称:getNowFormatDate(obj)
方法说明:当前时间格式化
参数说明:对象(object,非必须)
format属性:字符串(string,非必须,默认date,显示日期=date,显示日期时间=datetime)
seperator属性:字符串(string,非必须,默认-,间隔符)
返回说明:字符串(string)
使用方式:DateTool().getNowFormatDate({format: 'dateTime', seperator: '/'})

----------------------------------------------------------------------------------------

方法名称:stringToDate(dateStr)
方法说明:String日期转Date
参数说明:字符串(string,必须,日期格式=2021-01-01)
返回说明:日期(Date)
使用方式:DateTool.stringToDate('2021-11-01 11:31:10')

-----------------------------------------------------------------------------------------

方法名称:dateToString(obj)
方法说明:Date日期转String
参数说明:对象(object,必须)
date属性:日期(Date,必须)
format属性:字符串(string,非必须,默认date,显示日期=date,显示日期时间=datetime)
seperator属性:字符串(string,非必须,默认-,间隔符)
返回说明:字符串(string)
使用方式:DateTool.dateToString({date: new Date(), format: 'dateTime', seperator: '/'})

--------------------------------------------------------------------------------------------

方法名称:getWeek(date)
方法说明:根据日期获取星期
参数说明:日期(Date,必须)
返回说明:字符串(string)
使用方式:DateTool.getWeek(new Date('2021-11-13 11:59'))

-------------------------------------------------------------------------------

方法名称:getWeekDayFront(dateString)
方法说明:获取当前日期的近一周(包括当前日期)
参数说明:字符串(string,必须)
返回说明:数组(Array)
使用方式:DateTool.getWeekDayFront('2021-11-14')

-------------------------------------------------------------------------------

方法名称:getWeekDayAfter(date)
方法说明:获取当前日期的后一周(包括当前日期)
参数说明:日期(Date,必须)
返回说明:数组(Array)
使用方式:DateTool.getWeekDayAfter(new Date('2021-11-15'))

-------------------------------------------------------------------------------

方法名称:getCurrentMonthFirst()
方法说明:获取当前月的第一天
参数说明:无
返回说明:字符串(string)
使用方式:DateTool.getCurrentMonthFirst()

-------------------------------------------------------------------------------

方法名称:getCurrentMonthLast()
方法说明:获取当前月的最后一天
参数说明:无
返回说明:字符串(string)
使用方式:DateTool.getCurrentMonthLast()

文件工具类(FileTool)

方法名称:getExtName(fileName)
方法说明:获取文件名的后缀
参数说明:字符串(string,必须)
返回说明:字符串(string)
使用方式:FileTool.getExtName(fileName)

--------------------------------------------------------

方法名称:getBinaryOrTextOrBase64(obj)
方法说明:文件处理
参数说明:object(对象,必须)
file属性:文件(File,必须)
type属性:数值(number,必须)
0:将文件转成二进制数组
1:将文件转成二进制字符串
2:将文件转成base64编码
3:读取文本字符串
返回说明:异步(Promise)
使用方式:FileTool.getBinaryOrTextOrBase64({file=file, type=2})

-------------------------------------------------------

方法名称:getBinaryFile(file)
方法说明:将文件转换成二进制文件
参数说明:文件(File)
返回说明:二进制(Blob)
使用方式:FileTool.getBinaryFile(file)

-------------------------------------------------------

方法名称:getFormData(obj)
方法说明:将文件打包到formData
参数说明:object(对象,必须)
file属性:文件(File,必须)
type属性:数值(number,非必须,默认=1,文件=1,二进制=2)
返回说明:表单(FormData)
使用方式:FileTool.getFormData({file=file, type=2})

验证工具类(VerificationTool)

方法名称:checkAccount(account)
方法说明:账号验证(用户名至少6位,必须包含一个数字、字母、特殊字符)
参数说明:字符串(string)
返回说明:布尔(boolean)
使用方式:VerificationTool.checkAccount(account)

-----------------------------------------------------------------------

方法名称:checkPassword(password)
方法说明:密码验证(密码至少8位,必须包含一个大写和小写字母、数字)
参数说明:字符串(string)
返回说明:布尔(boolean)
使用方式:VerificationTool.checkPassword(password)

-----------------------------------------------------------------------

方法名称:checkPhone(phone)
方法说明:手机号验证
参数说明:字符串(string)
返回说明:布尔(boolean)
使用方式:VerificationTool.checkPhone(phone)

-----------------------------------------------------------------------

方法名称:checkEmail(email)
方法说明:电子邮箱验证
参数说明:字符串(string)
返回说明:布尔(boolean)
使用方式:VerificationTool.checkEmail(email)

-----------------------------------------------------------------------

方法名称:checkURL(url)
方法说明:URL格式验证
参数说明:字符串(string)
返回说明:布尔(boolean)
使用方式:VerificationTool.checkURL(url)

-----------------------------------------------------------------------

方法名称:checkChineseName(name)
方法说明:汉字姓名验证(请输入至少两个汉字、不包含字母和数字)
参数说明:字符串(string)
返回说明:布尔(boolean)
使用方式:VerificationTool.checkChineseName(name)

-----------------------------------------------------------------------

方法名称:checkInputPureNumber(str)
方法说明:input输入纯数字
参数说明:字符串(string)
返回说明:字符串(string)
使用方式:VerificationTool.checkInputPureNumber(str)

-----------------------------------------------------------------------

方法名称:checkInputTrimAndTabEnter(str)
方法说明:input输入禁止空格、换行
参数说明:字符串(string)
返回说明:字符串(string)
使用方式:VerificationTool.checkInputTrimAndTabEnter(str)

-----------------------------------------------------------------------

方法名称:checkInputTrimAndChinese(str)
方法说明:input输入禁止空格和汉字
参数说明:字符串(string)
返回说明:字符串(string)
使用方式:VerificationTool.checkInputTrimAndChinese(str)

-----------------------------------------------------------------------

方法名称:checkIdCard(idCard)
方法说明:身份证验证
参数说明:字符串(string)
返回说明:布尔(boolean)
使用方式:VerificationTool.checkIdCard(idCard)

-----------------------------------------------------------------------

方法名称:getIdCardInfo(idCard)
方法说明:将文件转换成二进制文件
参数说明:字符串(string)
返回说明:对象(object)
使用方式:VerificationTool.getIdCardInfo(idCard)

请求工具类(RequestTool)

npm install axios --save


使用示例:
RequestTool.post({
  url: TunnelInterfaces('用户').login,
  data: {id: 120}
}).then((res) => {
  const {succeed, content} = RequestTool.getResult(res);
  if (succeed) {
    // 接口响应成功,返回正常数据
    console.log(content);
  }
});

--------------------------------------------------------------------

响应字段说明:
succeed:响应是否成功
content:响应数据体

--------------------------------------------------------------------

方法名称:
RequestTool.setBaseUrl(baseUrl)
RequestTool.setAuthorization(token)
RequestTool.get({url: '接口名称', params: {name: 'gk'}})
RequestTool.post({url: '接口名称', data: {name: 'gk'}})
RequestTool.postCarry({url: '接口名称', data: {name: 'gk'}})

参数说明:
baseUrl:字符串(string,必须)
token:字符串(string,必须)
url:字符串(string,必须)
params:对象(object,非必须,适用于GET)
data:对象(object,非必须,适用于POST)
返回说明:异步(Promise)

隧道监控项目-接口(TunnelInterfaces)