Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
var utils = require('loader-utils');

module.exports = function (source) {
module.exports = function(source) {
this.cacheable();
var query = utils.parseQuery(this.query);

if (typeof query.search !== 'undefined' && typeof query.replace !== 'undefined') {
if (typeof query.flags !== 'undefined') {
query.search = new RegExp(query.search, query.flags);
}
var query = utils.parseQuery(this.query);
for (var i = 0; i < query.replace.length; i++) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't forget about backward compatibility for those who want replace only one option. And I personally suggest use "multiple" term instead of "replace".
UPD. Oops didn't see that now "replace" is already used, and I think we can leave it as is:)

if (Array.isArray(query.replace) {
  ...
} else if (typeof query.search !== 'undefined' && typeof query.replace !== 'undefined') {
  ...
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

var option = query.replace[i];

source = source.replace(query.search, query.replace);
source = source.split(option.search).join(option.replace)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

readd regex + flags

}

return source;
Expand Down