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 🙏

© 2026 – Pkg Stats / Ryan Hefner

utils-wh

v1.0.7

Published

工具函数 tool functions

Readme

创建包的目的:

1.测试npm包发布

2.自己的一些工具函数的放置

css安装方法:

main.js:
import 'utils-wh/base.css'

js安装方法:

import * as utils from 'utils-wh'  
or  
import {
  clearCookie,
  ...
} from 'utils-wh'  

里面的函数:

clearCookie:清空cookie

clearCookie()

findall:找出数组中某个元素的index

findall(arr,e)
arr:Array
e:String|Number|Boolean

flexisum:可以接收任何实参,可以递归处理实参

flexisum(args)
args:Number|Number[]
例:
flexisum([1,2,3,4,5,[1,2,3,4,5]],1,2,3,4,5,53,5,4,3,5,6,3,2,3,3,'123')

formatTime:格式化时间

formatTime(time,option)
@param {number} time 时间
@param {string} option
@returns {string} m月d天h小时s分
formatTime(+new Date()-100*1000)
// '2分钟前'

getCookie1:获取cookie

getCookie1(name)
@param {string} name

getCookie2:获取cookie

getCookie2(cname)
@param {string} cname

getnonceStr:获取随机数参数是位数

getnonceStr(num)
{string} num 位数 默认16

isArray:判断是否是数组

isArray(arr)

isArrayLike:是否是类数组

isArrayLike(arr)

param2Obj:url参数改为object

param2Obj(url)

parseTime:时间格式化

parseTime(time, cFormat)
@param {(Object|string|number)} time
@param {string} cFormat y:年 m:月 d:日 h:小时 i:分钟 s:秒 a:周几
@returns {string}

randnum:随机数字范围内

randnum(num)
@param {number} num 最大数

randstr:随机字符串类似上面getnonceStr

randstr(num)
@param {number} num 最大数

setCookie1:设置cookie1

setCookie1(name,val)
{string} name
{any} val

setCookie2:设置cookie1

setCookie2(name,val)
{string} name
{any} val

trim:字符串去两遍空格

trim(str)
{string} str

numtotime:传一个值,转换成时间,和formatTime类似

numtotime(nums,arg)
num:Number 时间秒数
arg:[format,max]
format:String 格式化字符串 '{y}-{m}-{d} {h}:{i}:{s}'
max:String 高位 '30小时50分钟':max:h

getsystem:获取微信还是阿里和手机安卓还是ios

getsystem()
// return [system, channel]
// system:系统ali/weixin/other
// channel:平台iPhone/Android/pc

formatMobile 将手机号变成中间有空格的格式

formatMobile(phoneNO)
{string} phoneNO

compareVersion 对比版本号

compareVersion(reqV, curV);
reqV //旧版本
curV //当前版本
return number   0/1/2  不需改版本/需要改版本/更改大版本

isObjectValueEqual 对比两个对象是否相同

isObjectValueEqual(o1,o2)
{object} o1,o2

geturltoObj 获取url参数变为Object格式

geturltoObj()
return Object

如果有什么觉得是工具函数的,可以发给我

[email protected]