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

js-utils-lib

v0.0.8

Published

This is a Js Functions Library

Downloads

9

Readme

js-utils

This is a Js Functions Library

Install(npm)

npm install js-utils-lib

How to use

delay

delay(callFunc: Function, condition?: Function, interval?: number, timeout?: number): void

每隔一段时间判断条件是否满足,条件满足时执行函数

API

参数 | 说明 | 类型 | 默认值 ---|---|---|--- callFunc | 条件满足时执行的函数 | Function | 0 condition | 获取条件是否满足 | Function | 默认为满足 interval | 时间间隔,单位 毫秒 | Number | 100 timeout | 超时时间,单位 毫秒 | Number | 100000

Demo

import { delay } from 'js-utils-lib'
let bool = false
let f = () => console.log('do somethings')
let c = () => (console.log(bool), bool)
setTimeout(() => bool = true, 2000)
delay(f, c)

getAllParentsByKey

function getAllParentsByKey(value: any, treeData?: any[], key: string, data?: any[], bFind?: boolean): any[] | {bFind: boolean, data: any[]}

根据指定key找出所有父节点

API

参数 | 说明 | 类型 | 默认值 ---|---|---|--- value | 要查找的值 | Number | - key | 要指定的key | Function | 'id' treeData | 树数据 | Array | [] data | 父节点数据 | Array | [] bFind | 是否已找到 | Boolean | false

Demo

import { getAllParentsByKey } from 'js-utils-lib'
let treeData = [
  {
    id: '1',
    children: [
      {
        id: '1-1',
        children: [
          {
            id: '1-1-1',
          }
        ]
      }
    ]
  },
  {
    id: '2',
    children: [
      {
        id: '2-1'
      },
      {
        id: '2-2',
        children: [
          {
            id: '2-2-1',
          }
        ]
      }
    ]
  }
];
getAllParentsByKey('1-1-1', treeData)

arrayConcat

arrayConcat(...arr: any[]): any[]

连接数组(多参数)

Demo

  import { arrayConcat } from 'js-utils-lib'
  let arr = arrayConcat(1,2,[3,4])

treeToArray

treeToArray(treeData: any[], isDeep: boolean): any[]

树结构转数组

API

参数 | 说明 | 类型 | 默认值 ---|---|---|--- treeData | 树结构数组 | Date | [] isDeep | 是否深拷贝 | Boolean | false

formatDate

formatDate(date?: Date, fmt?: string): string

格式化时间 将 Date 转化为指定格式的String

API

参数 | 说明 | 类型 | 默认值 ---|---|---|--- date | 要转换的数据 | Date | new Date() fmt | 指定格式 | String | 默认为'yyyy-MM-dd hh:mm:ss.S'

Demo

  import { formatDate } from 'js-utils-lib'
  console.log(formatDate(new Date(), 'yyyy-MM-dd hh:mm:ss.S'))

formatStringEllipsis

formatStringEllipsis(data: string, head: number, tail: number, maxLength: number): string

将较长的字符串 中间部分用...代替

API

参数 | 说明 | 类型 | 默认值 ---|---|---|--- data | 要格式化的字符串 | String | - head | 头部长度 | Number | 3 tail | 尾部长度 | Number | 3 maxLength | 超过 maxLength 时才格式化,不传则不筛选 | Number | -

Demo

  import { formatStringEllipsis } from 'js-utils-lib'
  console.log(formatStringEllipsis('12345678901234567890'))