-
Notifications
You must be signed in to change notification settings - Fork 23
/
stringReplacer.js
23 lines (21 loc) · 859 Bytes
/
stringReplacer.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
const replaceStream = require("replacestream");
/**
* Replaces placeholders with corresponding values.
*
* @public
* @alias module:@ui5/builder.processors.stringReplacer
* @param {Object} parameters Parameters
* @param {module:@ui5/fs.Resource[]} parameters.resources List of resources to be processed
* @param {Object} parameters.options Options
* @param {string} parameters.options.pattern Pattern of placeholders
* @param {string} parameters.options.replacement Replacement for placeholders
* @returns {Promise<module:@ui5/fs.Resource[]>} Promise resolving with modified resources
*/
module.exports = function({resources, options}) {
return Promise.all(resources.map((resource) => {
const stream = resource.getStream()
.pipe(replaceStream(options.pattern, options.replacement));
resource.setStream(stream);
return resource;
}));
};