UNPKG

zh-hant

Version:

A simple Simplified-Traditional Chinese converter. Supports DOM auto-conversion.

22 lines (17 loc) 512 B
import { zh_s, zh_t } from './zh-map' export type LangMode = 'zh-s' | 'zh-t' export function transform(text: string, from: string, to: string): string { return text .split('') .map(char => { const index = from.indexOf(char) return index !== -1 ? to.charAt(index) : char }) .join('') } export function toTrad(text: string): string { return transform(text, zh_s, zh_t) } export function toSimp(text: string): string { return transform(text, zh_t, zh_s) }