Bookmark this: tool.io/random/hiragana/source-code
Random Hiragana Generator Source Code
Browse the implementation files for Random Hiragana Generator.tool.ts typescript
import { validateChoice } from '../../../tool-runtime/validateChoice';
import { calculateRandomItem } from '../item/tool';
const SETS = {
basic: [
...'あいうえおかきくけこさしすせそたちつてとなにぬねのはひふへほまみむめもやゆよらりるれろわをん'
],
voiced: [
...'がぎぐげござじずぜぞだぢづでどばびぶべぼぱぴぷぺぽ'
]
} as const;
const SET_CHOICES = ['all', 'basic', 'voiced'] as const;
export const randomHiragana = (setInput: unknown): string => {
const set = validateChoice(setInput, SET_CHOICES);
if (set === null) return '';
return (
calculateRandomItem(
set === 'all' ? Object.values(SETS).flat() : SETS[set]
) ?? ''
);
};
export const Tool: TypeTool = {
name: 'Random Hiragana Generator',
slug: 'random/hiragana',
intro:
'Generate a random basic or voiced hiragana character.',
tool: randomHiragana,
i: [
{
example: 'all',
label: 'Character set',
placeholder: 'Hiragana set',
type: 'select',
value: 'all',
options: [
{
value: 'all',
text: 'Basic and voiced',
selected: true
},
{ value: 'basic', text: 'Basic' },
{ value: 'voiced', text: 'Voiced and semi-voiced' }
]
}
],
o: [
{
example: 'あ',
label: 'Random hiragana',
placeholder: 'Random hiragana',
render: 'textarea',
type: 'text'
}
],
rerunnable: true,
alternative: [
{ title: 'Random Katakana', url: '/random/katakana' },
{ title: 'Random Kanji', url: '/random/kanji' },
{ title: 'Random Letter', url: '/random/letter' }
],
cite: [
{
title: 'Hiragana - Wikipedia',
url: 'https://en.wikipedia.org/wiki/Hiragana'
}
]
};
export default Tool;
Description
Browse the implementation files for Random Hiragana Generator.