1
0
Fork 0
management/front/dkha-web-sz-main/node_modules/svg-sprite-loader/lib/utils/replace-sprite-placeholder.js

27 lines
722 B
JavaScript
Raw Permalink Normal View History

2023-12-18 13:12:25 +08:00
const escapeRegExpSpecialChars = require('escape-string-regexp');
const isWindows = /^win/i.test(process.platform);
/**
* @param {string} content
* @param {Object<string, string>} replacements
* @return {string}
*/
function replaceSpritePlaceholder(content, replacements) {
let result = content;
Object.keys(replacements)
.forEach((subj) => {
let re = new RegExp(escapeRegExpSpecialChars(subj), 'g');
result = result.replace(re, replacements[subj]);
if (isWindows) {
re = new RegExp(escapeRegExpSpecialChars(subj), 'g');
result = result.replace(/\\\\/g, '\\').replace(re, replacements[subj]);
}
});
return result;
}
module.exports = replaceSpritePlaceholder;