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

str-arr-utils-ygt

v1.0.1

Published

字符串和数组处理工具函数

Readme


# str-arr-utils-ygt

一个轻量实用的字符串与数组处理工具库,提供常用的去重、分组、驼峰转换、字符串反转等功能,适用于日常 JavaScript / TypeScript 项目开发。

---

## 📦 安装

```bash
npm install str-arr-utils-ygt
```

或使用 pnpm:

pnpm add str-arr-utils-ygt

🚀 快速使用

import {
  removeDuplicates,
  arrayToString,
  chunkArray,
  capitalizeAt,
  reverseString,
  toCamelCase,
} from "str-arr-utils-ygt";

removeDuplicates([1, 2, 2, 3]); // [1, 2, 3]
arrayToString([1, true, "hi"]); // ['1', 'true', 'hi']
chunkArray([1, 2, 3, 4, 5], 2); // [[1, 2], [3, 4], [5]]
capitalizeAt("hello", 1); // 'hEllo'
reverseString("hello"); // 'olleh'
toCamelCase("hello world example"); // 'helloWorldExample'

📚 API 文档

🧩 数组工具

removeDuplicates(arr: any[]): any[]

去除数组中的重复元素。

  • 参数: arr 任意类型数组
  • 返回: 去重后的新数组
  • 示例:
removeDuplicates([1, 2, 2, 3]); // [1, 2, 3]

arrayToString(arr: any[]): string[]

将数组中所有元素转换为字符串。

  • 参数: arr 任意类型数组,不能包含 null 或 undefined
  • 返回: 字符串数组
  • 示例:
arrayToString([1, true, "hi"]); // ['1', 'true', 'hi']

chunkArray(arr: any[], size: number): any[][]

将数组按指定大小拆分为子数组。

  • 参数:

    • arr: 任意数组
    • size: 拆分的子数组大小(必须大于 0)
  • 返回: 二维数组

  • 示例:

chunkArray([1, 2, 3, 4], 2); // [[1, 2], [3, 4]]

🔠 字符串工具

capitalizeAt(str: string, index: number): string

将字符串中指定索引的字符转换为大写。该字符必须是小写字母。

  • 参数:

    • str: 输入字符串
    • index: 要转换的大写字符的位置
  • 返回: 处理后的字符串

  • 示例:

capitalizeAt("hello", 1); // 'hEllo'

reverseString(str: string): string

将字符串反转。

  • 参数: str 输入字符串
  • 返回: 反转后的字符串
  • 示例:
reverseString("hello"); // 'olleh'

toCamelCase(str: string): string

将以空格分隔的字符串转换为 camelCase 格式。

  • 参数: str 输入字符串
  • 返回: camelCase 格式的字符串
  • 示例:
toCamelCase("hello world example"); // 'helloWorldExample'

formatDate(date: Date | string | number, format = "YYYY-MM-DD HH:mm:ss"): string

将输入的日期格式化

  • 参数: date 输入的日期 format 格式化格式
  • 返回: 格式化后的字符串日期
  • 示例:
formatDate("2025-11-09","YYYY-MM"); // 'helloWorldExample'

✅ TypeScript 支持

本工具包由 TypeScript 编写,提供完整类型提示,适用于 TS 项目和 JS 项目。


🧪 单元测试(Vitest)

该项目使用 Vitest 编写测试。

运行测试

npm run test

测试覆盖所有函数的核心逻辑和异常情况。


📁 项目结构

str-arr-utils-ygt/
├── src/
│   ├── arrayUtils.ts        # 数组工具函数
│   └── stringUtils.ts       # 字符串工具函数
├── tests/
│   ├── arrayUtils.test.ts   # 数组函数测试
│   └── stringUtils.test.ts  # 字符串函数测试
├── dist/                    # 构建产物
├── package.json
├── tsconfig.json
└── README.md