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 🙏

© 2024 – Pkg Stats / Ryan Hefner

pinin

v0.2.0

Published

TypeScript port of the Java library PinIn for Chinese text match using Pinyin - 用于各类汉语拼音匹配问题的库

Downloads

11

Readme

pinin-js

NPM version

这是一个 TypeScript 版的 PinIn 库,用于解决各类汉语拼音匹配问题。
对即时匹配提供基于 NFA 的实现,对索引匹配提供类后缀树的实现。除此之外,它还可以将汉字转换为拼音字符串,包括 ASCII,Unicode 和注音符号。
关于此库的更多介绍和实现细节,请点击上方的源库链接到源库查看。

此库的默认词典大小相对较大(≈597KB, gzip≈130KB, brotli≈109KB),依据使用情况可能需要自行对词典做相应调整。

示例

这里展示一下此项目的一些基础接口的使用方式,更多示例可以在 test 目录中找到。

import PinIn, { formatPinyinPhonetic, formatPinyinUnicode, SearchLogicContain, TreeSearcher, defaultDict } from 'pinin'

// context
const p = new PinIn({ dict: defaultDict })

// direct match
console.assert(p.contains('测试文本', 'ceshi'))

// indexed match
const searcher = new TreeSearcher<number>(SearchLogicContain, p)
p.put('测试文本', 0)
console.assert(searcher.search('ceshi').includes(0))

// fuzzy spelling (| for bidirectional, > for one-way)
const p2 = new PinIn({ dict: defaultDict, fuzzy: ['sh|s', 'en>e'] })
console.assert(p.contains('测试文本', 'cesiwe'))

// pinyin format
const c = p.genChar('圆'.charCodeAt(0))
const y = c.pinyins[0]
console.assert(formatPinyinUnicode(y) === 'yuán')
console.assert(formatPinyinPhonetic(y) === 'ㄩㄢˊ')

致谢

感谢 PinIn 项目的原作者 Towdium,本项目基本只是迁移工作。

内置的拼音数据来自于 地球拼音pinyin-data