pinyin-pro
Advanced tools
Comparing version 3.0.7 to 3.1.0-alpha.0
@@ -0,1 +1,6 @@ | ||
## 3.1.0 | ||
- 增加获取拼音首字母功能 | ||
- 修复 readme 中音调形式参数 toneType 错写成了 tone 的错误 | ||
## 3.0.7 | ||
@@ -2,0 +7,0 @@ |
@@ -0,0 +0,0 @@ export const DICT3: { [prop: string]: string } = { |
@@ -0,0 +0,0 @@ export const DICT5: { [prop: string]: string } = { |
@@ -0,0 +0,0 @@ export const INITIAL_LIST = [ |
@@ -129,2 +129,12 @@ import { DICT1 } from '../data/dict1'; | ||
type GetFirstLetter = (pinyin: string) => string; | ||
const getFirstLetter: GetFirstLetter = (pinyin) => { | ||
const first_letter_arr: string[] = []; | ||
const pinyin_arr = pinyin.split(' '); | ||
pinyin_arr.forEach((pinyin) => { | ||
first_letter_arr.push(pinyin[0]); | ||
}); | ||
return first_letter_arr.join(' '); | ||
}; | ||
export { | ||
@@ -137,2 +147,3 @@ getPinyin, | ||
getPinyinWithNum, | ||
getFirstLetter, | ||
}; |
export { pinyinFn as pinyin } from './pinyin'; |
@@ -8,2 +8,3 @@ import { | ||
getPinyinWithNum, | ||
getFirstLetter, | ||
} from './handle'; | ||
@@ -13,3 +14,3 @@ | ||
toneType?: 'symbol' | 'num' | 'none'; | ||
pattern?: 'pinyin' | 'initial' | 'final' | 'num'; | ||
pattern?: 'pinyin' | 'initial' | 'final' | 'num' | 'first'; | ||
type?: 'string' | 'array'; | ||
@@ -28,3 +29,3 @@ multiple?: boolean; | ||
toneType?: 'symbol' | 'num' | 'none'; | ||
pattern?: 'pinyin' | 'initial' | 'final' | 'num'; | ||
pattern?: 'pinyin' | 'initial' | 'final' | 'num' | 'first'; | ||
type?: 'string' | 'array'; | ||
@@ -63,2 +64,5 @@ multiple?: boolean; | ||
break; | ||
case 'first': | ||
pinyin = getFirstLetter(pinyin); | ||
break; | ||
default: | ||
@@ -65,0 +69,0 @@ break; |
{ | ||
"name": "pinyin-pro", | ||
"version": "3.0.7", | ||
"version": "3.1.0-alpha.0", | ||
"description": "汉字转拼音库。获取汉字、词语、句子等内容的拼音、韵母、声母、声调等信息。", | ||
@@ -14,2 +14,3 @@ "main": "./dist/index.js", | ||
"cover": "istanbul cover --report lcov node_modules/mocha/bin/_mocha -- -R spec test/*.js", | ||
"cover:local": "istanbul cover --report=html node_modules/mocha/bin/_mocha -- -R spec test/*.js", | ||
"lint": "eslint ." | ||
@@ -16,0 +17,0 @@ }, |
114
README.md
@@ -1,12 +0,12 @@ | ||
[![pinyin-pro Logo](https://i.ibb.co/26fJ5vF/pinyin-logo.png)](https://github.com/zh-lx/pinyin-pro) | ||
[![pinyin-pro Logo](https://p3-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/340e213b487e416d932a889a480a7674~tplv-k3u1fbpfcp-zoom-1.image)](https://github.com/zh-lx/pinyin-pro) | ||
pinyin-pro —— 专业的汉字拼音转换工具 | ||
[![NPM version](https://img.shields.io/npm/v/pinyin-pro.svg)](https://www.npmjs.com/package/pinyin-pro) | ||
[![GITHUB star](https://img.shields.io/github/stars/zh-lx/pinyin-pro.svg)](https://github.com/zh-lx/pinyin-pro) | ||
[![travis-build](https://travis-ci.com/zh-lx/pinyin-pro.svg?branch=main)](https://travis-ci.com/github/zh-lx/pinyin-pro) | ||
[![NPM Downloads](https://img.shields.io/npm/dm/pinyin-pro.svg)](https://npmcharts.com/compare/pinyin-pro?minimal=true) | ||
[![Coverage Status](https://coveralls.io/repos/github/zh-lx/pinyin-pro/badge.svg?branch=main)](https://coveralls.io/github/zh-lx/pinyin-pro?branch=main) | ||
[![MIT-license](https://img.shields.io/npm/l/pinyin-pro.svg)](https://opensource.org/licenses/MIT) | ||
[![GITHUB-language](https://img.shields.io/github/languages/top/zh-lx/pinyin-pro.svg)](https://github.com/zh-lx/pinyin-pro) | ||
[![NPM version](https://p3-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/51194c6889fa4586b6ea66034a465059~tplv-k3u1fbpfcp-zoom-1.image)](https://www.npmjs.com/package/pinyin-pro) | ||
[![GITHUB star](https://p3-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/37eed68e3e98486880533efe2f3bb878~tplv-k3u1fbpfcp-zoom-1.image)](https://github.com/zh-lx/pinyin-pro) | ||
[![travis-build](https://p3-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/d09fea63f5b84ae1b4d94a97e0f7bc82~tplv-k3u1fbpfcp-zoom-1.image)](https://travis-ci.com/github/zh-lx/pinyin-pro) | ||
[![NPM Downloads](https://p3-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/e08cc9f729324cc68c4ce1757c20c91c~tplv-k3u1fbpfcp-zoom-1.image)](https://npmcharts.com/compare/pinyin-pro?minimal=true) | ||
[![Coverage Status](https://p3-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/068c150e8b414eb397160044253057db~tplv-k3u1fbpfcp-zoom-1.image)](https://coveralls.io/github/zh-lx/pinyin-pro?branch=main) | ||
[![MIT-license](https://p3-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/dd06bb6172b44510bed7c9b1ea67f46a~tplv-k3u1fbpfcp-zoom-1.image)](https://opensource.org/licenses/MIT) | ||
[![GITHUB-language](https://p3-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/47d5352c2bc944309cd4ec9c651138c2~tplv-k3u1fbpfcp-zoom-1.image)](https://github.com/zh-lx/pinyin-pro) | ||
@@ -24,5 +24,6 @@ ## 特色功能 | ||
当前版本: 3.0.6 -> 3.0.7 | ||
当前版本: 3.0.7 -> 3.1.0 | ||
- package.json 中去掉 readme 选项 | ||
- 增加获取拼音首字母功能 | ||
- 修复 readme 中音调形式参数 toneType 错写成了 tone 的错误 | ||
@@ -47,3 +48,3 @@ 点击查看 [版本更新文档](./CHANGELOG.md) | ||
浏览器端: | ||
ES6 引入: | ||
@@ -54,3 +55,3 @@ ```javascript | ||
node 端: | ||
commonjs 引入: | ||
@@ -68,16 +69,14 @@ ```javascript | ||
| 参数 | 说明 | 类型 | 可选值 | 默认值 | | ||
| -------- | ------------------------------------------------------------- | ------- | ------------------------------ | ------ | | ||
| pattern | 输出的结果的信息(拼音 / 声母 / 韵母 / 音调) | string | pinyin / initial / final / num | pinyin | | ||
| tone | 音调输出形式(拼音符号 / 数字 / 不加音调) | string | symbol / num / none | symbol | | ||
| type | 输出结果类型(字符串/数组) | string | string / array | string | | ||
| multiple | 输出多音字全部拼音(仅在 word 为长度为 1 的汉字字符串时生效) | boolean | true / false | false | | ||
| 参数 | 说明 | 类型 | 可选值 | 默认值 | | ||
| -------- | ------------------------------------------------------------- | ------- | -------------------------------------- | ------ | | ||
| pattern | 输出的结果的信息(拼音 / 声母 / 韵母 / 音调 / 首字母) | string | pinyin / initial / final / num / first | pinyin | | ||
| toneType | 音调输出形式(拼音符号 / 数字 / 不加音调) | string | symbol / num / none | symbol | | ||
| type | 输出结果类型(字符串/数组) | string | string / array | string | | ||
| multiple | 输出多音字全部拼音(仅在 word 为长度为 1 的汉字字符串时生效) | boolean | true / false | false | | ||
## 使用 | ||
## 使用示例 | ||
### 基本用法 | ||
### 获取拼音 | ||
```javascript | ||
import { pinyin } from 'pinyin-pro'; // 若为node环境请用require形式引入 | ||
```js | ||
// 获取带音调拼音 | ||
@@ -89,4 +88,26 @@ pinyin('汉语拼音'); // 'hàn yǔ pīn yīn' | ||
pinyin('汉语拼音', { toneType: 'num' }); // 'han4 yu3 pin1 yin1' | ||
// 获取数组形式带音调拼音 | ||
pinyin('汉语拼音', { type: 'array' }); // ["hàn", "yǔ", "pīn", "yīn"] | ||
// 获取数组形式不带声调的拼音 | ||
pinyin('汉语拼音', { toneType: 'none', type: 'array' }); // ["han", "yu", "pin", "yin"] | ||
// 获取数组形式声调转换为数字后缀的拼音 | ||
pinyin('汉语拼音', { toneType: 'num', type: 'array' }); // ["han4", "yu3", "pin1", "yin1"] | ||
``` | ||
### 获取声母 | ||
```js | ||
import { pinyin } from 'pinyin-pro'; | ||
// 获取声母 | ||
pinyin('汉语拼音', { pattern: 'initial' }); // 'h y p y' | ||
// 获取数组形式声母 | ||
pinyin('汉语拼音', { pattern: 'initial', type: 'array' }); // ["h", "y", "p", "y"] | ||
``` | ||
### 获取韵母 | ||
```js | ||
import { pinyin } from 'pinyin-pro'; | ||
// 获取带音调韵母 | ||
@@ -98,27 +119,36 @@ pinyin('汉语拼音', { pattern: 'final' }); // 'àn ǔ īn īn' | ||
pinyin('汉语拼音', { pattern: 'final', toneType: 'num' }); // 'an4 u3 in1 in1' | ||
// 获取音调 | ||
pinyin('汉语拼音', { pattern: 'num' }); // '4 3 1 1' | ||
// 获取数组形式带音调韵母 | ||
pinyin('汉语拼音', { pattern: 'final', type: 'array' }); // ["àn", "ǔ", "īn", "īn"] | ||
// 获取数组形式不带音调韵母 | ||
pinyin('汉语拼音', { pattern: 'final', toneType: 'none', type: 'array' }); // ["an", "u", "in", "in"] | ||
// 获取数组形式音调为数字的韵母 | ||
pinyin('汉语拼音', { pattern: 'final', toneType: 'num', type: 'array' }); // ['an4', 'u3', 'in1', 'in1'] | ||
``` | ||
### 结果输出为数组格式 | ||
### 获取音调 | ||
通过在 options 参数中加入`type: 'array'`,可以以数组形式输出基本用法中的示例: | ||
```js | ||
import { pinyin } from 'pinyin-pro'; | ||
```javascript | ||
// 获取带音调拼音 | ||
pinyin('汉语拼音', { type: 'array' }); // ["hàn", "yǔ", "pīn", "yīn"] | ||
// 获取不带声调的拼音 | ||
pinyin('汉语拼音', { toneType: 'none', type: 'array' }); // ["han", "yu", "pin", "yin"] | ||
// 获取声调转换为数字后缀的拼音 | ||
pinyin('汉语拼音', { toneType: 'num', type: 'array' }); // ["han4", "yu3", "pin1", "yin1"] | ||
// 获取声母 | ||
pinyin('汉语拼音', { pattern: 'initial', type: 'array' }); // ["h", "y", "p", "y"] | ||
// 获取带音调韵母 | ||
pinyin('汉语拼音', { pattern: 'final', type: 'array' }); // ["àn", "ǔ", "īn", "īn"] | ||
// 获取不带音调韵母 | ||
pinyin('汉语拼音', { pattern: 'final', toneType: 'none', type: 'array' }); // ["an", "u", "in", "in"] | ||
// 获取音调 | ||
pinyin('汉语拼音', { pattern: 'num' }); // '4 3 1 1' | ||
// 获取数组形式音调 | ||
pinyin('汉语拼音', { pattern: 'num', type: 'array' }); // ["4", "3", "1", "1"] | ||
``` | ||
### 获取拼音首字母 | ||
```js | ||
import { pinyin } from 'pinyin-pro'; | ||
// 获取拼音首字母 | ||
pinyin('赵钱孙李额', { pattern: 'first' }); // 'z q s l é' | ||
// 获取不带音调拼音首字母 | ||
pinyin('赵钱孙李额', { pattern: 'first', toneType: 'none' }); // 'z q s l e' | ||
// 获取数组形式拼音首字母 | ||
pinyin('赵钱孙李额', { pattern: 'first', type: 'array' }); // ['z', 'q', 's', 'l', 'é'] | ||
// 获取数组形式不带音调拼音首字母 | ||
pinyin('赵钱孙李额', { pattern: 'first', toneType: 'none', type: 'array' }); // ['z', 'q', 's', 'l', 'e'] | ||
``` | ||
### 获取单个字的多音 | ||
@@ -129,3 +159,5 @@ | ||
```javascript | ||
// 获取多音 | ||
pinyin('好', { multiple: true }); // 'hǎo hào' | ||
// 获取数组形式多音 | ||
pinyin('好', { multiple: true, type: 'array' }); // ["hǎo", "hào"] | ||
@@ -140,2 +172,2 @@ ``` | ||
![wechat](https://i.ibb.co/VYXW19H/QQ-20210323221842.jpg) | ||
![wechat](https://p3-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/dfdb0fa475e04407a8582d0bd185b69c~tplv-k3u1fbpfcp-zoom-1.image) |
@@ -0,0 +0,0 @@ const { pinyin } = require('../dist/index'); |
@@ -0,0 +0,0 @@ const { pinyin } = require('../dist/index'); |
@@ -46,2 +46,13 @@ const { pinyin } = require('../dist/index'); | ||
expect(resultFinal).to.be.equal('ào ián ūn ǐ a'); | ||
const resultFirst = pinyin('赵钱孙李额', { | ||
pattern: 'first', | ||
}); | ||
expect(resultFirst).to.be.equal('z q s l é'); | ||
const resultFirst2 = pinyin('赵钱孙李额', { | ||
pattern: 'first', | ||
toneType: 'none', | ||
}); | ||
expect(resultFirst2).to.be.equal('z q s l e'); | ||
}); | ||
@@ -48,0 +59,0 @@ |
@@ -0,0 +0,0 @@ { |
export declare const DICT1: { | ||
[prop: string]: string; | ||
}; |
export declare const DICT2: { | ||
[prop: string]: string; | ||
}; |
export declare const DICT3: { | ||
[prop: string]: string; | ||
}; |
export declare const DICT4: { | ||
[prop: string]: string; | ||
}; |
export declare const DICT5: { | ||
[prop: string]: string; | ||
}; |
export declare const INITIAL_LIST: string[]; |
@@ -16,2 +16,4 @@ declare type GetPinYin = (word: string, length: number) => string; | ||
declare const getPinyinWithNum: GetPinyinWithNum; | ||
export { getPinyin, getPinyinWithoutTone, getInitialAndFinal, getMultipleTone, getNumOfTone, getPinyinWithNum, }; | ||
declare type GetFirstLetter = (pinyin: string) => string; | ||
declare const getFirstLetter: GetFirstLetter; | ||
export { getPinyin, getPinyinWithoutTone, getInitialAndFinal, getMultipleTone, getNumOfTone, getPinyinWithNum, getFirstLetter, }; |
export { pinyinFn as pinyin } from './pinyin'; |
declare type PinyinFn = (word: string, options?: { | ||
toneType?: 'symbol' | 'num' | 'none'; | ||
pattern?: 'pinyin' | 'initial' | 'final' | 'num'; | ||
pattern?: 'pinyin' | 'initial' | 'final' | 'num' | 'first'; | ||
type?: 'string' | 'array'; | ||
@@ -5,0 +5,0 @@ multiple?: boolean; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1092552
30392
166
1