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

@okcy/utils

v2020.1226.3

Published

<details open>

Readme

ArrayUtils.ts

  • init
  /**
   * 按长度初始化一个数组
   * @param length 长度
   */
   static init(length: number): number[]
  • remove
  /**
   * 删除元素
   * @param arr
   * @param val
   */
  static remove<T>(arr: T[], val: any): T[]
  • removeIndex
  /**
   * 删除下标
   * @param arr
   * @param index
   */
  static removeIndex<T>(arr: T[], index: number): T[]
  • addIndex
  /**
   * 指定位置插入元素
   * @param arr
   * @param index
   * @param items
   */
   static addIndex<T>(arr: T[], index: number, ...items: T[]): T[]
  • unique
  /**
   * 数组去重
   * @param arr
   */
  static unique<T>(arr: T[]): T[]
  • diff
  /**
   * 去重合并数组
   * @param arr1
   * @param arr2
   */
  static diff<T>(...list): T[]
  • clone
  /**
   * 克隆数组
   * @param arr null时返回[]
   */
  static clone<T>(arr: T[]): T[]
  • removeEmpty
  /**
   *  去除null/""/undefined 元素
   * @param arr null时返回[]
   */
  static removeEmpty<T>(arr: T[]): T[]
  • isNull
  /**
   * 是否为Null
   * @param arr
   */
  static isNull(arr: any): boolean
  • isNotNull
  /**
   * 是否不为空
   * @param arr
   */
  static isNotNull(arr: any): boolean
  • isArray
  /**
   * 验证是否数组
   * @param arr
   */
  static isArray(arr: any): boolean

JsonUtils.ts

  • recursion
/**
* 递归(一级克隆)
* @param list  原始数据
* @param pid   上级ID
* @param names.id  主键(id)
* @param names.pid  上级名称(pid)
* @param names.children  存放下级的名称
* @param childrenDefault  默认空类容
*/
static  recursion<T>(list, pid, names?: { id?: string; pid?: string; children?: string }, childrenDefault: any = []): T[]
  • depthClone
/**

* 深度克隆 (不可克隆复杂对象)
* @param json
*/
static depthClone<T>(json: T): T
  • isNull
/**

* 是否为Null
* @param obj
*/
static isNull(obj: any): boolean
  • isNotNull
/**

* 是否不为空
* @param obj
*/
static isNotNull(obj: any): boolean
  • isObject
/**

* 是否对象
* @param obj
*/
static isObject(obj: any): boolean

QueryUtils.ts

  • data
  /**
   * 初始路由数据
   * @param query 路由参数
   * @param data 需要合并的数据,可无限添加
   */
  static data<T>(query: T, ...data): any

