import { ICnChar } from 'cnchar-types/main' ; import { Json } from 'cnchar-types/main/common' ; import dict from './dict/radicals.json' ; import { RadicalArg , ISetRadical , IRadical } from 'cnchar-types/plugin/radical' ; const radicals = dict as Json < string > ; export const arg = { array : 'array' } ; let _cnchar ; export const radical = ( ( input , ... args ) : string | Array < string > => { if ( _cnchar ) { _cnchar . _ . checkArgs ( 'radical' , args ) ; } let res = '' ; for ( let i = 0 ; i < input . length ; i ++ ) { const char = radicals [ input [ i ] ] ; if ( char ) { res += char ; } else { res += input [ i ] ; } } if ( args . indexOf ( arg . array ) !== - 1 || input instanceof Array ) { return res . split ( '' ) ; } return res ; } ) as IRadical ; export function setCnchar ( cnchar ) { _cnchar = cnchar ; } export const setRadical = ( key , value ? ) : void => { _cnchar . _ . mapJson ( key , value , ( k , v ) => { radicals [ k ] = v ; } ) ; } ;