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

rk-util

v1.0.0

Published

project-init 常用工具类

Readme

project-init 常用工具类

Install

yarn add rk-util

Usage

import rkUtil from 'rk-util'
rkUtil.addZero(24, 4) === '0024'

API

  /**
   * 移除对象中值为空的键值对
   * @param obj
   */
  objectRemoveValueIsNull<T>(obj: T): T
  
  /**
   * 判断为空
   * @param arg1
   * @returns {boolean}
   */
  isEmpty<T>(arg1: T): boolean
    
  /**
     * 判断对象为无属性对象
     * @param e
     * @returns {boolean} 如果为空对象,返回true  如果为非空对象,返回false
     */
    isEmptyObject<T>(e: T): boolean
    
  /**
     * 计算年龄
     * @param birthday String '1988-10-06' |Date
     * @return String
     */
    getAge<T>(birthday: T): number
    
    
  /**
     * 回车键事件
     * @param e  事件
     * @param fn  回调函数
     * @param notEnterFn  非回车回调函数
     * @return boolean
     */
    keydownEnter(e: KeyboardEvent, fn?, notEnterFn?): void
    
  /**
     * 超出省略
     * @param s 字符串
     * @param len 最大长度
     * @returns {String}
     */
    beyondShowDot(s: string, len: number): string
    
  /**
     * 数字前补零(wjh)
     * @param num
     * @param length
     * @return {string}
     */
    addZero(num: number, length: number): string
    
  /**
     * 获取时间区间各个月份(wjh)
     * @param data type 日期数组
     * @return {Array}
     */
    getMonthArray<T>(data: Array<T>):  Array<string>
    
  /**
     * 删除请求参数的空值(lcq)
     * @param params
     * @param isJSON
     * @return {string | *}
     */
    noNoneGetParams<T>(params: T, isJSON = false): T | string
    
  /**
     * 将图片转成base64(lcq)
     * @param img(图片对象)
     * @returns {string}(base64)
     */
    picToBase64(img: HTMLImageElement): string
    
  /**
     * 将base64转成文件(lcq)
     * @param img,base64
     * @returns {File}
     */
    base64toFile<T>(img: string, name: string): File  
    
  /**
     * 二维数组穷尽组合游标算法函数
     * @param list  [ ['a1','a2'], ['b1','b2']]
     * @return {any[]}  [ [ 'a1', 'b1' ], [ 'a1', 'b2' ], [ 'a2', 'b1' ], [ 'a2', 'b2' ] ]
     * 1、计算出所有组合的长度length,初始化length长度的结果数组
     * 2、初始化游标数组,长度为list.length,每一项初始化为0,用于记录每一结果项的list来源项的下标
     * 3、开始循环结果数组(循环1),根据游标数组,获取要填入结果数组的list下标,从而获取list项,然后填入结果数组
     * 4、更新游标数组,更新为循环1下一次循环所要填入的下标
     * 5、直到循环1循环结束,算法结束
     */
    combination<T>(list: Array<Array<T>>): Array<Array<T>>
  
  /**
     * 树形筛选
     * @param tree
     * [
     {
              id: 1,
              children:[]
          }
     ]
     * @param filterCondition   要筛选出的id列表 [221, 121];
     * @returns {[]}
     */
    treeFilter<T>(tree:Array<T>, filterCondition:Array<string>): Array<T>
    
  /**
     * 将数字每千位逗号分隔
     * @param data string| number
     * @return string
     */
    toThousand(data:string | number):string