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

pinyin-slug

v1.0.1

Published

A URL slug generator that converts Chinese to pinyin slugs.

Readme

pinyin-slug

一个轻量且灵活的 URL slug 生成工具,可将中文文本转换为拼音 slug。由 pinyin-pro 提供底层支持。

特性

  • 🚀 高效: 在 pinyin-pro 基础上仅进行最轻量的处理。
  • 🛠 可配置: 完全控制拼音转换和 Slug 格式化逻辑。
  • 🔠 混合内容: 优雅处理中英文/非中文混合文本。
  • 🛡 TypeScript: 完整的类型定义,提供极佳的开发体验。
  • 📦 精简依赖: 除了 pinyin-pro,不依赖任何第三方 slug 库。

安装

npm install pinyin-slug
# 或
yarn add pinyin-slug
# 或
pnpm add pinyin-slug

快速上手

基本用法

import { pinyinSlug } from 'pinyin-slug';

console.log(pinyinSlug('你好世界')); 
// 输出: ni-hao-shi-jie

console.log(pinyinSlug('Hello 你好')); 
// 输出: hello-ni-hao

自定义配置

你可以分别配置拼音转换选项和 slug 格式化选项:

import { pinyinSlug } from 'pinyin-slug';

const slug = pinyinSlug('你好,世界!', {
  pinyin: {
    toneType: 'num', // 拼音带声调数字
  },
  slug: {
    replacement: '_', // 使用下划线作为分隔符
    lower: false,     // 不强制转小写
  }
});

console.log(slug); 
// 输出: ni3_hao3_shi4_jie4

API

pinyinSlug(text, options?)

参数

  • text (string): 输入的包含中文的字符串。
  • options (object): 可选配置。
    • pinyin (object): 直接传递给 pinyin-pro 的配置项。参考 pinyin-pro 文档
    • slug (object): Slug 格式化配置。
      • replacement (string): 用于替换空格的分隔符。默认: '-'
      • remove (RegExp): 用于移除非法字符的正则表达式。默认: /[^\w\s-]/g
      • lower (boolean): 是否转换为小写。默认: true
      • trim (boolean): 是否去除首尾空格。默认: true

开源协议

MIT