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

eric-tool

v1.0.8

Published

``` npm install eric-tool ```

Readme

安装

npm install eric-tool

导入

const erictool = require('eric-tool')

日期类

定义格式化时间

dateFormat(dateStr,format,type)
// dateStr  日期时间                                            默认:当天
// format   格式:YYYY-MM-DD || YYYY-MM-DD hh:im:ss ||........  默认:YYYY-MM-DD
// type     分割类型是“-”还是“/”  2022-01-01 || 2022/01/01       默认:/
const dtStr = erictool.dateFormat('2021-01-01','YYYY-MM-DD',"/")
// 结果  2022/01/01

获取几周(前|后)的日期

getWeekdate(dateStr,week,format)
// dateStr  	日期时间                                         	 默认:当天
// week 	第几周,正数(1...)是几周后,负数(-1...)是几周前         默认:1周后
// format     	格式:YYYY-MM-DD || YYYY-MM-DD hh:im:ss ||........	 默认:YYYY-MM-DD
const dtStr = erictool.getWeekdate('2021-01-01',1,'YYYY-MM-DD')
// 结果  2022-01-08

获取几个月(前|后)的当天

getMonthSameDay(dateStr,month,format)
// dateStr  	日期时间                                         	 默认:当天
// month 	第几月,正数(1...)是几月后,负数(-1...)是几月前  	    默认:1月后
// format     	格式:YYYY-MM-DD || YYYY-MM-DD hh:im:ss ||........	 默认:YYYY-MM-DD
const dtStr = erictool.getMonthSameDay('2021-01-15',1,'YYYY-MM-DD')
// 结果  2022-02-15

获取几个月(前|后)的1号

getMonthFirstDay(dateStr,month,format)
// dateStr  	日期时间                                         	   默认:当天
// month 	第几月,正数(1...)是几月后,负数(-1...)是几月前  	      默认:1月后
// format     	格式:YYYY-MM-DD || YYYY-MM-DD hh:im:ss ||........	   默认:YYYY-MM-DD
const dtStr = erictool.getMonthFirstDay('2021-01-15',1,'YYYY-MM-DD')
// 结果  2022-02-01

当前是星期几 默认当天

getWeek(dateStr,type)
// dateStr  	日期时间                                          默认:当天
// type 	id,name,选择id:返回数组1~7,选择name:返回中文  	    默认:1月后 
const dtStr = erictool.getWeek('2021-01-15','name')
// 结果  星期五

UID类

生成UID

uuid(len, radix)
// len  	生成uid的长度                                      	  默认:16
// radix 	产生uid的所使用的字符串长度(0-9A-Za-z)  	            默认:62 
const dtStr = erictool.uuid()
// 结果  S2550qqZebLum6Nv

字符串类

判断http返回回来的值是否报错

isHttpErr(value)
// value  	http返回过来的值
const dtStr = erictool.isHttpErr(value)
// 结果  true | false

判断http返回回来的值是否报错

isNull(value)
// value  	需要判断的值,undefined,null,'',' ',NaN,[] 都返回true,其他返回false
const dtStr = erictool.isNull('')
// 结果  true

布尔值返回

isBoolean(value)
// value  	需要判断的值,true返回是,false返回否
const dtStr = erictool.isBoolean('')
// 结果  true

判断日期是不是InvalidDate

isInvalidDate(value)
// value  	需要判断的值,是的话返回true,否的话返回false
const dtStr = erictool.isInvalidDate('2021-01-01')
// 结果  false

千分號

formatNumber(value)
// value  	    需要判断的值,是的话返回true,否的话返回false
//precision     后面有小数点就需要填,几位小数点就放几,没有就不用放    默认:0
const dtStr = erictool.formatNumber(1000.00,2)
// 结果  false

字符串转成数值类型

toNumber(value)
// value  	需要判断的值
const dtStr = erictool.toNumber('12asd._')
// 结果  12

把xml格式转成json格式

XmlToJson(value)
// value  	需要把xml格式的数据
const dtStr = erictool.XmlToJson(value)
// 结果  返回xml格式解析成json格式的数据

排序

sort(res, fields,type)
// res      需要排序的数据	
// fields  	需要排序的栏位,是个数组
// type  	排序是类型,排序的是字符串还是数字  ,字符串传string,数字传number   默认:string
let res =[{'name':'2'},{'name':'1'},{'name':'10'}]
const dtStr = erictool.sort(res, ['name'],'number')
// 结果  [{'name':'1'},{'name':'2'},{'name':'10'}]

开源协议

ISC