open-consul/ui/packages/consul-ui/app/utils/right-trim.js

13 lines
288 B
JavaScript
Raw Normal View History

/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: MPL-2.0
*/
2018-05-25 12:15:27 +00:00
export default function rightTrim(str = '', search = '') {
const pos = str.length - search.length;
if (pos >= 0) {
return str.lastIndexOf(search) === pos ? str.substr(0, pos) : str;
}
return str;
2018-05-25 12:15:27 +00:00
}