UNPKG

@redocly/theme

Version:

Shared UI components lib

15 lines (11 loc) 433 B
export function replaceInputsWithValue(node: string, inputs: Record<string, { value?: string }>) { const validKeys = Object.entries(inputs) .filter(([_, input]) => input.value) .map(([key]) => key) .join('|'); if (!validKeys) { return node; } const inputRegex = new RegExp(`\\{\\{\\s*(${validKeys})\\s*\\}\\}`, 'g'); return node.replace(inputRegex, (_, inputKey) => inputs[inputKey]?.value as string); }