1.0.0 • Published 6 months ago
@jimmyclchu/cangjie v1.0.0
@jimmyclchu/cangjie
A TypeScript library for Cangjie/Sucheng input method code lookup.
Installation
npm install @jimmyclchu/cangjieUsage
JavaScript
const { Cangjie } = require('@jimmyclchu/cangjie');
const cj = new Cangjie();
console.log(cj.searchCodes('香港')); // ['hda', 'etcu']TypeScript
import { Cangjie, CangjieOptions } from '@jimmyclchu/cangjie';
const cj = new Cangjie({ inputMethod: 'cangjie' });
console.log(cj.searchCodes('同熱愛這片土地')); // ['bmr', 'gif', 'bbpe', 'yymr', 'llml', 'g', 'gpd']API
Constructor
new Cangjie(options?: CangjieOptions)Methods
searchCodes(text: string): string[]
Get Cangjie codes for Chinese characters.
cj.searchCodes('難'); // ['toog']
cj.searchCodes('Hello香港World'); // ['hda', 'etcu'] - auto-extracts ChinesesearchCharacters(code: string): string[]
Get characters for a given code.
cj.searchCharacters('a'); // ['日', '曰']searchRadicals(text: string): string[]
Get radical representations grouped by character.
cj.searchRadicals('日月'); // ['日', '月']
cj.searchRadicals('你好'); // ['人弓火', '女弓木']containsChinese(text: string): boolean
Check if text contains any Chinese characters.
cj.containsChinese('Hello香港'); // trueisAllChinese(text: string): boolean
Check if text contains only Chinese characters.
cj.isAllChinese('香港'); // true
cj.isAllChinese('Hello香港'); // falseextractChinese(text: string): string
Extract only Chinese characters from text.
cj.extractChinese('Hello朋友World'); // '朋友'setInputMethod(method: 'cangjie' | 'sucheng'): void
Switch between Cangjie and Sucheng input methods.
cj.setInputMethod('sucheng');
cj.searchCodes('你'); // ['of'] - first + last code only
cj.searchRadicals('你'); // ['人火'] - simplified radicals for suchengInput Methods
- Cangjie
- Sucheng
License
MIT
1.0.0
6 months ago