Bookmark this: tool.io/random/chinese-character/source-code
Random Chinese Character Generator Source Code
Browse the implementation files for Random Chinese Character Generator.tool.ts typescript
import { validateChoice } from '../../../tool-runtime/validateChoice';
import { calculateRandomItem } from '../item/tool';
const CHARACTERS = {
common: [
...'的一是不了在人有我他这为之大来以个中上们到说国和地也子时道出而要于就下得可你年生自会那后能对着事其里所去行过家十用发天如然作方成者多日都三小军二无同么经法当起与好看学进种将还分此心前面又定见只主没公从知全工使情明性知高长'
],
simplified: [...'汉语书车门云东风电广乐龙马鸟鱼国爱学体'],
traditional: [...'漢語書車門雲東風電廣樂龍馬鳥魚國愛學體']
} as const;
const SETS = [
'all',
'common',
'simplified',
'traditional'
] as const;
export const randomChineseCharacter = (
setInput: unknown
): string => {
const set = validateChoice(setInput, SETS);
if (set === null) return '';
return (
calculateRandomItem(
set === 'all'
? Object.values(CHARACTERS).flat()
: CHARACTERS[set]
) ?? ''
);
};
export const Tool: TypeTool = {
name: 'Random Chinese Character Generator',
slug: 'random/chinese-character',
intro:
'Generate a random Chinese character from a curated common, Simplified, or Traditional set.',
tool: randomChineseCharacter,
i: [
{
example: 'all',
label: 'Character set',
placeholder: 'Chinese character set',
type: 'select',
value: 'all',
options: [
{
value: 'all',
text: 'All curated characters',
selected: true
},
{ value: 'common', text: 'Common characters' },
{ value: 'simplified', text: 'Simplified examples' },
{ value: 'traditional', text: 'Traditional examples' }
]
}
],
o: [
{
example: '中',
label: 'Random Chinese character',
placeholder: 'Random Chinese character',
render: 'textarea',
type: 'text'
}
],
rerunnable: true,
alternative: [
{ title: 'Random Kanji', url: '/random/kanji' },
{ title: 'Random Hiragana', url: '/random/hiragana' },
{ title: 'Random Katakana', url: '/random/katakana' }
],
cite: [
{
title: 'Chinese characters - Wikipedia',
url: 'https://en.wikipedia.org/wiki/Chinese_characters'
}
]
};
export default Tool;
Description
Browse the implementation files for Random Chinese Character Generator.