open-nomad/ui/app/helpers/trim-path.js
2023-04-10 15:36:59 +00:00

26 lines
532 B
JavaScript

/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: MPL-2.0
*/
// @ts-check
import Helper from '@ember/component/helper';
/**
* Trims any number of slashes from the beginning and end of a string.
* @param {Array<string>} params
* @returns {string}
*/
export function trimPath([path]) {
if (!path) return;
if (path.startsWith('/')) {
path = trimPath([path.slice(1)]);
}
if (path?.endsWith('/')) {
path = trimPath([path.slice(0, -1)]);
}
return path;
}
export default Helper.helper(trimPath);