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

js-utils-plus

v1.4.1

Published

Javascript工具包

Readme

js-utils-plus

介绍

Javascript 工具包

安装

  npm i js-utils-plus --save

使用

CommonJS 方式引入

const utilsPlus = require('js-utils-plus');

ES Modules 方式引入

import * as utilsPlus from 'js-utils-plus';

使用说明

Array
  • treeToArray: 树转列表,(tree: any[], key = "children"): any[]
  • arrayToTree: 列表转树,(arr: any[], key: string, parentKey = "parentId"): any[]
  • arrayToObject: 列表转对象,(arr: any[], key: string, value: string): object
  • arrayDistinct: 数组去重,(arr: any[], iteratee?: Function | string): any[]
  • arrayGroupBy: 数组分组,(arr: any[], iteratee: Function | string): any[]
  • arraySameAbove: 数组默认同上,(arr: any[], props: string | string[]): any[]
  • arrayFlatten: 多维数组扁平化,(arr: any[], deep: number): any[]
  • arrayNested: 一维数组二维化,(arr: any[], size: number | Function): any[]
  • arrayDifference: 排除数组中指点的值,(arr: any[], values: string | string[]): any[]
  • getTreeChecked: 获取树形结构选中状态复选框,(tree: any[], keys = 'children'): any[]
  • updateTreeState: 树形结构复选框状态更新,(tree: any[], state: boolean, keys = 'children'): any[]
  • calculateTreeState: 树形结构复选框状态计算,(tree: any[], keys = 'children'): any[]
Object
  • objectPick: 创建对象中选中属性的新对象,(obj: object, props: string | string[]): T
  • objectOmit: 创建对象中忽略属性的新对象,(obj: object, props: string | string[]): T
  • objectFormatKey: 创建格式化对象键的新对象,(obj: object, format: RegExp | Function): T
  • objectFormatValue: 创建格式化对象值的新对象,(obj: object, format: RegExp | Function): T
  • objectFlatten: 创建对象扁平化后的新对象,(obj: object, connector = "."): object
  • objectNested: 创建对象嵌套化后的新对象,嵌套层使用”.“连接, (obj: object): object
  • objectToContent: 将对象转为字符串文本内容,(value: any, prefix = '', deep = 1): string

Function

  • promisify: 回调函数快速转换 promise 对象,(fn: Function, _this?: any): Function
  • delay: promise 等待函数(毫秒),(time: number): Promise
  • debounce: 防抖函数(固定延时后触发),(func: Function, wait = 1000): Function
  • throttle: 节流函数(固定时间内触发),(func: Function, wait = 1000, leading = true): Function
  • throttleWithArgsList: 节流函数合并参数(固定时间内触发),(func: Function, wait = 1000): Function
String
  • snakeToCamel: 蛇形转驼峰,(str: string): string
  • cameToSnake: 驼峰转蛇形,(str: string): string
  • uppercaseFirst: 首字母转大写,(str: string): string
  • lowercaseFirst: 首字母转小写,(str: string): string
  • padStart: 字符串左侧填充字符,(str: string, length: number, chars: string): string
  • padEnd: 字符串右侧填充字符,(str: string, length: number, chars: string): string
  • getByteLength: 字符串字节长度,(str: string): number
  • replaceRange: 替换字符串区间,(str: string, start: number, end: number, replacement: string): string
  • insertByLength: 固定长度插入字符,(str: string, len = 4, separator = ' '): string
  • maskPhoneNumber: 影藏部分手机号码,(str: string): string
  • formatAmount: 金额千分位逗号分隔,(value: string | number): string
  • getStringSuffix: 获取字符串后缀,(str: string, separator = '.'): string
