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

h5-tools

v1.1.20

Published

tools

Downloads

3

Readme

常用js函数

npm install h5-tools --save
import {} from 'h5-tools'

1、获取url参数

url:http:www.xxx.com/xxx/index.html?id=123&name=布玛
getUrlParam("id")  => 123
getUrlCHParams("name")  => 布玛

2、获取元素宽高坐标边距等

<div ref="root" width="375" height="600"></div>
getElmInfo(el)  => {width:375,height:600,left:0,right:0,bottom:0,top:0,x:0,y:0}

3、获取当前所在系统环境

getPlace()  => { inAndroid: false, inIos: true, inMobile: true, inQQ: false, inQQBrower: false, inWechat: false, inWeibo: false }
getPlace("inAndroid")   => false
getPlace("inIos")   => true
{
	inAndroid: 	安卓
	inIos: 	ios
	inMobile: 	移动端
	inQQ: 	QQ
	inQQBrower: 	QQ浏览器
	inWechat: 	微信
	inWeibo: 	微博
}

4、打开或下载APP

openApp({ ios_scheme,ios_download,android_scheme,and_download,time })
{
	ios_scheme:	ios打开APP协议及地址
	ios_download:	ios下载APP地址
	android_scheme:	android打开APP协议及地址
	and_download:	android下载APP地址
	time: 	默认3000
}

5、随机生成指定长度字符串

randomString(5)		=> uh27x

6、根据历史时间戳和指定时间戳获取多少年/月/周/天/小时/分钟之前

dateDiff(1594012494000)		=> 1个月之前 参数2可选,默认当前时间戳 

根据日期格式获取时间戳 formp(); // 默认获取当前时间戳,formp('2020-09-24') 7、根据时间戳获取指定时间格式

format(1594012494000)		=> 2020-07-06 13:14:54 默认格式:YYYY-MM-DD HH:MM:SS
format(1594012494000,'YYYY/MM/DD')		=> 2020/07/06
{
	MM-DD
	YYYY/MM/DD
	YYYY-MM-DD
	YYYY-MM-DD HH:MM
	YYYY-MM-DD HH:MM:SS
	HH:MM MM月DD日
	YYYY年MM月DD日 HH:MM
	YYYY年MM月DD日 HH:MM:SS
}

8、 设置单个session值

setItem(key,value)

9、 设置多个session值

setItems({key1:value1,key2:value2,key3:value3})

10、获取单个session值 参数为String

getItem(key)		=> value => String

11、获取多个session值 参数为Array

getItem(keys)		=> value => Object

12、清除单个session值 参数为String

removeItem(key)

13、清除多个session值 参数为Array

removeItems(keys)

14、正则校验

regex(reg,value)		=> Boolean

15、数组去重 [1,2,3,4,5,2] [1,6,8,9] => [1,2,3,4,5,6,8,9]

distinct(arr1,arr2,...)		=> Array

16、数组取相同值 [1,2,3,5] [2,5,7,8] => [2,5]

same(arr1,arr2)		=> Array

17、数组删除重复元素 [1,4,6,8,9] [1,2,3,7,8] => [2,3,4,6,7,9]

diff([1,4,6,8,9],[1,2,3,7,8])		=> Array

18、字符串指定位置替换别的字符串

changeStr(str,index,changeStr)
例:changeStr('abcdefgh',3,'***')		=> abc***gh

19、检测是否是url地址

isURL(str)
例:isURL('www.baidu.com')		=> true || false

20、是否字符串

isString(str)
例:isString('dsadsad')		=> true || false

21、是否数字

isNumber(num)
例:isNumber(3213')		=> true || false

22、是否布尔

isBoolean(boolean)
例:isBoolean('dfsf')		=> true || false

23、是否函数

isFunction(o)
例:isFunction(obj')		=> true || false

24、是否null

isNull(num)
例:isNull(3213')		=> true || false

25、是否undefined

isUndefined(num)
例:isUndefined(3213')		=> true || false

26、是否对象

isObj(obj)
例:isObj('3213')		=> true || false

27、是否数组

isArray(obj)
例:isArray('3213')		=> true || false

28、是否时间

isDate(obj)
例:isDate('3213')		=> true || false

29、去除Html标签

removeHtmltag(str)
例:removeHtmltag('<div>dsad</div>')		=> dsad

30、动态引入js

injectScript(str)
例:injectScript('https://yufabu_s.1667799.com/js/app.05d8fc09.js')		

31、根据url地址下载文件

download(url)
例:download('https://yufabu_s.1667799.com/js/app.05d8fc09.js')		

32、去除字符串空格-- type: 默认1-所有空格 2-前后空格 3-前空格 4-后空格

trim(str)
例:trim(' Hello World')		=> HelloWorld'

33、字符串大小写转换 type: 1:首字母大写 2:首字母小写 3:大小写转换 4:全部大写(默认) 5:全部小写

changeCase(str,type)
例:changeCase('hello')  => HELLO		

33、在字符串中插入新字符串

insertStr(str,index, newStr)
例:insertStr("abc",1,"****")	=> a****bc

34、获取静态资源内容/域名

getDomain(url)  url是资源地址 可选
返回一个promise