open-vault/ui/app/utils/trim-right.js
Hamid Ghaf 27bb03bbc0
adding copyright header (#19555)
* adding copyright header

* fix fmt and a test
2023-03-15 09:00:52 -07:00

14 lines
459 B
JavaScript

/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: MPL-2.0
*/
// 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, '');
}