mirror of
https://git.joinsharkey.org/Sharkey/Sharkey.git
synced 2024-11-09 03:53:08 +02:00
18 lines
642 B
JavaScript
18 lines
642 B
JavaScript
const loaderUtils = require('loader-utils');
|
|
|
|
function trim(text, g) {
|
|
return text.substring(1, text.length - (g ? 2 : 0));
|
|
}
|
|
|
|
module.exports = function(src) {
|
|
this.cacheable();
|
|
const options = loaderUtils.getOptions(this);
|
|
const search = options.search;
|
|
const g = search[search.length - 1] == 'g';
|
|
const replace = global[options.replace];
|
|
if (typeof search != 'string' || search.length == 0) console.error('invalid search');
|
|
if (typeof replace != 'function') console.error('invalid replacer:', replace, this.request);
|
|
src = src.replace(new RegExp(trim(search, g), g ? 'g' : ''), replace);
|
|
this.callback(null, src);
|
|
return src;
|
|
};
|