mirror of
				https://github.com/Qortal/qortal-ui.git
				synced 2025-11-03 22:27:51 +00:00 
			
		
		
		
	
		
			
				
	
	
		
			16 lines
		
	
	
		
			561 B
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
			
		
		
	
	
			16 lines
		
	
	
		
			561 B
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
export function interpolate(text, values, config) {
 | 
						||
    return Object.entries(extract(values || {})).reduce((text, [key, value]) => text.replace(new RegExp(`{{[  ]*${key}[  ]*}}`, `gm`), String(extract(value))), text)
 | 
						||
}
 | 
						||
 | 
						||
export function lookup(key, config) {
 | 
						||
    const parts = key.split(".")
 | 
						||
    let string = config.strings
 | 
						||
    while (string != null && parts.length > 0) {
 | 
						||
        string = string[parts.shift()]
 | 
						||
    }
 | 
						||
    return string != null ? string.toString() : null
 | 
						||
}
 | 
						||
 | 
						||
export function extract(obj) {
 | 
						||
    return (typeof obj === "function") ? obj() : obj
 | 
						||
} |