some functions for preparing string on typescript there is a need for a more elegant solution

Maybe a different organization:

const transformedSortFunc = (sortingPath) => {
  if (!sortingPath) return sortingPath;

  const negative = sortingPath[0] === '-' ? '-' : '';
  const sortingValue = negative ? sortingPath.slice(1) : sortingPath;

  const transformPath = get(SORTING_PATH_MAP, sortingValue);
  return transformPath ? `${negative}${transformPath}` : sortingPath;
};

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top