vault/ui/app/utils/trim-right.js
Jordan Reimer 483ef19946
Eslint prefer-const (#17864)
* adds prefer-const to eslint config and runs fixer

* reverts unintended change
2022-11-09 15:15:31 -08:00

9 lines
381 B
JavaScript

// will trim a given set of endings from the end of a string
// if isExtension is true, the first char of that string will be escaped
// in the regex
export default function (str, endings = [], isExtension = true) {
const prefix = isExtension ? '\\' : '';
const trimRegex = new RegExp(endings.map((ext) => `${prefix}${ext}$`).join('|'));
return str.replace(trimRegex, '');
}