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

panda-utils

v1.0.6

Published

Some of utility functions used in dialy.

Readme

panda-utils

自己平常用的一些的工具函数

如何使用

# 安装
$ npm install panda-utils --save

# 引入
import pandaUtils from 'panda-utils'

# 使用
pandaUtils.somefunc()

分为以下几个模块

时间日期相关

  • 月维度:
// 获取某年某月中有多少天
getDaysInOneMonth(<year>,<month>)

// eg:
pandaUtils.getDaysInOneMonth(2020,2); // 29
// 获取上月第一天的开始时刻
getStartTimeInLastMonth()

// eg(统一返回string格式的GMT中国标准时间):
pandaUtils.getStartTimeInLastMonth(); // Sat Feb 01 2020 00:00:00 GMT+0800 (中国标准时间)
// 获取上月最后一天的结束时刻
getEndTimeInLastMonth()

// eg:
pandaUtils.getEndTimeInLastMonth(); // Sat Feb 29 2020 23:59:59 GMT+0800 (中国标准时间)

// 扩展
如果要获取上月最后一天的开始时刻就减掉一天的毫秒数:pandaUtils.getEndTimeInMonth().getTime()-86400000
// 获取本月第一天的开始时刻
getStartTimeInMonth()

// eg:
pandaUtils.getStartTimeInMonth(); // Sun Mar 01 2020 00:00:00 GMT+0800 (中国标准时间)
// 获取本月最后一天的结束时刻
getEndTimeInMonth()

// eg:
pandaUtils.getEndTimeInMonth(); // Tue Mar 31 2020 23:59:59 GMT+0800 (中国标准时间)
  • 周维度:
// 获取本周第一天的开始时刻
getStartTimeInWeek()

// eg:
pandaUtils.getStartTimeInWeek(); // Mon Mar 02 2020 00:00:00 GMT+0800 (中国标准时间)
// 获取本周最后一天的结束时刻
getEndTimeInWeek()

// eg:
pandaUtils.getEndTimeInWeek(); // Sun Mar 08 2020 23:59:59 GMT+0800 (中国标准时间)
  • 日维度:
// 获取昨天的开始时刻
getStartTimeInYesterday()

// eg:
pandaUtils.getStartTimeInYesterday(); // Wed Mar 04 2020 00:00:00 GMT+0800 (中国标准时间)
// 获取昨天的结束时刻
getEndTimeInYesterday()

// eg:
pandaUtils.getEndTimeInYesterday(); // Wed Mar 04 2020 23:59:59 GMT+0800 (中国标准时间)
// 获取今天的开始时刻
getStartTimeInToday()

// eg:
pandaUtils.getStartTimeInToday(); // Thu Mar 05 2020 00:00:00 GMT+0800 (中国标准时间)
// 获取今天的结束时刻
getEndTimeInToday()

// eg:
pandaUtils.getEndTimeInToday(); // Thu Mar 05 2020 23:59:59 GMT+0800 (中国标准时间)
  • 时间处理
// 将时间戳转化为自定义的时间格式
formatTime(<number>, <format>)

// eg:
const num = new Date().getTime();
pandaUtils.formatTime(num, "Y-M-D h:m:s"); // 2020-03-05 17:38:33
pandaUtils.formatTime(num, "Y年M月D日h时m分s秒"); // 2020年03月05日17时38分33秒

表单验证相关

// 手机号码格式验证
checkPhoneNum(<手机号码(Number类型)>)

// eg:
pandaUtils.checkPhoneNum(12345678901); // false

判断客户端环境

// 判断是否为IOS
checkInIOS()

// eg:
pandaUtils.checkInIOS(); 
// 判断是否为Andriod
checkInAndriod()

// eg:
pandaUtils.checkInAndriod(); 
// 判断是否为微信
checkInWx()

// eg:
pandaUtils.checkInWx();

价格数字处理

// 分转换为元
toDecimal(<分(Number类型)>)

// eg:
pandaUtils.toDecimal(1234); // 12.34
// 分转换为元,去掉小数点后面的数值
toDecimal0(<Number>)

// eg:
pandaUtils.toDecimal0(1234); // 12
// 分转换为元,并保留小数点后两位(不够两位强制补0)
toDecimal0(<Number>)

// eg:
pandaUtils.toDecimal2(10); // 0.10
  • 添加完善中...

License

MIT