Files
DefinitelyTyped/types/pinyin/index.d.ts
wanganjun e160492009 add pinyin 2.8.3 (#18344)
* add pinyin 2.8.3

* format code

* more meaningful parameters

* export Options

* support UMD

* add jsdoc

* add dom support for compilation

* add tslint.json

* fix lint error

* fix lint error
2017-07-25 08:20:36 -07:00

80 lines
2.8 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// Type definitions for pinyin 2.8
// Project: https://github.com/hotoo/pinyin
// Definitions by: AnJun Wang <https://github.com/wanganjun>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
export = pinyin;
export as namespace pinyin;
/**
* 转换中文字符为拼音。可以设定拼音风格,可以打开多音字选项,也可以打开分词。
* @example
* pinyin("中心") // returns [ [ 'zhōng' ], [ 'xīn' ] ]
*/
declare function pinyin(words: string, options?: pinyin.Options): string[][];
declare namespace pinyin {
/**
* 按拼音比较两个字符串 a 和 b 的顺序。
* 如果返回 -1 表示 a 在 b 前
* 如果返回 0 表示 a 和 b 顺序相同
* 如果返回 1 表示 a 在 b 后
*/
function compare(a: string, b: string): -1 | 0 | 1;
/**
* 普通风格,即不带声调。
* 如pin yin
*/
const STYLE_NORMAL: number;
/**
* 声调风格,拼音声调在韵母第一个字母上。
* 如pīn yīn
*/
const STYLE_TONE: number;
/**
* 声调风格 2即拼音声调以数字形式在各个拼音之后用数字 [0-4] 进行表示。
* 如pin1 yin1
*/
const STYLE_TONE2: number;
/**
* 声调风格 3即拼音声调以数字形式在注音字符之后用数字 [0-4] 进行表示。
* 如pi1n yi1n
*/
const STYLE_TO3NE: number;
/**
* 声母风格,只返回各个拼音的声母部分。对于没有声母的汉字,返回空白字符串。
* 如:中国 的拼音 zh g
* 注:声母风格会区分 zh 和 zch 和 csh 和 s。
* 部分汉字没有声母,如 啊,饿 等,另外 y, w, yu 都不是声母, 这些汉字的拼音声母风格会返回 ""
*/
const STYLE_INITIALS: number;
/**
* 首字母风格,只返回拼音的首字母部分。
* 如p y
*/
const STYLE_FIRST_LETTER: number;
interface Options {
/**
* 设置拼音风格,默认风格是 {@link STYLE_TONE}
* @see {@link STYLE_NORMAL}
* @see {@link STYLE_TONE}
* @see {@link STYLE_TONE2}
* @see {@link STYLE_TO3NE}
* @see {@link STYLE_INITIALS}
* @see {@link STYLE_FIRST_LETTER}
*/
style?: number;
/**
* 是否启用分词模式,默认关闭。
* 中文分词有助于极大的降低多音字问题。但性能会极大的下降,内存也会使用更多。
*/
segment?: boolean;
/**
* 是否启用多音字模式,默认关闭。
* 关闭多音字模式时,返回每个汉字第一个匹配的拼音。
* 启用多音字模式时,返回多音字的所有拼音列表。
*/
heteronym?: boolean;
}
}