Skip to content

Main content

Random Letter Generator Source Code

Browse the implementation files for Random Letter Generator.
tool.ts typescript
import { calculateRandomLetter } from '@tool.io/tools/random/letter';
import type { RandomSource } from '@tool.io/tools/random/number';
import { validateChoice } from '../../../tool-runtime/validateChoice';

const CASES = ['uppercase', 'lowercase', 'mixed'] as const;

export const randomLetter = (
	caseInput: unknown,
	random: RandomSource = Math.random
): string => {
	const letterCase = validateChoice(caseInput, CASES);
	if (letterCase === null) return '';

	return calculateRandomLetter(letterCase, random) ?? '';
};

export const Tool: TypeTool = {
	name: 'Random Letter Generator',
	slug: 'random/letter',
	intro: 'Generate a random letter from the Latin alphabet.',
	tool: randomLetter,
	i: [
		{
			example: 'mixed',
			label: 'Letter case',
			placeholder: 'Letter case',
			type: 'select',
			value: 'mixed',
			options: [
				{
					value: 'mixed',
					text: 'Uppercase and lowercase',
					selected: true
				},
				{ value: 'uppercase', text: 'Uppercase' },
				{ value: 'lowercase', text: 'Lowercase' }
			]
		}
	],
	o: [
		{
			example: 'R',
			label: 'Random letter',
			placeholder: 'Random letter',
			render: 'textarea',
			type: 'text'
		}
	],
	rerunnable: true,
	alternative: [
		{ title: 'Random Hiragana', url: '/random/hiragana' },
		{ title: 'Random Katakana', url: '/random/katakana' },
		{ title: 'Random Symbol', url: '/random/symbol' }
	],
	cite: [
		{
			title: 'Latin alphabet - Wikipedia',
			url: 'https://en.wikipedia.org/wiki/Latin_alphabet'
		}
	]
};

export default Tool;

Description

Browse the implementation files for Random Letter Generator.

References

  1. Tool.io on GitHub
  2. Tool.io TypeScript tools library

Similar or alternative tools