UNPKG

@alauda/doom

Version:

Doctor Doom making docs.

32 lines (31 loc) 1.02 kB
import { jsx as _jsx } from "react/jsx-runtime"; import { capitalize } from 'es-toolkit'; import { useMemo } from 'react'; import { useSiteOverrides } from '../hooks/index.js'; import { handleCJKWhitespaces } from '../utils.js'; import { Markdown } from './Markdown.js'; export const Term = ({ name, textCase }) => { const { terms } = useSiteOverrides(); const text = useMemo(() => { const origin = handleCJKWhitespaces(terms?.[name]); if (!origin) { return origin; } switch (textCase) { case 'lower': { return origin.toLowerCase(); } case 'upper': { return origin.toUpperCase(); } case 'capitalize': { return origin.split(/\b/).map(capitalize).join(''); } default: { return origin; } } }, [terms, name, textCase]); return _jsx(Markdown, { inline: true, children: text }); }; export default Term;