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

hjai-utils

v1.0.6

Published

js工具库

Readme

npm Build Status Coverage Status LICENSE MIT

前端业务代码工具库

目的:高效率完成前端业务代码

安装使用

  1. 直接下载dist目录下的utils.min.js使用,支持UMD通用模块规范
  2. 使用npm安装

浏览器:

  <script src="utils.min.js"></script>
  <script>
      var OS = utils.getOS()
  </script>

npm:

$ npm install --save hjai-utils

webpack、RequireJS、SeaJS等

// 完整引入
const utils = require('hjai-utils/dist/utils.min.js');
const OS = utils.getOS();

import * as utils from 'hjai-utils/dist/utils.min.js';
utils.getOS();

推荐使用方法

也可以不需要完整引入所有函数,所以只引入需要使用的方法即可。

// 只引入部分方法('hjai-utils/<方法名>')
const getOS = require('hjai-utils/getOS');
const OS = getOS();

import * as utils from 'hjai-utils/getOS';
utils.getOS();

API文档

Array

  arrayEqual  判断两个数组是否相等

Device

  getExplore  获取浏览器类型和版本号

  getOS  获取操作系统类型

Random

  randomColor   随机生成颜色

  randomNum  生成指定范围随机数

Regexp

  isEmail  判断是否为邮箱地址

  isIdCard  判断是否为身份证号

  isPhoneNum  判断是否为手机号

  isUrl  判断是否为URL地址

Time

  getTimer  获取当前已经运行了多少豪秒

  getNowStamp  获取当前时间戳

  getFullDate  根据时间戳获取完整日期 yy-mm-dd hh:mm:ss

  getFullDateArray  根据时间戳获取日期的数组形式 [yy,mm,dd,hh,mm,ss]

  getTime  根据时间戳获取时间的日期格式 hh:mm:ss

  getTimeArray  根据时间戳,获取时间的数组形式[hh,mm,ss]

  getDate  根据时间戳,获取日期的日期形式 yy-mm-dd

  getFullDate  根据时间戳获取完整日期 yy-mm-dd hh:mm:ss

  getFullDateArray  根据时间戳获取日期的数组形式 [yy,mm,dd,hh,mm,ss]

  getCountDown  根据传入的时间(秒/时间戳10位/时间戳13位),返回倒计时的数组形式[dd,hh,mm,ss]

  getPastSecond  获取指定时间戳距离0点已经过去了多少秒(不传,就是今天过去了多少秒)

  getTimeArray  根据时间戳,获取时间的数组形式[hh,mm,ss]

  getDateArray  根据时间戳,获取日期的数组形式 [yy,mm,dd]

  getWeek  获取指定的week的日期数据

  getMonthByOffset  获取指定的month的日期列表

  getWeekNum  根据时间戳/日期,获取属于今年第几周(周一开始)

Event

  addEventListenerOnce  添加一次监听

  addEventListener  添加监听

  removeEventListener  移除监听

  dispatchEvent  派发监听回调

  removeAllListener  移除所有监听

Data (默认为localStorage存储,传'ses'则为sessionStorage存储)

  setData  存储数据到localStorage

  getData  从localStorage取数据

  delData  清除localStorage指定的键值对应的数据

  delAllData  清空localStorage全部数据

Merge

  merge  合并对象