Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Replace %x parameters in string
- *
- * @param {String} str The chain of characters with %x...%x+1 parameters
- * @param {Array} params The parameters to be included in the string. Accept: {string, number, node, component}
- * @returns {Array}
- *
- * Usage:
- * @example
- * // returns ['Example with ', 'param1', 'and', '<strong>param2</strong>']
- * replacePramsInString('Example with %0 and %1", ["param1", <strong>param2</strong>]);
- */
- const replacePramsInString = (str, params) => {
- const items = Array.isArray(params) ? params : [params];
- return str.split(/%\d/).reduce((accumulator, currentValue, index) => {
- const item = items[index];
- accumulator.push(currentValue);
- accumulator.push(item);
- return accumulator;
- }, []);
- };
- export {
- replacePramsInString
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement