UNPKG

pinyin-utils

Version:

Utilities to transform Pinyin syllables

83 lines (82 loc) 2.63 kB
/** * Create a unicode character from the codepoint of a Chinese character * @param codepoint codepoint of Chinese character as number or string type * @example * ``` * codepointToUnicode(0x6211) // 我 * codepointToUnicode('0x6211') // 我 * codepointToUnicode('U+6211') // 我 * codepointToUnicode('6211') // 我 * ``` */ export declare const codepointToUnicode: (codepoint: number | string) => string; /** * Four tones: ` ̄` ` ́` ` ̌` ` ̀` */ export declare const toneMarks: string[]; /** * Returns the tone number of a Pinyin syllable * @param text Pinyin syllable to get the tone number from * @example * ``` * getToneNumber('shì') // 4 * getToneNumber('shi4') // 4 * ``` */ export declare const getToneNumber: (text: string) => number; /** * Removes the tone mark/number from a Pinyin syllable * @param text Pinyin syllable to remove the tone mark/number from * @example * ``` * removeTone('wǒ') // wo * removeTone('wo3') // wo * ``` */ export declare const removeTone: (text: string) => string; /** * Converts the tone mark into the corresponding tone number * @param text Pinyin syllable containing the tone mark to be converted * @param fithTone show fith tone as number (ex. `he` => `he5`) * @example * ``` * markToNumber('lǜ') // lü4 * markToNumber('he') // he5 * markToNumber('he', false) // he * ``` */ export declare function markToNumber(text: string, fithTone?: boolean): string; /** * Converts the tone mark into the corresponding tone number * @param list list of Pinyin syllables containing the tone mark to be converted * @param fithTone show fith tone as number (ex. `he` => `he5`) * @example * ``` * markToNumber(['Wǒ', 'shì', 'dé', 'guó', 'rén']) * // ['Wo3', 'shi4', 'de2', 'guo2', 'ren2'] * markToNumber(['he']) // ["he5"] * markToNumber(['he'], false) // ["he"] * ``` */ export declare function markToNumber(list: string[], fithTone?: boolean): string[]; /** * Converts the tone number into the corresponding tone mark * @param text Pinyin syllable containing the tone number to be converted * @example * ``` * numberToMark('lü4') // lǜ * numberToMark('he5') // he * ``` */ export declare function numberToMark(text: string): string; /** * Converts the tone number into the corresponding tone mark * @param list list of Pinyin syllables containing the tone number to be converted * @example * ``` * markToNumber(['Wo3', 'shi4', 'de2', 'guo2', 'ren2']) * // ['Wǒ', 'shì', 'dé', 'guó', 'rén'] * numberToMark('he5') // he * ``` */ export declare function numberToMark(list: string[]): string[];