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 🙏

© 2024 – Pkg Stats / Ryan Hefner

dpape-utils

v1.0.6

Published

Common tool class

Downloads

7

Readme

dpape-utils

Introduce

Common tool class

Install

npm i dpape-utils -S

描述

封装并发布 npmjs 常用的工具库。是一个模块化 JavaScript 实用工具库。

安装

npm i dpape-utils -S
# OR
yarn add dpape-utils -S

1. Rules

验证规则,正则表达式

import { Rules } from 'dpape-utils';
// 正整数isInteger
const value = 12.5;
Rules.INTEGER.test(value); // -- false
1.1 正则列表

| 名称 | 说明 | | :-------: | :---------------------------------------------------------------: | | INTEGER | 正整数 | | NUMBER | 数字,包含负数或 0 或小数 | | FLOAT | 浮点数,正负 | | CHINESE | 只有中文 | | ENGLISH | 只有英文 | | IP | IP 地址 | | PORT | 端口 | | NETMASK | 子网掩码 | | DOMAIN | 域名 | | URL | URL | | EMAIL | 邮箱:Email | | PHONE | 手机号 | | TELEPHONE | 电话号码:xxxx-xxxxx | | PASSWORD | 密码规则:以字母开头,长度在 6-18 之间,只能包含字符、数字和下划线 | | PASSWORD | 密码规则:以字母开头,长度在 6-18 之间,只能包含字符、数字和下划线 | | ZIPCODE | 邮政编码 | | NICKNAME | 昵称 | | MONEY | 金额,支持$¥ 前缀,支持以金钱单位结束[元] |

2. BrowserInfo

判断设备|浏览器类型

import { BrowserInfo } from 'dpape-utils'
//是否是Android终端|浏览器
console.log(BrowserInfo.isAndroid)
2.1 浏览器类型列表

| 名称 | 说明 | | :-------: | :---------------------: | | isAndroid | 是否是 Android 终端 / 浏览器 | | isIOS | 是否 IOS 浏览器终端 | | isIphone | 是否是苹果浏览器 | | isIpad | 是否是 IPad 浏览器 | | isLinux | 是否是 Linux 平台浏览器 | | isWeixin | 是否是微信平台浏览器 | | isAli | 是否是支付宝平台浏览器 | | isMobile | 是否是手机端 |

3. Type

数据类型判断

import { Type } from 'dpape-utils'
const isStr = Type.IsString('123')
console.log(isStr)  // true
3.1 类型列表方法

| 名称 | 说明 | | :---------: | :----------------: | | IsString | 是否字符串类型 | | IsObject | 是否字符串类型 | | IsNumber | 是否数字类型 | | IsArray | 是否数组类型 | | IsUndefined | 是否 Undefind 类型 | | IsFunction | 是否函数类型 | | IsNull | 是否 NULL 类型 | | IsSymbol | 是否标记类型 | | IsBoolean | 是否布尔类型 | | IsBigInt | 是否大整型类型 | | IsDate | 是否日期类型 |

4. Cookies

Cookies操作

import { Cookies } from 'dpape-utils'
// 设置cookie
Cookies.set('token','1010100110',{
  // 默认 ‘/’
  path:'/sub'
  expires:30000
})
//获取cookie
Cookies.get('token')
//删除cookie
Cookies.del('token','/sub')

5. getQueryHash

获取地址栏hash参数

import { getQueryHash } from 'dpape-utils'
// eg: http://test.cn/#/home?test=11111
getQueryHash('test') // -- "11111"

6. getQueryParam

获取地址栏参数,不包含锚点

import { getQueryParam } from 'dpape-utils'
// eg: http://test.cn/home.html?test=222222
getQueryParam('test') // -- "222222"

7. capitalize

首字母转大写

import { capitalize } from 'dpape-utils'
capitalize('user') // --> "User"

8. getFileExtension

获取文件扩展名

import { getFileExtension } from 'dpape-utils'
getFileExtension('password.txt') // --> .txt

9. bytesToSize

字节单位转换

import { bytesToSize } from 'dpape-utils'
bytesToSize(1257) // --> 1.23 KB

10. deepObjectCopy

对象深度拷贝

