Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

372
Visualizações
Typescript: Can't do string replacement

I'm not familiar with typescript. I'm trying to delete the string https://i.pximg.net and https://source.pixiv.net but I'm getting this error when I try do a string replacement with typescript

ERROR in
/var/www/type.adoreanime.com/htdocs/pixiv.moe/src/utils/api.ts
  121:59  error  Replace `"https://i.pximg.net"|"https://source.pixiv.net",·''` with `⏎······'https://i.pximg.net'·|·'https://source.pixiv.net',⏎······''⏎····`  prettier/prettier
  163:3   error  Insert `⏎`                                                                                                                                      prettier/prettier

✖ 2 problems (2 errors, 0 warnings)
  2 errors and 0 warnings potentially fixable with the `--fix` option.

this is the code:

export const proxyImage = (url: string) => {
  if (!url) {
    return url;
  }
  const regex = /^https?:\/\/(i\.pximg\.net)|(source\.pixiv\.net)/i;
  if (regex.test(url)) {
    url = `https://img.adoreanime.com/image/${url.replace("https://i.pximg.net"|"https://source.pixiv.net", '')}`;
    if (
      process.env.NODE_ENV !== 'test' &&
      document.body.classList.contains('supports-webp') &&
      (url.indexOf('.png') > -1 ||
        url.indexOf('.jpg') > -1 ||
        url.indexOf('.jpeg') > -1)
    ) {
      url = `${url}@progressive.webp`;
    }
  }

  return url;
};

can anyone help me fix my typos or errors?

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

This is a linter error, it is asking you to leave some space to make the code more readable. Replace the line where you are setting the url to this:

url = `https://img.adoreanime.com/image/${url.replace(
    'https://i.pximg.net'|'https://source.pixiv.net',
    ''
)}`;

It is also asking you to place a newline at the bottom of the file.

The last line of that error is giving you an option to run your linter with the '--fix' flag. Give that a go to solve some of the pesky lint errors.

about 4 years ago · Juan Pablo Isaza Relatório

0

This is not a TypeScript issue, it's a prettier issue.

It's telling you that the line is too long, and you should break up that line to make it more readable. ⏎ means newline.

But a better approach might be to put the string to be removed into its own variable.

  if (regex.test(url)) {
    const trimOut = "https://i.pximg.net"|"https://source.pixiv.net";
    url = `https://img.adoreanime.com/image/${url.replace(trimOut, '')}`;

But also, I'm pretty sure

url.replace("https://i.pximg.net"|"https://source.pixiv.net",

is not what you wanted - "https://i.pximg.net"|"https://source.pixiv.net" will evaluate to 0. Did you mean to use a regular expression?

  if (regex.test(url)) {
    const trimOut = /https:\/\/i\.pximg\.net|https:\/\/source\.pixiv\.net/g;
    url = `https://img.adoreanime.com/image/${url.replace(trimOut, '')}`;
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda