open-vault/ui/app/utils/trim-right.js
Matthew Irish aba957660f
UI - fix bug in policy creation from files (#5864)
* fix bug in trim-right util where the last ending wasn't trimming from the end of the string

* simplify based on feedback
2018-11-28 10:35:55 -06:00

9 lines
374 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) {
let prefix = isExtension ? '\\' : '';
let trimRegex = new RegExp(endings.map(ext => `${prefix}${ext}$`).join('|'));
return str.replace(trimRegex, '');
}