1// qcode-ui v1.0.53 2import html_escape from '/static/js/qcode-ui/html_escape-a0db4a7e.js' 3 4/** 5 * Escape special characters in a string for use in a regular expression. 6 * 7 * @param {string} string - The string to escape. 8 * @returns {string} - The escaped string. 9 */ 10function regex_escape (string) { 11 return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&') 12} 13 14/** 15 * Replace all occurrences of a substring in a string. 16 * 17 * @param {string} string - The input string. 18 * @param {string} pattern - The substring to find. 19 * @param {string} replacement - The replacement string. 20 * @returns {string} - The resulting string after replacements. 21 */ 22function string_replace_all (string, pattern, replacement) { 23 const pattern_regex = new RegExp(regex_escape(pattern), 'g') 24 return string.replace(pattern_regex, replacement) 25} 26 27 28/** 29 * Replace template placeholders in a string with values. 30 * 31 * @param {string} template - The template string. 32 * @param {object} map - The object containing the key-value pairs to replace. 33 * @returns {string} - Returns the string with the placeholders replaced. 34 * 35 * @example 36 * const template = 'Hello, {{name}}!' 37 * const name = 'unsafe <script> code' 38 * const map = { 39 * name 40 * } 41 * return template_substitute(template, map) 42 * // => 'Hello, unsafe <script> code!' 43 * 44 */ 45 46function template_substitute (template, map) { 47 for (const [key, value] of Object.entries(map)) { 48 // triple braces - no escaping 49 template = string_replace_all(template, '{{{' + key + '}}}', value) 50 51 // double braces - html escape 52 template = string_replace_all(template, '{{' + key + '}}', html_escape(value)) 53 } 54 55 return template 56} 57 58export { regex_escape, string_replace_all } // For testing purposes 59export default template_substitute
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.