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

@zhiliteam/utils-core

v0.0.12

Published

##### 本项目是公司内部共用方法库,在开发时尽量全面思考可能遇到的场景。修改已上线代码时需注意兼容问题。

Readme

@zhilinteam/utils

本项目是公司内部共用方法库,在开发时尽量全面思考可能遇到的场景。修改已上线代码时需注意兼容问题。

开始

node版本: v15+

包管理器:请务必使用 pnpm ,不要用其他的。

pnpm i @zhilinteam/utils 

目录介绍

── auto-imports.d.ts
├── build.config.ts
├── index.ts
├── LICENSE
├── package.json
├── packages
│  ├── array // 数组方法相关的库
│  │  ├── arrToObj // 将数组转换为对象
│  │  │  ├── arrToObj.test.ts // 测试用例
│  │  │  ├── arrToObj.ts // 方法实现
│  │  │  └── README.md // 方法文档
│  │  ├── build.config.ts
│  │  ├── index.ts
│  │  ├── package.json
│  │  └── unique
│  │     ├── README.md
│  │     ├── unique.test.ts
│  │     └── unique.ts
│  ├── fn
│  │  ├── build.config.ts
│  │  ├── index.ts
│  │  └── package.json
│  └── object
│     ├── build.config.ts
│     ├── index.ts
│     └── package.json
├── plagrounds
├── pnpm-lock.yaml
├── pnpm-workspace.yaml
├── README.md
├── tsconfig.json
└── vitest.config.ts

注释介绍

1、第一行函数介绍,也可写上用途场景

2、@since 版本号:主版本号 . 次版本号 . 补丁版本号

​ 主版本号:重大变更,做了不兼容修改

​ 次版本号:小版本更新,向下兼容

​ 补丁版本号:bug 修复,向下兼容

3、 @param { 数据类型 } 参数

4、 @returns { 数据类型 } 返回值

5、 @example 使用示例

/**
 * 数组对象 转对象
 * 遇到频繁在数组中查找某条数据的场景,可用此方法将数组转化为对象,以某一个key的值作为键,方便取值并且提高代码性能。
 * @since 0.1.0
 *
 * @param {Array[Object]} arr 目标数组
 * @param {String} keyField 对象key取值
 * @param {String} valField value取值 不传默认取当前项
 * @returns {Object}
 * @example
 * arrayToObject([{id:1, name:'zs', age:16}], 'id', 'name') => { 1: 'zs' }
 * arrayToObject([{id:1, name:'zs', age:16}], 'id') => { 1: { id:1, name:'zs', age:16 } }
 */
export function arrayToObject<T>(
  arr: Array<{ [key: string]: T }>,
  keyField: string,
  valField?: string
): object {
  if (!keyField)
    return {}

  if (!arr.length)
    return {}

  return arr.reduce(
    (acc: { [key: string]: T }, cur: { [key: string]: any }) => {
      acc[cur[keyField]] = valField ? cur[valField] : cur
      return acc
    },
    {}
  )
}

测试

每个方法都要在对应文件内写单元测试,测试情况尽可能多的覆盖各个场景

测试使用文档:Vitest

pnpm run test          // 持续监听文件变化进行测试
pnpm run test:once     // 仅测试一次

pnpm run coverage      // 生成测试覆盖率报告