SergeiKiss/backend-project-4

View on GitHub
src/helpers/common-funcs.js

Summary

Maintainability
A
0 mins
Test Coverage
A
100%
export const replaceSymbols = (str) => {
  let strToChange = str;
  const reg = /[^a-zа-яёA-ZА-ЯЁ\d]/g;
  if (str.endsWith('/')) strToChange = str.slice(0, str.length - 1);
  return strToChange.replaceAll(reg, '-');
};

export const createName = (str, ending) => {
  const name = `${replaceSymbols(str)}${ending}`;
  return name;
};