import { deepObjectCopy } from 'dpape-utils'
const value = {a:1}
const copyValue = deepObjectCopy(value)

11. isObject

是否对象

import { isObject } from 'dpape-utils'
isObject('abc') // --> false

12. isEmptyObject

是否空对象

import { isEmptyObject } from 'dpape-utils'
isEmptyObject({}) // --> true

13. isJsonString

是否JSON数据类型字符串

import { isJsonString } from 'dpape-utils'
isJsonString('{a:1}') // --> true

14. arrayUnique

数组去重复项

import { arrayUnique } from 'dpape-utils'
arrayUnique([1,2,3,4,1,2,3]) // --> [1,2,3,4]

15. arrayRemove

删除数组中指定值,只支持数字类型和字符串类型

import { arrayRemove } from 'dpape-utils'
arrayRemove([1,2,3,4],3) // --> [1,2,4]

16. isHasSpecChar

字符串中是否含有特殊字符

import { isHasSpecChar } from 'dpape-utils'
isHasSpecChar('abce%%gdsda') // --> true

17. isFunction

是否函数对象

import { isFunction } from 'dpape-utils'
isFunction(123) // --> false

18. dateFormat

格式化日期时间

import { dateFormat } from 'dpape-utils'
dateFormat('2020/2/1') // --> 2020-02-01 00:00:00
dateFormat('2020-07-08T07:10:41.329Z') // --> 2020-07-08 15:10:41

19. formatSecondsTime

将秒时间格式化,{h}小时{m}分{s}秒

import { formatSecondsTime } from 'dpape-utils'
formatSecondsTime(100) // --> 0小时1分40秒

20. toDecimal

保留小数位数

import { toDecimal } from 'dpape-utils'
toDecimal(3.1415,2) // --> 3.14

21. getRandomNum

生成一个随机数

import { getRandomNum } from 'dpape-utils'
getRandomNum(100,10000,2)

22. getMultipleRandom

生成多个随机数

import { getMultipleRandom } from 'dpape-utils'
getMultipleRandom(5,100,10000) // 生产5个100~10000的随机数

23. 金额转大写

import { digitUppercase } from 'dpape-utils'
digitUppercase(100) // 壹佰元整

24. moneyToRMB

数字转人民币形式

import { moneyToRMB } from 'dpape-utils'
moneyToRMB(45.5,2) // ¥45.50

25. isMoney

判断字符串是否是金钱格式数据

import { isMoney } from 'dpape-utils'
isMoney(050) // false

26. isIdCard

是否合法身份证号

import { isIdCard } from 'dpape-utils'
isIdCard('43011132423432') // false

27. isBankCard

是否银行卡号

import { isBankCard } from 'dpape-utils'
isBankCard('6214830213714487') // true

28. isDomain

是否合法域名(包含IP)

import { isDomain } from 'dpape-utils'
isDomain('baidu.com') // true

29. isMac

是否合法的Mac地址

import { isMac } from 'dpape-utils'
isMac('00-00-00-00-00-00') // false

30. getNetmask

获取子网掩码

import { getNetmask } from 'dpape-utils'
getNetmask(32) // 255.255.255.255

30. isDHCPIp

根据lanIp和lan掩码判断Ip地址的合法性

import { isDHCPIp } from 'dpape-utils'
isDHCPIp('192.168.23.1','255.255.255.255','192.168.23.2')

31. getHtmlClosestTag

查找父级最邻近的元素

import { getHtmlClosestTag } from 'dpape-utils'
getHtmlClosestTag('当前dom对象','选择器,父级元素')

32. getPureHtml

过滤敏感HTML标签

import { getPureHtml } from 'dpape-utils'
getPureHtml('<div>hello world</div>')

33. getOffset

获取元素绝对位置,对浏览器版本有要求

import { getOffset } from 'dpape-utils'
getOffset(document.querySelector('#app'))

34. LeftPad

小于10前面补零

import { LeftPad } from 'dpape-utils'
LeftPad(5) // --> 05

35. getDocumentMaxZIndex

获取文档流最大的zindex

import { getDocumentMaxZIndex } from 'dpape-utils'
const maxZIndex = getDocumentMaxZIndex()