MathiasKandelborg/TRUE-framework

View on GitHub
util/ifPathnameIsIndex.ts

Summary

Maintainability
A
0 mins
Test Coverage
/**
 * Takes a string and reassigns the value depending on the content
 *
 * @param {string} pathname - The pathname
 * @returns {string} The pathname with '/' prepended or just /
 */
function ifPathnameIsIndex(pathname: string | null | undefined): string {
  if (pathname !== '/') {
    // eslint-disable-next-line no-param-reassign
    pathname = `/${pathname || ''}`
  }

  return pathname
}

export default ifPathnameIsIndex