1.1.0 • Published 5 years ago

chinese-idiom-chengyu v1.1.0

Weekly downloads
4
License
MIT
Repository
github
Last release
5 years ago

Chinese Idioms Chengyu

Simple npm package that contains utilities for Chinese idioms or Chengyu. Functions available right now are for Chinese idioms solitaire or Chengyu Jielong. More functions will be added in the future versions!

Installation

npm install chinese-idioms-chengyu

Usage

Solitaire Functions

NameParamsDescriptionError handling
nextIdiomsWithMatchingCharacteridiomWord - String of Chinese characters of the idiom options - return idioms as word-pinyin-pairs, words, or pinyinReturns a list of idiom word-pinyin-pairs, words, or pinyin that have idioms where the first character is the same as the last character of the parameter idiomWord.Throw an error when idiomWord does not exist.
nextIdiomsWithMatchingTonePinyinidiomWord - String of Chinese characters of the idiom options - return idioms as word-pinyin-pairs, words, or pinyinReturns a list of idiom word-pinyin-pairs, words, or pinyin that have idioms where the pinyin of the first character is the same as the pinyin of the last character of the parameter idiomWord.Throw an error when idiomWord does not exist.
nextIdiomsWithMatchingNoTonePinyinidiomWord - String of Chinese characters of the idiom options - return idioms as word-pinyin-pairs, words, or pinyinReturns a list of idiom word-pinyin-pairs, words, or pinyin that have idioms where the pinyin of the first character is the same as the pinyin of the last character of the parameter idiomWord disregarding the tone.Throw an error when idiomWord does not exist.

Search Functions

NameParamsDescriptionError handling
startWithCharactercharacter - String of first character of the idiom options - return idioms as word-pinyin-pairs, words, or pinyinReturn a list of idiom word-pinyin-pairs, word, or pinyin that starts with the parameter character.Throw an error when options is not valid.
startWithTonePinyinpinyin - String of pinyin of first character of the idiom options - return idioms as word-pinyin-pairs, words, or pinyinReturn a list of idiom word-pinyin-pairs, word, or pinyin that starts with the parameter pinyin.Throw an error when options is not valid.
startWithNoTonePinyinnoTonePinyin - String of no tone pinyin of first character of the idiom options - return idioms as word-pinyin-pairs, words, or pinyinReturn a list of idiom word-pinyin-pairs, word, or pinyin that starts with the parameter noTonEpinyin.Throw an error when options is not valid.
getDefinitionidiomWord - String of idiom wordReturn the definition of the parameter idiomWordThrow an error when idiomWord does not exist.

Options

NameTypeDefault valueDescription
wordBooleantrueWhether returned idioms include the string of words
pinyinBooleantrueWhether returned idioms include the string of pinyin

Example

const chengyu = require('chinese-idioms-chengyu')

const idiom = '全力以赴' // [ '全力以赴' : 'quán lì yǐ fù' ]
const lessIdioms = chengyu.nextIdiomsWithMatchingCharacter(idiom)
console.log(lessIdioms.length)
console.log(lessIdioms[0])

const wordOnly = chengyu.nextIdiomsWithMatchingCharacter(idiom, {word: true, pinyin: false})
console.log(wordOnly[0])

const moreIdioms = chengyu.nextIdiomsWithMatchingNoTonePinyin(idiom)
console.log(moreIdioms.length)
console.log(moreIdioms[0])

const pinyinOnly = chengyu.nextIdiomsWithMatchingNoTonePinyin(idiom, {word: false, pinyin: true})
console.log(pinyinOnly[0])

Output

2
[ '赴汤蹈火', 'fù tāng dǎo huǒ' ]
赴汤蹈火
347
[ '夫倡妇随', 'fū chàng fù suí' ]
fū chàng fù suí

License

MIT

Acknowledge

chinese-xinhua