github.com/anth0d/nomad@v0.0.0-20221214183521-ae3a0a2cad06/ui/app/helpers/trim-path.js (about)

     1  // @ts-check
     2  import Helper from '@ember/component/helper';
     3  
     4  /**
     5   * Trims any number of slashes from the beginning and end of a string.
     6   * @param {Array<string>} params
     7   * @returns {string}
     8   */
     9  export function trimPath([path]) {
    10    if (!path) return;
    11    if (path.startsWith('/')) {
    12      path = trimPath([path.slice(1)]);
    13    }
    14    if (path?.endsWith('/')) {
    15      path = trimPath([path.slice(0, -1)]);
    16    }
    17    return path;
    18  }
    19  
    20  export default Helper.helper(trimPath);