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

jinbi-utils

v1.0.19

Published

这是一个实用工具库,包含了多个常用的功能模块。以下是各个模块的详细说明:

Readme

jbwy-utils 使用说明

这是一个实用工具库,包含了多个常用的功能模块。以下是各个模块的详细说明:

1. Common 模块 (common/index.ts)

通用函数集合,提供了一些基础工具方法:

1.1 判空相关

import { isEmpty } from 'jbwy-utils/common'

isEmpty('') // 返回 true
isEmpty(null) // 返回 true
isEmpty(undefined) // 返回 true
isEmpty(12323) // 返回 false

1.2 环境判断

import { getDeviceType, getEnvironment, getIsComWx } from 'jbwy-utils/common'

// 获取设备类型
const deviceInfo = getDeviceType()
// 返回: { isWxWork, isWeixin, isMobileScreen, isMobileAny }

// 获取运行环境
const env = getEnvironment()
// 返回: 'com-wx-mobile' | 'com-wx-pc' | 'wx-mobile' | 'wx-pc' | 'other'

// 判断是否企业微信环境
const isComWx = getIsComWx()

1.3 URL参数处理

import { getQueryString, getQueryVariable } from 'jbwy-utils/common'

// 获取URL参数
getQueryString(url, 'key')
getQueryVariable('key')

2. Number 模块 (number/index.ts)

数字处理相关函数:

import { toThousands, formatFloat, ceil, floor } from 'jbwy-utils/number'

// 千分位格式化
toThousands(12345) // 返回 '12,345'
toThousands('12323.12') // 返回 '12,323.12'

// 格式化小数位
formatFloat('1.2345') // 返回 '1.23'
formatFloat('1.2345', 3) // 返回 '1.235'

// 向上取整
ceil('1.234', 2) // 返回 1.24

// 向下取整
floor('1.234', 2) // 返回 1.23

3. String 模块 (string/index.ts)

字符串处理相关函数:

import { formatPhone, formatPhoneHide, formatBank } from 'jbwy-utils/string'

// 格式化手机号
formatPhone('18211572781') // 返回 '182 1157 2781'
formatPhone('18211572781', '-') // 返回 '182-1157-2781'

// 隐藏手机号中间四位
formatPhoneHide('18211572781') // 返回 '182****2781'

// 格式化银行卡号
formatBank('6282356862823568123') // 返回 '6282 3568 6282 3568 123'

4. Validate 模块 (validate/index.ts)

提供各种验证函数:

import { isMobile, isEmail, isTelephone, isQQ } from 'jbwy-utils/validate'

// 验证手机号
isMobile('13800138000') // 返回 true/false

// 验证邮箱
isEmail('[email protected]') // 返回 true/false

// 验证固定电话
isTelephone('0755-88888888') // 返回 true/false

// 验证QQ号
isQQ('10000') // 返回 true/false

5. File 模块 (file/index.ts)

文件处理相关函数:

import { calcFileSize, fileSizeFormat, compressImg } from 'jbwy-utils/file'

// 计算文件大小
calcFileSize(1024) // 返回 { size: 1, unit: 'KB' }

// 格式化文件大小
fileSizeFormat('1024', 'KB') // 返回 '1MB'

// 压缩图片
compressImg(file, scaleCallback, qualityCallback)

6. Object 模块 (object/index.ts)

对象处理相关函数:

import { deepEqual, findNodePath } from 'jbwy-utils/object'

// 深度比较两个对象是否相等
deepEqual({a: 10}, {a: 10}) // 返回 true
deepEqual({a: 10}, {a: 10, b: 20}) // 返回 false

// 查找树结构节点路径
findNodePath(nodeValue, nodeKey, treeArray, childrenKey)

7. WeChat Work 模块 (wecom/wecom.ts)

企业微信相关功能:

import { initWWConfig } from 'jbwy-utils/wecom'

// 初始化企业微信配置
initWWConfig()

8. middleware 模块 (middleware)

中间件相关功能:

8.1 requestLogger.middware.ts

日志服务 此插件支持使用了koa的nodejs项目 注意:(recordLogMiddleWare('project-plan-service'))需要传入项目名,日志文件会根据传入的项目名来 命名前缀

// midway 项目接入方案 configuration.ts
import { recordLogMiddleWare } from 'jinbi-utils'

export class MainConfiguration {
  @App('koa')
  app: koa.Application;

  async onReady() {
    // 
    this.app.useMiddleware([recordLogMiddleWare('project-plan-service')]);

  }
}
//  只用了koa的nodejs项目接入方案 app.js
import { recordLogMiddleWare } from 'jinbi-utils'

const app = new Koa();
app.use(bodyParser());
app.use(router.routes()).use(router.allowedMethods()).use(recordLogMiddleWare('project-plan-service'));

安装和使用

  1. 安装依赖:
npm install jbwy-utils
  1. 引入使用:
import { isEmpty } from 'jbwy-utils/common'
import { formatPhone } from 'jbwy-utils/string'
// ... 按需引入其他功能

注意:所有模块都支持按需引入,可以只引入需要使用的功能,减少打包体积。