UNPKG

@mintlify/common

Version:

Commonly shared code within Mintlify

29 lines (28 loc) 753 B
import filterXSS from 'xss'; const VARIABLE_REGEX = /\{\{\s*([\w.\-]+)\s*\}\}/g; const EXECUTABLE_TAGS = [ 'script', 'style', 'iframe', 'object', 'embed', 'form', 'link', 'meta', 'base', ]; function sanitizeVariableValue(value) { return filterXSS(value, { whiteList: {}, stripIgnoreTag: true, stripIgnoreTagBody: EXECUTABLE_TAGS, }); } export function replaceVariables(content, variables) { if (!variables || Object.keys(variables).length === 0 || !content.includes('{{')) return content; return content.replace(VARIABLE_REGEX, (match, key) => { const value = variables[key]; return value !== undefined ? sanitizeVariableValue(value) : match; }); }