StringUtils.ts

  • format
  /**
   *替换占位符内容
   * 用{two}自符串替换占位符{two} {three}  {one}-> {one: "A",two: "B",three: "C"}
   * 用{2}自符串替换占位符{2} {3}  {1} ->"A","B","C"
   * @param str
   * @param params
   */
  static format(str: string, ...params): string
  • hide
  /**
   * 隐藏字符串
   * @param str
   * @param startLength 开始长度
   * @param endLength 结束长度
   */
  static hide(str: string, startLength: number, endLength: number, val: string = '*'): string
  • isEmpty
  /**
   * 是否空字符串
   * @param value
   */
  static isEmpty(value: string): boolean
  • isNotEmpty
  /**
   * 是否非空
   * @param value
   */
  static isNotEmpty(value: string): boolean
  • isBlank
  /**
   * 空和空格
   * @param value
   */
  static isBlank(value: string): boolean
  • isNotBlank
  /**
   * 不可空和空格
   * @param value
   */
  static isNotBlank(value: string): boolean
  • startsWith
  /**
   * 验证字符串开始
   * @param value
   * @param prefix
   */
  static startsWith(value: string, prefix: string): boolean
  • endsWith
  /**
   * 字符串结束
   * @param value
   * @param suffix
   */
  static endsWith(value: string, suffix: string): boolean
  • contains
  /**
   * 是否包含
   * @param value
   * @param searchSeq
   */
  static contains(value: string, searchSeq): boolean
  • isString
  /**
   * 是否字符串
   * @param obj
   */
  static isString(obj: any): boolean
  • equals
  /**
   * 是否相等
   * @param value
   * @param val
   */
  static equals(value: string, val: string): boolean
  • equalsIgnoreCase
  /**
   * 排除大小写是否相等
   * @param value
   * @param val
   */
  static equalsIgnoreCase(value: string, val: string): boolean
  • repeat
  /**
   * 生成指定长度的字符串
   * @param value
   * @param length
   */
  static repeat(value: string, length: number): string
  • isAlpha
  /**
   * 只包含字母
   * @param value
   */
  static isAlpha(value: string): boolean
  • isAlphaSpace
  /**
   * 只包含字母、空格
   * @param value
   */
  static isAlphaSpace(value: string): boolean
  • isAlphanumeric
  /**
   * 只包含字母、数字
   * @param value
   */
  static isAlphanumeric(value: string): boolean
  • isAlphanumericSpace
  /**
   * 只包含字母、数字和空格
   * @param value
   */
  static isAlphanumericSpace(value: string): boolean
  • isNumeric
  /**
   * 数字
   * @param value
   */
  static isNumeric(value: string): boolean
  • isDecimal
  /**
   * 小数
   * @param value
   */
  static isDecimal(value: string): boolean
  • isNegativeDecimal
  /**
   * 负小数
   * @param value
   */
  static isNegativeDecimal(value: string): boolean
  • isPositiveDecimal
  /**
   * 正小数
   * @param value
   */
  static isPositiveDecimal(value: string): boolean
  • isInteger
  /**
   * 整数
   * @param value
   */
  static isInteger(value: string): boolean
  • isPositiveInteger
  /**
   * 正整数
   * @param value
   */
  static isPositiveInteger(value: string): boolean
  • isNegativeInteger
  /**
   * 负整数
   * @param value
   */
  static isNegativeInteger(value: string): boolean
  • isNumericSpace
  /**
   * 只包含数字和空格
   * @param value
   */
  static isNumericSpace(value: string): boolean
  • isAllLowerCase
  /**
   * 只能小写
   * @param value
   */
  static isAllLowerCase(value: string): boolean
  • isAllUpperCase
  /**
   * 只能大写
   * @param value
   */
  static isAllUpperCase(value: string): boolean
  • isSpecialCharacterAlphanumeric
  /**
   * 只包含特殊字符、数字和字母(不包括空格,若想包括空格,改为[ -~])
   * @param value
   */
  static isSpecialCharacterAlphanumeric(value: string): boolean
  • isChinese
  /**
   * 必须是中文
   * @param value
   */
  static isChinese(value: string): boolean
  • removeChinese
  /**
   * 删除中文字符
   * @param value
   */
  static removeChinese(value: string): string
  • escapeMetacharacter
  /**
   * 转义元字符
   * @param value
   */
  static escapeMetacharacter(value: string): string
  • escapeMetacharacterOfStr
  /**
   * 转义字符串中的元字符
   * @param value
   */
  static escapeMetacharacterOfStr(value: string): string

Utils.ts

  • uniqueString
  /**
   * 生成随机字符串
   */
  static uniqueString(): string
  • uniqueNumber
  /**
   * 生成随机数
   */
  static uniqueNumber(): string

ValidUtils

验证成功返回 null ,失败返回 string

  • userName
  /**
   * 登录名
   * @param value
   */
  static userName(value: string): string | null
  • name
  /**
   * 姓名
   * @param value
   */
  // @ts-ignore
  static name(value: string): string  | null
  • password
  /**
   * 密码验证
   * @param value
   */
  static password(value: string): string | null
  • phone
  /**
   * 手机号
   * @param value
   */
  static phone(value: string): string | null
  • email
  /**
   * 邮箱
   * @param value
   */
  static email(value: string): string  | null
  • equals
  /**
   * 是否相等
   * @param value
   * @param value1
   */
  static equals(value: string, value1: string): string  | null
  • notBlank
  /**
   * 不为空
   * @param value
   */
  static notBlank(value: any): string | null
  • length
  /**
   * 长度
   * @param value
   * @param length 长度
   */
  static length(value: string, length: number): string | null
  • maxLength
  /**
   * 最大长度
   * @param value
   * @param length 最大长度
   */
  static maxLength(value: string, length: number): string | null
  • minLength
  /**
   * 最小长度
   * @param value
   * @param length 最小长度
   */
  static minLength(value: string, length: number): string | null
  • numberSize
  /**
   * 数字最大最小值
   * @param value
   * @param min 最小
   * @param max 最大
   */
  static numberSize(value: any, min: number, max: number): string | null