js 获取css内背景图片和字体文件过滤base64

js yekong 997℃

首先需要获取css文件的数据内容,然后进行过滤,并过滤掉不需要的字符内容

export function getCssInFile(data) {
    var pattern = /url\((\S*?)\)/g
    let fileList = data.match(pattern)
    var newfileList = []
    if (fileList) {
        fileList.forEach((type) => {
            type = type.replace('url(', '')
            type = type.replace(')', '')
            // 判断字符串是否包含指定字符串
            if (!doesItInclude('data:image', type)) {
                newfileList.push(type)
            }
        });
    }
    return newfileList
}
喜欢 (0)