@xiping/pinyin-search
v1.0.84
Published
pinyin-search
Readme
@xiping/pinyin-search
A utility package for Chinese Pinyin search functionality, supporting flexible matching and TypeScript integration.
Installation
You can install this package using your preferred package manager:
npm
npm install @xiping/pinyin-searchyarn
yarn add @xiping/pinyin-searchpnpm
pnpm add @xiping/pinyin-searchUsage
import { pinyinSearch, pinyinMatch } from '@xiping/pinyin-search';
// Search in array of objects
const list = [
{ name: '张三' },
{ name: '李四' },
{ name: '王五' }
];
const result = pinyinSearch(list, 'name', 'zhang');
console.log(result); // [{ name: '张三' }]
// Direct pinyin matching
const isMatch = pinyinMatch('你好', 'nihao');
console.log(isMatch); // trueFeatures
- Array search support: Search through arrays of objects using Pinyin
- Direct matching: Check if a Chinese string matches a Pinyin search text
- TypeScript ready: Full TypeScript type definitions included
- Simple API: Just two main functions for different search needs
API Reference
pinyinSearch(list: object[], key: string, text: string)
Search through an array of objects using a specific key and Pinyin text.
pinyinMatch(text: string, searchText: string)
Direct matching between Chinese text and Pinyin search text.
License
MIT
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
