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 🙏

© 2025 – Pkg Stats / Ryan Hefner

jh-util

v1.2.7

Published

javascript工具类库

Downloads

83

Readme

jh-util

一个JavaScript工具类库, 封装了常用的api

引入方法

首先使用npm安装jh-util包:
 npm i jh-util -S
然后使用import引入所需方法
import {
  // 动画 animation
  animate
  
  // dom操作 JDom
  scrollTo,
  query,
  
  // 对象操作 jObject
  deepCopy,
  
  // 日期 jDate
  getNowDate,
  formatDate,
  
  // 类型校验 JType类
  isNumber,
  isString,
  isObject,
  isArray,
  isNull,
  isSymbol,
  isUndef,
  isFunc,

  // 性能优化 JPerformance类
  throttle,
  debounce,

  // 获取Url参数 JParam类
  getParam,
  getParamByUrl

  // 表单校验 JValid类
  isPhone,
  isEmail,
  isIdentityCard,
  isPlate,
  isDate,
  isColor,
  isUrl

} from 'jh-util'

动画 animation 模块

 /** 
 * 线性动画
 * start: 起始值
 * end: 结束值
 * time: 持续时间
 * callback: 回调函数 第一个参数为当前值
 */
 animate (start, end, time, callback) 

对象 JDom 类

/**
  * 滚动条滚动到指定位置
  * @param {string|dom} dom 选择器或domcument
  * @param {number} target 目标scrollTop
  * @param {number} time 动画时间
 */
  scrollTo (dom, target, time = 300, isY = true)

对象 jObject 模块

/**
 对象深拷贝
 解决循环循环引用
 可拷贝以symbol类型为属性名打的属性
 可拷贝function属性但为浅拷贝
 可拷贝值为undefined的属性
 @param {any} val 
/
deepCopy (obj)

日期 jDate 模块

  /**
   * 将传入事件转化为所需格式
   * @param {Date|string|number} date 接收Date对象,时间字符串,以及时间戳
   * @param {string} fSplit 若不为空则将年月日以该字符隔开,若为空则返回时间戳
   * @param {string} sSplit 若不为空则日期会带有时分秒并时分秒以该字符隔开
  */
  - formatDate(date, fSplit = '-', sSplit)
  /**
   * 获取当前 yyyy-MM-dd 格式时间字符串
   * @param {*} fSplit 如为空返回时间戳,不为空则返回以该字符为分隔符的时间
   * @param {*} sSplit 
   * @return {string}
  */
  getNowDate(fSplit = '-', sSplit)

类型校验 JType

  • isNumber(val) 判断 val 是否为 Number 类型
  • isString(val) 判断 val 是否为 String 类型
  • isObject(val) 判断 val 是否为 Object 类型
  • isArray(val) 判断 val 是否为 Array 类型
  • isNull(val) 判断 val 是否为 Null 类型
  • isSymbol(val) 判断 val 是否为 Symbol 类型
  • isUndef(val) 判断 val 是否为 undefined 类型
  • isFunc(val) 判断 val 是否为 Functionn 类型

性能优化 JPerformance

  • throttle(fn, time) 节流函数
  • debounce(fn, time) 防抖函数

获取Url参数 JParam类

  • getParam() 获取当前页面参数值 getParam(key) 传入 key 值获取参数名为 key 的参数值 getParam() 不传值则获取所有参数的键值对对象
  • getParamByUrl() 获取某个 url 的参数值 getParam(key, url) 如果同时传入 key 与 url 则返回 对应该 key 的参数值字符串 getParam(url) 如果只传入 url 则获取该 url 所有参数的键值对对象

表单验证 JValid 类

  • isPhone(val) 验证手机号码格式
  • isEmail(val) 验证邮箱格式
  • isIdentityCard(val) 验证身份证号格式
  • isPlate(val) 验证车牌号格式
  • isDate(val) 验证日期格式 支持以下三种格式 yyyy-mm-dd、 yyyy/mm/dd、 yyyy mm dd
  • isColor(val) 验证十六进制颜色
  • isUrl(val) 验证Url格式