aba957660f
* fix bug in trim-right util where the last ending wasn't trimming from the end of the string * simplify based on feedback
9 lines
374 B
JavaScript
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, '');
|
|
}
|