Number
  • getUniqueRandom: 生成唯一随机数,(): string
  • toNumber: 转为数字,(num: any): number | undefined
  • toInt: 转为整数,(num: any): number | undefined
  • toFixed: 数字精度转换,(num: number | string, digit = 2): number
  • calcAdd: 精准计算(加法),(num1: number | string, num2: number | string): number
  • calcSubtract: 精准计算(减法),(num1: number | string, num2: number | string): number
  • calcMultiply: 精准计算(乘法),(num1: number | string, num2: number | string): number
  • calcDivide: 精准计算(除法),(num1: number | string, num2: number | string): number
  • meterToFt: 米(m)转英尺(ft),(num: number, digit = 2): number
  • ftToMeter: 英尺(ft)转米(m),(num: number, digit = 2): number
  • meter2ToFt2: 平方米(m²)转平方英尺(ft²),(num: number, digit = 2): number
  • ft2ToMeter2: 平方英尺(ft²)转平方米(m²),(num: number, digit = 2): number
  • celsiusToFahrenheit: 摄氏度(°C)转华氏度(°F),(num: number, digit = 0): number
  • fahrenheitToCelsius: 华氏度(°F)转摄氏度(°C),(num: number, digit = 0): number
Validate
  • isEmpty: 是否为空,(undefined/null/''/NaN),(arg: any): boolean
  • isNotEmpty: 是否不为空,非(undefined/null/''/NaN),(arg: any): boolean
  • isObject: 是否为对象,(arg: any): boolean
  • isArray: 是否为数组,(arg: any): boolean
  • isRegExp: 是否为正则,(regex: any): boolean
  • isFunction: 是否为函数,(arg: any): boolean
  • isBoolean: 是否为布尔值,(arg: any): boolean
  • isNumber: 是否为数字,(arg: any): boolean
  • isInt: 是否为整数,(arg: any): boolean
  • isString: 是否为字符串,(arg: any): boolean
  • isNumberString: 是否为数字字符串,(arg: any): boolean
  • isNullOrUndefined: 是否为 null 或 undefined,(arg: any): boolean
  • isUndefined: 是否为 undefined,(arg: any): boolean
  • isNull: 是否为 null,(arg: any): boolean
  • isDate: 是否为日期(YYYY-MM-DD),(arg: any): boolean
  • isDateTime: 是否为日期时间(YYYY-MM-DD HH:mm:ss),(arg: any): boolean
  • isJsonString: 是否为 json 字符串,(arg: string): boolean
  • isChinese: 是否包含中文,(arg: any): boolean
  • isMobile: 是否为手机号,(arg: string): boolean
  • isEmail: 是否为邮箱地址,(arg: any): boolean
  • isBank: 是否为银行卡号,(arg: any): boolean
  • isVersion: 是否为版本号(X.Y.Z),(arg: any): boolean
  • isAccount: 是否为账号(字母/数字/下划线/-),(arg: any, min = 5, max = 16): boolean
  • isPwd: 是否为密码(字母/数字/特殊符,任意 2 种),(arg: any, min = 8, max = 16): boolean
  • isEqual 是否相等(支持对象和数组类型),(a: any, b: any): boolean
Window
  • getQueryParams 获取 url 参数,(url: string): Record<string, unknown>
  • copyToClipboard 复制到粘贴板,(text: string): boolean
  • loadScript: 异步加载 script 脚本,(url: string, id: string, noCache?: boolean): Promise
  • getImageSize: 获取图片原始宽高,(src: string): Promise
  • getFileDataURL: 生成文件 DataURL(图片预览),(file: File): Promise
  • isFontInstalled: 判断系统是否包含某字体,(fontFamily: string): boolean
  • getStorage: 获取浏览器储存值(localStorage),(key: string, initValue?: any): T
  • setStorage: 设置浏览器储存值(localStorage),(key: string, value: T): void
  • getSession: 获取浏览器储存值(sessionStorage),(key: string, initValue?: any): T
  • setSession: 设置浏览器储存值(sessionStorage),(key: string, value: T): void
Node
  • isExist 检测文件(夹)是否存在,(filePath: string): boolean
  • isFile 检测是否是一个文件路径,(filePath: string): boolean
  • isDirectory 检测是否是一个文件夹路径,(filePath: string): boolean
  • chmod 修改文件(夹)权限,(filePath: string, mode = 0o755): boolean
  • mkdir 创建文件夹,(filePath: string): boolean
  • readFileSync 读取文件内容,(fullPath: string, toJson: boolean): string | object
  • writeFileSync 写入文件内容,(filePath: string, content: string): boolean
  • listFilesRecursively 递归列出文件,(dir: string, ext: string, excludes: string[]): string[]
  • deleteFilesRecursively 递归删除文件,(dir: string, ext: string, excludes: string[]): void