/**
 *****************************************
 * Created by edonet@163.com
 * Created on 2020-09-05 11:23:10
 *****************************************
 */ 'use strict' ; /**
 *****************************************
 * 定义匹配项
 *****************************************
 */ const regexp = /\$\{(.*?)\}/g ; /**
 *****************************************
 * 失败内容
 *****************************************
 */ async function replace ( str , handler ) { if ( str ) { let matched = regexp . exec ( str ) ; let result = '' ; let idx = 0 ; while ( matched ) { result += str . slice ( idx , matched . index ) ; result += await handler ( matched [ 1 ] ) || '' ; idx = matched . index + matched [ 0 ] . length ; matched = regexp . exec ( str ) ; } return result + str . slice ( idx ) ; } return str ; } /**
 *****************************************
 * 抛出接口
 *****************************************
 */ export default replace ;