-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
25 lines (19 loc) · 733 Bytes
/
index.js
File metadata and controls
25 lines (19 loc) · 733 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
var querystring = require('querystring')
module.exports = function strReplaceLoader(source) {
this.cacheable()
var query = (typeof this.query === 'string')
? querystring.parse(this.query.substring(1))
: this.query
if ( !query.match
|| ( typeof query.match !== 'string'
&& !(query.match instanceof RegExp)
)
) throw ('* str-replace-loader * missing or invalid option. `match` must be [String] or [RegExp]')
if ( !query.replace
|| ( typeof query.replace !== 'string'
&& typeof query.replace !== 'function'
)
) throw ('* str-replace-loader * missing or invalid option. `replace` must be [String] or [Function]')
return source.toString()
.replace(query.match, query.replace)
}