vikunja-frontend/src/helpers/replaceAll.js

15 lines
372 B
JavaScript
Raw Normal View History

/**
* This function replaces all text, no matter the case.
*
* See https://stackoverflow.com/a/7313467/10924593
*
* @parma str
* @param search
* @param replace
* @returns {*}
*/
export const replaceAll = (str, search, replace) => {
2021-07-19 11:18:22 +02:00
const esc = search.replace(/[-/\\^$*+?.()|[\]{}]/g, '\\$&')
const reg = new RegExp(esc, 'ig')
return str.replace(reg, replace)
}